Minor cleanup.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18696 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2006-08-29 15:04:42 +00:00
parent a6ccb0bef6
commit 7ee49d9f64
3 changed files with 103 additions and 108 deletions
+82 -87
View File
@@ -40,29 +40,29 @@ class AddOnManager::InputServerMonitorHandler : public AddOnMonitorHandler {
} }
virtual void virtual void
AddOnEnabled(const add_on_entry_info * entry_info) AddOnEnabled(const add_on_entry_info* entryInfo)
{ {
CALLED(); CALLED();
entry_ref ref; entry_ref ref;
make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node, make_entry_ref(entryInfo->dir_nref.device, entryInfo->dir_nref.node,
entry_info->name, &ref); entryInfo->name, &ref);
BEntry entry(&ref, false); BEntry entry(&ref, false);
fManager->RegisterAddOn(entry); fManager->RegisterAddOn(entry);
} }
virtual void virtual void
AddOnDisabled(const add_on_entry_info * entry_info) AddOnDisabled(const add_on_entry_info* entryInfo)
{ {
CALLED(); CALLED();
entry_ref ref; entry_ref ref;
make_entry_ref(entry_info->dir_nref.device, entry_info->dir_nref.node, make_entry_ref(entryInfo->dir_nref.device, entryInfo->dir_nref.node,
entry_info->name, &ref); entryInfo->name, &ref);
BEntry entry(&ref, false); BEntry entry(&ref, false);
fManager->UnregisterAddOn(entry); fManager->UnregisterAddOn(entry);
} }
virtual void virtual void
AddOnRemoved(const add_on_entry_info * entry_info) AddOnRemoved(const add_on_entry_info* entryInfo)
{ {
} }
@@ -75,9 +75,9 @@ class AddOnManager::InputServerMonitorHandler : public AddOnMonitorHandler {
AddOnManager::AddOnManager(bool safeMode) AddOnManager::AddOnManager(bool safeMode)
: BLooper("addon_manager"), : BLooper("add-on manager"),
fLock("add-on manager"), fLock("add-on manager"),
fSafeMode(safeMode) fSafeMode(safeMode)
{ {
Run(); Run();
} }
@@ -104,7 +104,7 @@ AddOnManager::SaveState()
status_t status_t
AddOnManager::RegisterAddOn(BEntry &entry) AddOnManager::RegisterAddOn(BEntry& entry)
{ {
BPath path(&entry); BPath path(&entry);
@@ -115,90 +115,91 @@ AddOnManager::RegisterAddOn(BEntry &entry)
PRINT(("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path())); PRINT(("AddOnManager::RegisterAddOn(): trying to load \"%s\"\n", path.Path()));
image_id addon_image = load_add_on(path.Path()); image_id addonImage = load_add_on(path.Path());
if (addon_image < B_OK) { if (addonImage < B_OK) {
PRINT(("load addon %s failed\n", path.Path())); PRINT(("load addon %s failed\n", path.Path()));
return addon_image; return addonImage;
} }
BString pathString = path.Path(); BString pathString = path.Path();
if (pathString.FindFirst("input_server/devices")>0) { if (pathString.FindFirst("input_server/devices") > 0) {
BInputServerDevice *(*instantiate_func)(); BInputServerDevice *(*instantiate_func)();
if (get_image_symbol(addon_image, "instantiate_input_device", if (get_image_symbol(addonImage, "instantiate_input_device",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n", PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_device in \"%s\"\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerDevice *isd = (*instantiate_func)(); BInputServerDevice *device = (*instantiate_func)();
if (isd == NULL) { if (device == NULL) {
PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n", PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_device in \"%s\" returned NULL\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
status_t status = isd->InitCheck();
status_t status = device->InitCheck();
if (status != B_OK) { if (status != B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): BInputServerDevice.InitCheck in \"%s\" returned %s\n", PRINTERR(("AddOnManager::RegisterAddOn(): BInputServerDevice.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status))); path.Path(), strerror(status)));
delete isd; delete device;
goto exit_error; goto exit_error;
} }
RegisterDevice(isd, ref, addon_image); RegisterDevice(device, ref, addonImage);
} else if (pathString.FindFirst("input_server/filters")>0) { } else if (pathString.FindFirst("input_server/filters") > 0) {
BInputServerFilter *(*instantiate_func)(); BInputServerFilter *(*instantiate_func)();
if (get_image_symbol(addon_image, "instantiate_input_filter", if (get_image_symbol(addonImage, "instantiate_input_filter",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n", PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_filter in \"%s\"\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerFilter *isf = (*instantiate_func)(); BInputServerFilter *filter = (*instantiate_func)();
if (isf == NULL) { if (filter == NULL) {
PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n", PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_filter in \"%s\" returned NULL\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
status_t status = isf->InitCheck(); status_t status = filter->InitCheck();
if (status != B_OK) { if (status != B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): BInputServerFilter.InitCheck in \"%s\" returned %s\n", PRINTERR(("AddOnManager::RegisterAddOn(): BInputServerFilter.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status))); path.Path(), strerror(status)));
delete isf; delete filter;
goto exit_error; goto exit_error;
} }
RegisterFilter(isf, ref, addon_image); RegisterFilter(filter, ref, addonImage);
} else if (pathString.FindFirst("input_server/methods")>0) { } else if (pathString.FindFirst("input_server/methods") > 0) {
BInputServerMethod *(*instantiate_func)(); BInputServerMethod *(*instantiate_func)();
if (get_image_symbol(addon_image, "instantiate_input_method", if (get_image_symbol(addonImage, "instantiate_input_method",
B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) { B_SYMBOL_TYPE_TEXT, (void **)&instantiate_func) < B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n", PRINTERR(("AddOnManager::RegisterAddOn(): can't find instantiate_input_method in \"%s\"\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
BInputServerMethod *ism = (*instantiate_func)(); BInputServerMethod *method = (*instantiate_func)();
if (ism == NULL) { if (method == NULL) {
PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n", PRINTERR(("AddOnManager::RegisterAddOn(): instantiate_input_method in \"%s\" returned NULL\n",
path.Path())); path.Path()));
goto exit_error; goto exit_error;
} }
status_t status = ism->InitCheck(); status_t status = method->InitCheck();
if (status != B_OK) { if (status != B_OK) {
PRINTERR(("AddOnManager::RegisterAddOn(): BInputServerMethod.InitCheck in \"%s\" returned %s\n", PRINTERR(("AddOnManager::RegisterAddOn(): BInputServerMethod.InitCheck in \"%s\" returned %s\n",
path.Path(), strerror(status))); path.Path(), strerror(status)));
delete ism; delete method;
goto exit_error; goto exit_error;
} }
RegisterMethod(ism, ref, addon_image); RegisterMethod(method, ref, addonImage);
} else { } else {
PRINTERR(("AddOnManager::RegisterAddOn(): addon type not found for \"%s\" \n", path.Path())); PRINTERR(("AddOnManager::RegisterAddOn(): addon type not found for \"%s\" \n", path.Path()));
goto exit_error; goto exit_error;
@@ -207,13 +208,13 @@ AddOnManager::RegisterAddOn(BEntry &entry)
return B_OK; return B_OK;
exit_error: exit_error:
unload_add_on(addon_image); unload_add_on(addonImage);
return status; return status;
} }
status_t status_t
AddOnManager::UnregisterAddOn(BEntry &entry) AddOnManager::UnregisterAddOn(BEntry& entry)
{ {
BPath path(&entry); BPath path(&entry);
@@ -231,34 +232,34 @@ AddOnManager::UnregisterAddOn(BEntry &entry)
BAutolock locker(fLock); BAutolock locker(fLock);
if (pathString.FindFirst("input_server/devices")>0) { if (pathString.FindFirst("input_server/devices") > 0) {
device_info *pinfo; device_info *pinfo;
for (fDeviceList.Rewind(); fDeviceList.GetNext(&pinfo);) { for (fDeviceList.Rewind(); fDeviceList.GetNext(&pinfo);) {
if (!strcmp(pinfo->ref.name, ref.name)) { if (!strcmp(pinfo->ref.name, ref.name)) {
gInputServer->StartStopDevices(*pinfo->isd, false); gInputServer->StartStopDevices(*pinfo->device, false);
delete pinfo->isd; delete pinfo->device;
if (pinfo->addon_image >= B_OK) if (pinfo->addon_image >= B_OK)
unload_add_on(pinfo->addon_image); unload_add_on(pinfo->addon_image);
fDeviceList.RemoveCurrent(); fDeviceList.RemoveCurrent();
break; break;
} }
} }
} else if (pathString.FindFirst("input_server/filters")>0) { } else if (pathString.FindFirst("input_server/filters") > 0) {
filter_info *pinfo; filter_info *pinfo;
for (fFilterList.Rewind(); fFilterList.GetNext(&pinfo);) { for (fFilterList.Rewind(); fFilterList.GetNext(&pinfo);) {
if (!strcmp(pinfo->ref.name, ref.name)) { if (!strcmp(pinfo->ref.name, ref.name)) {
delete pinfo->isf; delete pinfo->filter;
if (pinfo->addon_image >= B_OK) if (pinfo->addon_image >= B_OK)
unload_add_on(pinfo->addon_image); unload_add_on(pinfo->addon_image);
fFilterList.RemoveCurrent(); fFilterList.RemoveCurrent();
break; break;
} }
} }
} else if (pathString.FindFirst("input_server/methods")>0) { } else if (pathString.FindFirst("input_server/methods") > 0) {
method_info *pinfo; method_info *pinfo;
for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) { for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) {
if (!strcmp(pinfo->ref.name, ref.name)) { if (!strcmp(pinfo->ref.name, ref.name)) {
delete pinfo->ism; delete pinfo->method;
if (pinfo->addon_image >= B_OK) if (pinfo->addon_image >= B_OK)
unload_add_on(pinfo->addon_image); unload_add_on(pinfo->addon_image);
fMethodList.RemoveCurrent(); fMethodList.RemoveCurrent();
@@ -266,13 +267,13 @@ AddOnManager::UnregisterAddOn(BEntry &entry)
} }
} }
if (fMethodList.CountItems()<=0) { if (fMethodList.CountItems() <= 0) {
// we remove the method replicant // we remove the method replicant
BDeskbar().RemoveItem(REPLICANT_CTL_NAME); BDeskbar().RemoveItem(REPLICANT_CTL_NAME);
gInputServer->SetMethodReplicant(NULL); gInputServer->SetMethodReplicant(NULL);
} else { } else {
BMessage msg(IS_REMOVE_METHOD); BMessage msg(IS_REMOVE_METHOD);
msg.AddInt32("cookie", (uint32)pinfo->ism); msg.AddInt32("cookie", (uint32)pinfo->method);
if (gInputServer->MethodReplicant()) if (gInputServer->MethodReplicant())
gInputServer->MethodReplicant()->SendMessage(&msg); gInputServer->MethodReplicant()->SendMessage(&msg);
} }
@@ -344,33 +345,33 @@ AddOnManager::UnregisterAddOns()
// we have to stop manually the addons because the monitor doesn't disable them on exit // we have to stop manually the addons because the monitor doesn't disable them on exit
{ {
device_info *pinfo; device_info *info;
for (fDeviceList.Rewind(); fDeviceList.GetNext(&pinfo);) { for (fDeviceList.Rewind(); fDeviceList.GetNext(&info);) {
gInputServer->StartStopDevices(*pinfo->isd, false); gInputServer->StartStopDevices(*info->device, false);
delete pinfo->isd; delete info->device;
if (pinfo->addon_image >= B_OK) if (info->addon_image >= B_OK)
unload_add_on(pinfo->addon_image); unload_add_on(info->addon_image);
fDeviceList.RemoveCurrent(); fDeviceList.RemoveCurrent();
} }
} }
{ {
filter_info *pinfo; filter_info *info;
for (fFilterList.Rewind(); fFilterList.GetNext(&pinfo);) { for (fFilterList.Rewind(); fFilterList.GetNext(&info);) {
delete pinfo->isf; delete info->filter;
if (pinfo->addon_image >= B_OK) if (info->addon_image >= B_OK)
unload_add_on(pinfo->addon_image); unload_add_on(info->addon_image);
fFilterList.RemoveCurrent(); fFilterList.RemoveCurrent();
} }
} }
{ {
method_info *pinfo; method_info *info;
for (fMethodList.Rewind(); fMethodList.GetNext(&pinfo);) { for (fMethodList.Rewind(); fMethodList.GetNext(&info);) {
delete pinfo->ism; delete info->method;
if (pinfo->addon_image >= B_OK) if (info->addon_image >= B_OK)
unload_add_on(pinfo->addon_image); unload_add_on(info->addon_image);
fMethodList.RemoveCurrent(); fMethodList.RemoveCurrent();
} }
} }
} }
@@ -395,7 +396,7 @@ AddOnManager::RegisterDevice(BInputServerDevice* device, const entry_ref& ref,
device_info info; device_info info;
info.ref = ref; info.ref = ref;
info.addon_image = addonImage; info.addon_image = addonImage;
info.isd = device; info.device = device;
fDeviceList.Insert(info); fDeviceList.Insert(info);
} }
@@ -420,12 +421,11 @@ AddOnManager::RegisterFilter(BInputServerFilter* filter, const entry_ref& ref,
filter_info info; filter_info info;
info.ref = ref; info.ref = ref;
info.addon_image = addonImage; info.addon_image = addonImage;
info.isf = filter; info.filter = filter;
fFilterList.Insert(info); fFilterList.Insert(info);
BAutolock lock2(InputServer::gInputFilterListLocker); BAutolock lock2(InputServer::gInputFilterListLocker);
InputServer::gInputFilterList.AddItem(filter); InputServer::gInputFilterList.AddItem(filter);
} }
@@ -449,7 +449,7 @@ AddOnManager::RegisterMethod(BInputServerMethod* method, const entry_ref& ref,
method_info info; method_info info;
info.ref = ref; info.ref = ref;
info.addon_image = addonImage; info.addon_image = addonImage;
info.ism = method; info.method = method;
fMethodList.Insert(info); fMethodList.Insert(info);
@@ -504,16 +504,16 @@ AddOnManager::LoadReplicant()
int32 uid; int32 uid;
while ((uid = GetReplicantAt(status, index++)) >= B_OK) { while ((uid = GetReplicantAt(status, index++)) >= B_OK) {
BMessage rep_info; BMessage rep_info;
if (GetReplicantName(status, uid, &rep_info) != B_OK) { if (GetReplicantName(status, uid, &rep_info) != B_OK)
continue; continue;
}
const char *name; const char *name;
if ((rep_info.FindString("result", &name) == B_OK) if (rep_info.FindString("result", &name) == B_OK
&& (strcmp(name, REPLICANT_CTL_NAME)==0)) { && !strcmp(name, REPLICANT_CTL_NAME)) {
BMessage rep_view; BMessage replicant;
if (GetReplicantView(status, uid, &rep_view)==0) { if (GetReplicantView(status, uid, &replicant) == B_OK) {
BMessenger result; BMessenger result;
if (rep_view.FindMessenger("result", &result) == B_OK) { if (replicant.FindMessenger("result", &result) == B_OK) {
gInputServer->SetMethodReplicant(new BMessenger(result)); gInputServer->SetMethodReplicant(new BMessenger(result));
} }
} }
@@ -526,10 +526,8 @@ AddOnManager::LoadReplicant()
int32 int32
AddOnManager::GetReplicantAt(BMessenger target, int32 index) const AddOnManager::GetReplicantAt(BMessenger target, int32 index) const
{ {
/* // So here we want to get the Unique ID of the replicant at the given index
So here we want to get the Unique ID of the replicant at the given index // in the target Shelf.
in the target Shelf.
*/
BMessage request(B_GET_PROPERTY);// We're getting the ID property BMessage request(B_GET_PROPERTY);// We're getting the ID property
BMessage reply; BMessage reply;
@@ -552,10 +550,8 @@ AddOnManager::GetReplicantAt(BMessenger target, int32 index) const
status_t status_t
AddOnManager::GetReplicantName(BMessenger target, int32 uid, BMessage *reply) const AddOnManager::GetReplicantName(BMessenger target, int32 uid, BMessage *reply) const
{ {
/* // We send a message to the target shelf, asking it for the Name of the
We send a message to the target shelf, asking it for the Name of the // replicant with the given unique id.
replicant with the given unique id.
*/
BMessage request(B_GET_PROPERTY); BMessage request(B_GET_PROPERTY);
BMessage uid_specifier(B_ID_SPECIFIER);// specifying via ID BMessage uid_specifier(B_ID_SPECIFIER);// specifying via ID
@@ -583,13 +579,12 @@ status_t
AddOnManager::GetReplicantView(BMessenger target, int32 uid, AddOnManager::GetReplicantView(BMessenger target, int32 uid,
BMessage* reply) const BMessage* reply) const
{ {
/* // We send a message to the target shelf, asking it for the Name of the
We send a message to the target shelf, asking it for the Name of the // replicant with the given unique id.
replicant with the given unique id.
*/
BMessage request(B_GET_PROPERTY); BMessage request(B_GET_PROPERTY);
BMessage uid_specifier(B_ID_SPECIFIER);// specifying via ID BMessage uid_specifier(B_ID_SPECIFIER);
// specifying via ID
status_t err; status_t err;
status_t e; status_t e;
+3 -3
View File
@@ -62,17 +62,17 @@ class AddOnManager : public BLooper {
struct device_info { struct device_info {
entry_ref ref; entry_ref ref;
image_id addon_image; image_id addon_image;
BInputServerDevice *isd; BInputServerDevice *device;
}; };
struct filter_info { struct filter_info {
entry_ref ref; entry_ref ref;
image_id addon_image; image_id addon_image;
BInputServerFilter *isf; BInputServerFilter *filter;
}; };
struct method_info { struct method_info {
entry_ref ref; entry_ref ref;
image_id addon_image; image_id addon_image;
BInputServerMethod *ism; BInputServerMethod *method;
}; };
BLocker fLock; BLocker fLock;
+1 -1
View File
@@ -1086,7 +1086,7 @@ InputServer::UnregisterDevices(BInputServerDevice& serverDevice,
if (devices != NULL) { if (devices != NULL) {
// remove the devices as specified only // remove the devices as specified only
input_device_ref *device = NULL; input_device_ref *device = NULL;
for (int32 i = 0; NULL != (device = devices[i]); i++) { for (int32 i = 0; (device = devices[i]) != NULL; i++) {
for (int32 j = fInputDeviceList.CountItems() - 1; j >= 0; j--) { for (int32 j = fInputDeviceList.CountItems() - 1; j >= 0; j--) {
InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j); InputDeviceListItem* item = (InputDeviceListItem*)fInputDeviceList.ItemAt(j);