Addons could instantiate multiple NetworkSetupAddOn.

Pass the image_id of addon to the instantiate function.
Some NetworkSetupAddOns may require it to get their resources...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6086 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Philippe Houdoin 2004-01-15 00:15:55 +00:00
parent ce22a23a9f
commit f530af584f
3 changed files with 35 additions and 21 deletions

View File

@ -3,8 +3,8 @@
#include "NetworkSetupAddOn.h"
NetworkSetupAddOn::NetworkSetupAddOn()
: is_dirty(false), profile(NULL)
NetworkSetupAddOn::NetworkSetupAddOn(image_id image)
: is_dirty(false), profile(NULL), addon_image(image)
{
}

View File

@ -2,12 +2,13 @@
#define NETWORKSETUPADDON_H
#include <View.h>
#include <kernel/image.h> // for image_id
class NetworkSetupProfile;
class NetworkSetupAddOn {
public:
NetworkSetupAddOn();
NetworkSetupAddOn(image_id addon_image);
virtual ~NetworkSetupAddOn();
virtual BView * CreateView(BRect *bounds);
@ -15,25 +16,32 @@ class NetworkSetupAddOn {
virtual status_t Revert();
virtual const char * Name();
// virtual const BBitmap * Icon();
status_t ProfileChanged(NetworkSetupProfile *new_profile);
NetworkSetupProfile * Profile();
virtual status_t ProfileChanged(NetworkSetupProfile *new_profile);
NetworkSetupProfile * Profile();
bool IsDirty();
void SetDirty(bool dirty = true);
image_id AddonImageId();
private:
bool is_dirty;
NetworkSetupProfile * profile;
image_id addon_image;
};
inline bool NetworkSetupAddOn::IsDirty() { return is_dirty; };
inline void NetworkSetupAddOn::SetDirty(bool dirty) { is_dirty = dirty; };
inline NetworkSetupProfile * NetworkSetupAddOn::Profile() { return profile; };
inline image_id NetworkSetupAddOn::AddonImageId() { return addon_image; };
extern "C" {
typedef NetworkSetupAddOn * (*network_setup_addon_instantiate)(void);
NetworkSetupAddOn * get_addon(void);
#define NETWORK_SETUP_ADDON_INSTANCIATE_FUNC_NAME "get_nth_addon"
typedef NetworkSetupAddOn * (*network_setup_addon_instantiate)(image_id image, int index);
extern NetworkSetupAddOn * get_nth_addon(image_id image, int index);
}

View File

@ -430,28 +430,34 @@ void NetworkSetupWindow::BuildShowMenu
printf("Addon %s loaded.\n", addon_path.Path());
by_instantiate_func by_func;
network_setup_addon_instantiate ns_func;
by_instantiate_func by_instantiate;
network_setup_addon_instantiate get_nth_addon;
status_t status;
status = get_image_symbol(addon_id, "get_addon", B_SYMBOL_TYPE_TEXT, (void **) &ns_func);
status = get_image_symbol(addon_id, "get_nth_addon", B_SYMBOL_TYPE_TEXT, (void **) &get_nth_addon);
if (status == B_OK) {
NetworkSetupAddOn *addon;
int n;
n = 0;
while ((addon = get_nth_addon(addon_id, n)) != NULL) {
BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("addon", addon);
menu->AddItem(new BMenuItem(addon->Name(), msg));
n++;
}
addon = ns_func();
BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("addon", addon);
menu->AddItem(new BMenuItem(addon->Name(), msg));
continue;
continue; // skip the Boneyard addon test...
};
status = get_image_symbol(addon_id, "instantiate", B_SYMBOL_TYPE_TEXT, (void **) &by_func);
status = get_image_symbol(addon_id, "instantiate", B_SYMBOL_TYPE_TEXT, (void **) &by_instantiate);
if (status == B_OK) {
BYAddon *addon;
addon = by_func();
addon = by_instantiate();
BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path());
@ -460,8 +466,8 @@ void NetworkSetupWindow::BuildShowMenu
continue;
};
// No "modules" symbol found in this addon
printf("Symbol \"instantiate\" not found in %s addon: not a module addon!\n", addon_path.Path());
// No "addon instantiate function" symbol found in this addon
printf("No symbol \"get_nth_addon\" or \"instantiate\" not found in %s addon: not a network setup addon!\n", addon_path.Path());
unload_add_on(addon_id);
};