From f530af584f909269d6de632dfadc877199773b69 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Thu, 15 Jan 2004 00:15:55 +0000 Subject: [PATCH] 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 --- .../kits/net/preflet/NetworkSetupAddOn.cpp | 4 +-- .../kits/net/preflet/NetworkSetupAddOn.h | 18 +++++++--- .../kits/net/preflet/NetworkSetupWindow.cpp | 34 +++++++++++-------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp b/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp index ffc6338aca..659a5bc42d 100644 --- a/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp +++ b/src/tests/kits/net/preflet/NetworkSetupAddOn.cpp @@ -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) { } diff --git a/src/tests/kits/net/preflet/NetworkSetupAddOn.h b/src/tests/kits/net/preflet/NetworkSetupAddOn.h index 8bc01f0108..d83edac3ee 100644 --- a/src/tests/kits/net/preflet/NetworkSetupAddOn.h +++ b/src/tests/kits/net/preflet/NetworkSetupAddOn.h @@ -2,12 +2,13 @@ #define NETWORKSETUPADDON_H #include +#include // 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); } diff --git a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp index 4859ed5bad..3e5566b6ee 100644 --- a/src/tests/kits/net/preflet/NetworkSetupWindow.cpp +++ b/src/tests/kits/net/preflet/NetworkSetupWindow.cpp @@ -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); };