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
@@ -3,8 +3,8 @@
#include "NetworkSetupAddOn.h" #include "NetworkSetupAddOn.h"
NetworkSetupAddOn::NetworkSetupAddOn() NetworkSetupAddOn::NetworkSetupAddOn(image_id image)
: is_dirty(false), profile(NULL) : is_dirty(false), profile(NULL), addon_image(image)
{ {
} }
+12 -4
View File
@@ -2,12 +2,13 @@
#define NETWORKSETUPADDON_H #define NETWORKSETUPADDON_H
#include <View.h> #include <View.h>
#include <kernel/image.h> // for image_id
class NetworkSetupProfile; class NetworkSetupProfile;
class NetworkSetupAddOn { class NetworkSetupAddOn {
public: public:
NetworkSetupAddOn(); NetworkSetupAddOn(image_id addon_image);
virtual ~NetworkSetupAddOn(); virtual ~NetworkSetupAddOn();
virtual BView * CreateView(BRect *bounds); virtual BView * CreateView(BRect *bounds);
@@ -15,25 +16,32 @@ class NetworkSetupAddOn {
virtual status_t Revert(); virtual status_t Revert();
virtual const char * Name(); virtual const char * Name();
// virtual const BBitmap * Icon();
virtual status_t ProfileChanged(NetworkSetupProfile *new_profile);
status_t ProfileChanged(NetworkSetupProfile *new_profile);
NetworkSetupProfile * Profile(); NetworkSetupProfile * Profile();
bool IsDirty(); bool IsDirty();
void SetDirty(bool dirty = true); void SetDirty(bool dirty = true);
image_id AddonImageId();
private: private:
bool is_dirty; bool is_dirty;
NetworkSetupProfile * profile; NetworkSetupProfile * profile;
image_id addon_image;
}; };
inline bool NetworkSetupAddOn::IsDirty() { return is_dirty; }; inline bool NetworkSetupAddOn::IsDirty() { return is_dirty; };
inline void NetworkSetupAddOn::SetDirty(bool dirty) { is_dirty = dirty; }; inline void NetworkSetupAddOn::SetDirty(bool dirty) { is_dirty = dirty; };
inline NetworkSetupProfile * NetworkSetupAddOn::Profile() { return profile; }; inline NetworkSetupProfile * NetworkSetupAddOn::Profile() { return profile; };
inline image_id NetworkSetupAddOn::AddonImageId() { return addon_image; };
extern "C" { extern "C" {
typedef NetworkSetupAddOn * (*network_setup_addon_instantiate)(void); #define NETWORK_SETUP_ADDON_INSTANCIATE_FUNC_NAME "get_nth_addon"
NetworkSetupAddOn * get_addon(void); typedef NetworkSetupAddOn * (*network_setup_addon_instantiate)(image_id image, int index);
extern NetworkSetupAddOn * get_nth_addon(image_id image, int index);
} }
@@ -430,28 +430,34 @@ void NetworkSetupWindow::BuildShowMenu
printf("Addon %s loaded.\n", addon_path.Path()); printf("Addon %s loaded.\n", addon_path.Path());
by_instantiate_func by_func; by_instantiate_func by_instantiate;
network_setup_addon_instantiate ns_func; network_setup_addon_instantiate get_nth_addon;
status_t status; 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) { if (status == B_OK) {
NetworkSetupAddOn *addon; NetworkSetupAddOn *addon;
int n;
addon = ns_func(); n = 0;
BMessage *msg = new BMessage(msg_what); while ((addon = get_nth_addon(addon_id, n)) != NULL) {
msg->AddInt32("image_id", addon_id); BMessage *msg = new BMessage(msg_what);
msg->AddString("addon_path", addon_path.Path());
msg->AddPointer("addon", addon); msg->AddInt32("image_id", addon_id);
menu->AddItem(new BMenuItem(addon->Name(), msg)); msg->AddString("addon_path", addon_path.Path());
continue; msg->AddPointer("addon", addon);
menu->AddItem(new BMenuItem(addon->Name(), msg));
n++;
}
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) { if (status == B_OK) {
BYAddon *addon; BYAddon *addon;
addon = by_func(); addon = by_instantiate();
BMessage *msg = new BMessage(msg_what); BMessage *msg = new BMessage(msg_what);
msg->AddInt32("image_id", addon_id); msg->AddInt32("image_id", addon_id);
msg->AddString("addon_path", addon_path.Path()); msg->AddString("addon_path", addon_path.Path());
@@ -460,8 +466,8 @@ void NetworkSetupWindow::BuildShowMenu
continue; continue;
}; };
// No "modules" symbol found in this addon // No "addon instantiate function" symbol found in this addon
printf("Symbol \"instantiate\" not found in %s addon: not a module addon!\n", addon_path.Path()); 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); unload_add_on(addon_id);
}; };