diff --git a/src/servers/input/AddOnManager.cpp b/src/servers/input/AddOnManager.cpp index 268b084cf8..a0e9b2380c 100644 --- a/src/servers/input/AddOnManager.cpp +++ b/src/servers/input/AddOnManager.cpp @@ -185,7 +185,6 @@ AddOnManager::UnregisterAddOn(BEntry &entry) if (!strcmp(pinfo->ref.name, ref.name)) { InputServer::StartStopDevices(pinfo->isd, false); delete pinfo->isd; - delete pinfo->addon; if (pinfo->addon_image >= B_OK) unload_add_on(pinfo->addon_image); fDeviceList.RemoveCurrent(); @@ -208,7 +207,6 @@ AddOnManager::UnregisterAddOn(BEntry &entry) for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) { if (!strcmp(pinfo->ref.name, ref.name)) { delete pinfo->ism; - delete pinfo->addon; if (pinfo->addon_image >= B_OK) unload_add_on(pinfo->addon_image); fMethodList.RemoveCurrent(); @@ -255,7 +253,7 @@ AddOnManager::RegisterAddOns() const directory_which directories[] = { B_USER_ADDONS_DIRECTORY, B_COMMON_ADDONS_DIRECTORY, -// B_BEOS_ADDONS_DIRECTORY, + B_BEOS_ADDONS_DIRECTORY, }; const char subDirectories[][24] = { "input_server/devices", @@ -278,12 +276,6 @@ AddOnManager::RegisterAddOns() } } - // ToDo: this is for our own convenience only, and should be removed - // in the final release - //if ((directory.SetTo("/boot/home/develop/openbeos/current/distro/x86.R1/beos/system/add-ons/media/plugins") == B_OK) - // && (directory.GetNodeRef(&nref) == B_OK)) { - // fHandler->AddDirectory(&nref); - //} } @@ -305,7 +297,6 @@ AddOnManager::UnregisterAddOns() for (fDeviceList.Rewind(); fDeviceList.GetNext(&pinfo);) { InputServer::StartStopDevices(pinfo->isd, false); delete pinfo->isd; - delete pinfo->addon; if (pinfo->addon_image >= B_OK) unload_add_on(pinfo->addon_image); fDeviceList.RemoveCurrent(); @@ -326,7 +317,6 @@ AddOnManager::UnregisterAddOns() method_info *pinfo; for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) { delete pinfo->ism; - delete pinfo->addon; if (pinfo->addon_image >= B_OK) unload_add_on(pinfo->addon_image); fMethodList.RemoveCurrent(); @@ -354,7 +344,6 @@ AddOnManager::RegisterDevice(BInputServerDevice *device, const entry_ref &ref, i info.ref = ref; info.addon_image = addon_image; info.isd = device; - //info.addon = new _BDeviceAddOn_; fDeviceList.Insert(info); } @@ -407,8 +396,7 @@ AddOnManager::RegisterMethod(BInputServerMethod *method, const entry_ref &ref, i info.ref = ref; info.addon_image = addon_image; info.ism = method; - //info.addon = new _BMethodAddOn_; - + fMethodList.Insert(info); BAutolock lock2(InputServer::gInputMethodListLocker); diff --git a/src/servers/input/AddOnManager.h b/src/servers/input/AddOnManager.h index 5822189d22..960b7014fc 100644 --- a/src/servers/input/AddOnManager.h +++ b/src/servers/input/AddOnManager.h @@ -39,7 +39,6 @@ class AddOnManager { private: struct device_info { entry_ref ref; - _BDeviceAddOn_* addon; image_id addon_image; BInputServerDevice *isd; }; @@ -50,7 +49,6 @@ class AddOnManager { }; struct method_info { entry_ref ref; - _BMethodAddOn_* addon; image_id addon_image; BInputServerMethod *ism; }; diff --git a/src/servers/input/DeviceManager.cpp b/src/servers/input/DeviceManager.cpp index bef1048310..2339da7dca 100644 --- a/src/servers/input/DeviceManager.cpp +++ b/src/servers/input/DeviceManager.cpp @@ -25,6 +25,7 @@ IAHandler::IAHandler(DeviceManager * manager) : BHandler ("DeviceManager") { + CALLED(); fManager = manager; } @@ -32,18 +33,33 @@ IAHandler::IAHandler(DeviceManager * manager) void IAHandler::MessageReceived(BMessage * msg) { + CALLED(); if (msg->what == B_NODE_MONITOR) { int32 opcode; if (msg->FindInt32("opcode", &opcode) == B_OK) { switch (opcode) { case B_ENTRY_CREATED: - - - break; case B_ENTRY_REMOVED: - - break; case B_ENTRY_MOVED: + { + node_ref dir_nref; + if ((msg->FindInt32("device", &dir_nref.device)!=B_OK) + || (msg->FindInt64("directory", &dir_nref.node)!=B_OK)) + return; + + _BDeviceAddOn_ *addon = NULL; + int32 i = 0; + while ((addon = fManager->GetAddOn(i++)) !=NULL) { + int32 j=0; + node_ref *dnref = NULL; + while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j++)) != NULL) { + if (*dnref == dir_nref) { + addon->fDevice->Control(NULL, NULL, msg->what, msg); + } + } + } + } + break; case B_STAT_CHANGED: case B_ATTR_CHANGED: case B_DEVICE_MOUNTED: @@ -58,8 +74,9 @@ IAHandler::MessageReceived(BMessage * msg) status_t -IAHandler::AddDirectory(const node_ref * nref) +IAHandler::AddDirectory(const node_ref * nref, _BDeviceAddOn_ *addon) { + CALLED(); BDirectory directory(nref); status_t status = directory.InitCheck(); if (status != B_OK) @@ -71,16 +88,14 @@ IAHandler::AddDirectory(const node_ref * nref) BEntry entry; while (directory.GetNextEntry(&entry, true) == B_OK) { - add_on_entry_info entry_info; - if (entry.GetName(entry_info.name) != B_OK) { - continue; // discard and proceed - } - if (entry.GetNodeRef(&entry_info.nref) != B_OK) { - continue; // discard and proceed - } - entry_info.dir_nref = *nref; - - // TODO : handle refs + entry_ref ref; + entry.GetRef(&ref); + BMessage msg(B_NODE_MONITOR); + msg.AddInt32("opcode", B_ENTRY_CREATED); + msg.AddInt32("device", nref->device); + msg.AddInt64("directory", nref->node); + msg.AddString("name", ref.name); + addon->fDevice->Control(NULL, NULL, msg.what, &msg); } return B_OK; @@ -88,8 +103,9 @@ IAHandler::AddDirectory(const node_ref * nref) status_t -IAHandler::RemoveDirectory(const node_ref * nref) +IAHandler::RemoveDirectory(const node_ref * nref, _BDeviceAddOn_ *addon) { + CALLED(); BDirectory directory(nref); status_t status = directory.InitCheck(); if (status != B_OK) @@ -101,16 +117,14 @@ IAHandler::RemoveDirectory(const node_ref * nref) BEntry entry; while (directory.GetNextEntry(&entry, true) == B_OK) { - add_on_entry_info entry_info; - if (entry.GetName(entry_info.name) != B_OK) { - continue; // discard and proceed - } - if (entry.GetNodeRef(&entry_info.nref) != B_OK) { - continue; // discard and proceed - } - entry_info.dir_nref = *nref; - - // TODO : handle refs + entry_ref ref; + entry.GetRef(&ref); + BMessage msg(B_NODE_MONITOR); + msg.AddInt32("opcode", B_ENTRY_REMOVED); + msg.AddInt32("device", nref->device); + msg.AddInt64("directory", nref->node); + msg.AddString("name", ref.name); + addon->fDevice->Control(NULL, NULL, msg.what, &msg); } return B_OK; @@ -126,6 +140,9 @@ DeviceManager::DeviceManager() DeviceManager::~DeviceManager() { + _BDeviceAddOn_ *addon = NULL; + while ((addon = (_BDeviceAddOn_ *)fDeviceAddons.RemoveItem((int32)0)) !=NULL) + delete addon; } @@ -148,22 +165,59 @@ status_t DeviceManager::StartMonitoringDevice(_BDeviceAddOn_ *addon, const char *device) { - // test if already monitored - - // monitor if needed + CALLED(); status_t err; node_ref nref; BDirectory directory; BPath path("/dev"); - if (((err = path.Append(device)) == B_OK) - && ((err = directory.SetTo(path.Path())) == B_OK) - && ((err = directory.GetNodeRef(&nref)) == B_OK) - && ((err = fHandler->AddDirectory(&nref)) == B_OK) ) { - return B_OK; - } else + if (((err = path.Append(device)) != B_OK) + || ((err = directory.SetTo(path.Path())) != B_OK) + || ((err = directory.GetNodeRef(&nref)) != B_OK)) return err; - // add in list + // test if already monitored + bool alreadyMonitored = false; + _BDeviceAddOn_ *tmpaddon = NULL; + int32 i = 0; + while ((tmpaddon = (_BDeviceAddOn_ *)fDeviceAddons.ItemAt(i++)) !=NULL) { + int32 j=0; + node_ref *dnref = NULL; + while ((dnref = (node_ref *)tmpaddon->fMonitoredRefs.ItemAt(j++)) != NULL) { + if (*dnref == nref) { + alreadyMonitored = true; + break; + } + } + if (alreadyMonitored) + break; + } + + // monitor if needed + if (!alreadyMonitored) { + if ((err = fHandler->AddDirectory(&nref, addon)) != B_OK) + return err; + } + + // add addon in list + if (!fDeviceAddons.HasItem(addon)) + fDeviceAddons.AddItem(addon); + + // add dir ref in list + int32 j=0; + node_ref *dnref = NULL; + alreadyMonitored = false; + while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j++)) != NULL) { + if (*dnref == nref) { + alreadyMonitored = true; + break; + } + } + + if (!alreadyMonitored) { + addon->fMonitoredRefs.AddItem(new node_ref(nref)); + } + + return B_OK; } @@ -171,19 +225,53 @@ status_t DeviceManager::StopMonitoringDevice(_BDeviceAddOn_ *addon, const char *device) { - // test if still monitored - // remove from list - - // stop monitoring if needed + CALLED(); status_t err; node_ref nref; BDirectory directory; BPath path("/dev"); - if (((err = path.Append(device)) == B_OK) - && ((err = directory.SetTo(path.Path())) == B_OK) - && ((err = directory.GetNodeRef(&nref)) == B_OK) - /*&& ((err = fHandler->RemoveDirectory(&nref)) ==B_OK)*/) { - return B_OK; - } else + if (((err = path.Append(device)) != B_OK) + || ((err = directory.SetTo(path.Path())) != B_OK) + || ((err = directory.GetNodeRef(&nref)) != B_OK)) return err; + + // test if still monitored + bool stillMonitored = false; + _BDeviceAddOn_ *tmpaddon = NULL; + int32 i = 0; + while ((tmpaddon = (_BDeviceAddOn_ *)fDeviceAddons.ItemAt(i++)) !=NULL) { + if (addon == tmpaddon) + continue; + + int32 j=0; + node_ref *dnref = NULL; + while ((dnref = (node_ref *)tmpaddon->fMonitoredRefs.ItemAt(j++)) != NULL) { + if (*dnref == nref) { + stillMonitored = true; + break; + } + } + if (stillMonitored) + break; + } + + // remove from list + node_ref *dnref = NULL; + int32 j=0; + while ((dnref = (node_ref *)addon->fMonitoredRefs.ItemAt(j)) != NULL) { + if (*dnref == nref) { + addon->fMonitoredRefs.RemoveItem(j); + delete dnref; + break; + } + j++; + } + + // stop monitoring if needed + if (!stillMonitored) { + if ((err = fHandler->RemoveDirectory(&nref, addon)) != B_OK) + return err; + } + + return B_OK; } diff --git a/src/servers/input/DeviceManager.h b/src/servers/input/DeviceManager.h index 30290e4246..f6a0287371 100644 --- a/src/servers/input/DeviceManager.h +++ b/src/servers/input/DeviceManager.h @@ -23,8 +23,8 @@ class IAHandler : public BHandler { public: IAHandler(DeviceManager * manager); void MessageReceived(BMessage * msg); - status_t AddDirectory(const node_ref * nref); - status_t RemoveDirectory(const node_ref * nref); + status_t AddDirectory(const node_ref * nref, _BDeviceAddOn_ *addon); + status_t RemoveDirectory(const node_ref * nref, _BDeviceAddOn_ *addon); private: DeviceManager * fManager; @@ -42,11 +42,11 @@ class DeviceManager { const char *device); status_t StopMonitoringDevice(_BDeviceAddOn_ *addon, const char *device); - + _BDeviceAddOn_ *GetAddOn(int32 index) { + return (_BDeviceAddOn_*)fDeviceAddons.ItemAt(index); + } private: - - private: - + BList fDeviceAddons; BLocker fLock; IAHandler *fHandler; }; diff --git a/src/servers/input/InputServer.cpp b/src/servers/input/InputServer.cpp index a115583b55..63901f4792 100644 --- a/src/servers/input/InputServer.cpp +++ b/src/servers/input/InputServer.cpp @@ -75,11 +75,6 @@ BLocker InputServer::gInputMethodListLocker; DeviceManager InputServer::gDeviceManager; -/*BList InputServer::mInputServerDeviceList; -BList InputServer::mInputServerFilterList; -BList InputServer::mInputServerMethodList;*/ - - /* * */ @@ -97,23 +92,17 @@ int main() * Method: InputServer::InputServer() * Descr: */ -InputServer::InputServer(void) : BApplication("application/x-vnd.OBOS-input_server") +InputServer::InputServer(void) : BApplication(INPUTSERVER_SIGNATURE) { CALLED(); void *pointer=NULL; EventLoop(pointer); -// InitTestDevice(); - gDeviceManager.LoadState(); fAddOnManager = new AddOnManager(); fAddOnManager->LoadState(); - -// InitDevices(); -// InitFilters(); -// InitMethods(); } /* @@ -141,7 +130,7 @@ InputServer::ArgvReceived(int32 argc, char** argv) printf("InputServer::ArgvReceived - Restarting ...\n"); status_t quit_status; //BMessenger msgr = BMessenger("application/x-vnd.OpenBeOS-input_server", -1, &quit_status); - BMessenger msgr = BMessenger("application/x-vnd.OBOS-input_server", -1, &quit_status); + BMessenger msgr = BMessenger(INPUTSERVER_SIGNATURE, -1, &quit_status); if (B_OK == quit_status) { BMessage msg = BMessage(B_QUIT_REQUESTED); msgr.SendMessage(&msg); @@ -487,6 +476,9 @@ bool InputServer::QuitRequested(void) { CALLED(); + if (!BApplication::QuitRequested()) + return false; + fAddOnManager->SaveState(); gDeviceManager.SaveState(); diff --git a/src/servers/input/InputServer.h b/src/servers/input/InputServer.h index f38a62ebf1..181140b66e 100644 --- a/src/servers/input/InputServer.h +++ b/src/servers/input/InputServer.h @@ -49,6 +49,8 @@ #include #include +#define INPUTSERVER_SIGNATURE "application/x-vnd.OBOS-input_server" + #if DEBUG>=1 #define EXIT() printf("EXIT %s\n", __PRETTY_FUNCTION__) #define CALLED() printf("CALLED %s\n", __PRETTY_FUNCTION__) @@ -77,6 +79,7 @@ class _BDeviceAddOn_ : fDevice(device) {}; BInputServerDevice *fDevice; + BList fMonitoredRefs; }; class _BMethodAddOn_