From a241336807f322731e8bc3c075c3ce71dd0971c7 Mon Sep 17 00:00:00 2001 From: "heesung84.kim" Date: Thu, 18 Dec 2014 14:41:00 +0900 Subject: [PATCH] Fix prevent bug in the PluginManager. Fix bug in the sample app. Change-Id: Ie1eca80ba41c768374229196b368c4fa070595b1 Signed-off-by: heesung84.kim --- service/protocol-plugin/build/linux/Makefile | 2 +- .../protocol-plugin/plugin-manager/src/Config.cpp | 4 ++ .../plugin-manager/src/PluginManager.cpp | 3 +- .../plugin-manager/src/PluginManager.h | 1 + service/protocol-plugin/readme | 18 ++++---- .../sample-app/linux/mqtt/mqttclient.cpp | 48 +++++++++++++++++++--- 6 files changed, 61 insertions(+), 15 deletions(-) diff --git a/service/protocol-plugin/build/linux/Makefile b/service/protocol-plugin/build/linux/Makefile index dafa22e..a3f6aa1 100644 --- a/service/protocol-plugin/build/linux/Makefile +++ b/service/protocol-plugin/build/linux/Makefile @@ -23,7 +23,7 @@ sample-app: cd $(PROTOCOL_ROOT)sample-app/linux/mqtt && $(MAKE) cp -Rdp $(PROTOCOL_ROOT)plugin-manager/build/linux/libpmimpl.so $(PROTOCOL_ROOT)sample-app/linux/mqtt/ cp -Rdp $(PROTOCOL_ROOT)sample-app/linux/mqtt/mqttclient release/ - + cp -Rdp $(PROTOCOL_ROOT)sample-app/linux/mqtt/pluginmanager.xml release/ clean: cd $(PROTOCOL_ROOT)plugin-manager/build/linux && $(MAKE) clean diff --git a/service/protocol-plugin/plugin-manager/src/Config.cpp b/service/protocol-plugin/plugin-manager/src/Config.cpp index 528c7dd..d473421 100644 --- a/service/protocol-plugin/plugin-manager/src/Config.cpp +++ b/service/protocol-plugin/plugin-manager/src/Config.cpp @@ -51,6 +51,10 @@ PMRESULT Config::loadConfigFile(const std::string configfilepath) { // Read the xml file std::ifstream xmlFile(configfilepath.c_str()); + if(!xmlFile.good()) + { + return PM_S_FALSE; + } xml_document<> doc; //into a vector std::vector buffer((istreambuf_iterator(xmlFile)), istreambuf_iterator()); diff --git a/service/protocol-plugin/plugin-manager/src/PluginManager.cpp b/service/protocol-plugin/plugin-manager/src/PluginManager.cpp index c3abdb8..7e0f0ed 100644 --- a/service/protocol-plugin/plugin-manager/src/PluginManager.cpp +++ b/service/protocol-plugin/plugin-manager/src/PluginManager.cpp @@ -29,7 +29,7 @@ using namespace OIC; PluginManager::PluginManager() { - void *handle = dlopen("./libpmimpl.so", RTLD_LAZY); + handle = dlopen("./libpmimpl.so", RTLD_LAZY); if (!handle) { fprintf(stderr, "%s\n", dlerror()); @@ -44,6 +44,7 @@ PluginManager::PluginManager() PluginManager::~PluginManager(void) { destroy(pluginManagerImpl); + free(handle); } int PluginManager::startPlugins(const std::string key, const std::string value) diff --git a/service/protocol-plugin/plugin-manager/src/PluginManager.h b/service/protocol-plugin/plugin-manager/src/PluginManager.h index 2ae8b73..12c11ab 100644 --- a/service/protocol-plugin/plugin-manager/src/PluginManager.h +++ b/service/protocol-plugin/plugin-manager/src/PluginManager.h @@ -96,6 +96,7 @@ namespace OIC private: PluginManagerImpl *pluginManagerImpl; void (*destroy)(PluginManagerImpl *); + void *handle; }; } #endif //__PLUGINMANAGER_H diff --git a/service/protocol-plugin/readme b/service/protocol-plugin/readme index 351756b..c9f3ad2 100644 --- a/service/protocol-plugin/readme +++ b/service/protocol-plugin/readme @@ -41,12 +41,12 @@ The Protocol Plug-in directory includes following sub directories; 2. Compiling C-Pluff library Before building Protocol-Plugin Manager, C-Pluff library should be compiled as follows. -~/oic/oic-service/protocol-plugin/lib/cpluff$ aclocal -~/oic/oic-service/protocol-plugin/lib/cpluff$ autoconf -~/oic/oic-service/protocol-plugin/lib/cpluff$ autoheader -~/oic/oic-service/protocol-plugin/lib/cpluff$ automake -~/oic/oic-service/protocol-plugin/lib/cpluff$ ./configure -~/oic/oic-service/protocol-plugin/lib/cpluff$ make +~/service/protocol-plugin/lib/cpluff$ aclocal +~/service/protocol-plugin/lib/cpluff$ autoconf +~/service/protocol-plugin/lib/cpluff$ autoheader +~/service/protocol-plugin/lib/cpluff$ automake +~/service/protocol-plugin/lib/cpluff$ ./configure +~/service/protocol-plugin/lib/cpluff$ make 3. Run make @@ -54,7 +54,7 @@ By running make in the protocol-plugin path, protocol-plugin manager, all plugin NOTE: To build plugins in 64-bit Ubuntu Linux, OCLib.a and libcoap.a library should be re-compiled with ?fPIC option. -~/oic/oic-service/protocol-plugin/build/linux$make +~/service/protocol-plugin/build/linux$make 4. Using Plugins @@ -63,6 +63,8 @@ This version of protocol plug-in source code has following functionality. 1) provides plug-in manager which can start and stop plug-in library. 2) provides plug-in library which can communicate with MQTT protocol Fan and Light. 3) provides OIC Sample Client which can get info about Fan and Light with configuration file(pluginmanager.xml). + before starting sample app need as below command. + $export LD_LIBRARY_PATH={Top_Dir}/out/linux/x86/release/:$LD_LIBRARY_PATH So, to test a plug-in, follow below steps. @@ -70,6 +72,6 @@ So, to test a plug-in, follow below steps. 2) Register the plug-in with directory path input from plug-in manager sample. 3) Start the plug-in from plug-in manager sample. 4) Run OIC sample client. - ex)service/protocol-plugin/sample-app/linux/mqtt$./mqttclient + ex)~service/protocol-plugin/sample-app/linux/mqtt$./mqttclient (mqtt broker is already installed in the local system.) diff --git a/service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp b/service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp index eda93d4..59ec85d 100644 --- a/service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp +++ b/service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp @@ -54,6 +54,21 @@ class Fan Fan myfan; +class Light +{ + public: + + bool m_state; + int m_power; + std::string m_name; + + Light() : m_state(false), m_power(0), m_name("") + { + } +}; + +Light mylight; + int observe_count() { static int oc = 0; @@ -237,11 +252,11 @@ void putFanRepresentation(std::shared_ptr resource) } // Callback handler on GET request -void onGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode) +void onFanGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode) { if (eCode == OC_STACK_OK) { - std::cout << "GET request was successful" << std::endl; + std::cout << "GET Fan request was successful" << std::endl; std::cout << "Resource URI: " << rep.getUri() << std::endl; rep.getValue("state", myfan.m_state); @@ -261,6 +276,29 @@ void onGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, cons } } +void onLightGet(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int eCode) +{ + if (eCode == OC_STACK_OK) + { + std::cout << "GET Light request was successful" << std::endl; + std::cout << "Resource URI: " << rep.getUri() << std::endl; + + rep.getValue("state", mylight.m_state); + rep.getValue("power", mylight.m_power); + rep.getValue("name", mylight.m_name); + + std::cout << "\tstate: " << mylight.m_state << std::endl; + std::cout << "\tpower: " << mylight.m_power << std::endl; + std::cout << "\tname: " << mylight.m_name << std::endl; + } + else + { + std::cout << "onGET Response error: " << eCode << std::endl; + std::exit(-1); + } +} + + // Local function to get representation of fan resource void getFanRepresentation(std::shared_ptr resource) { @@ -270,7 +308,7 @@ void getFanRepresentation(std::shared_ptr resource) // Invoke resource's get API with the callback parameter QueryParamsMap test; - resource->get(test, &onGet); + resource->get(test, &onFanGet); } } @@ -282,7 +320,7 @@ void getLightRepresentation(std::shared_ptr resource) // Invoke resource's get API with the callback parameter QueryParamsMap test; - resource->get(test, &onGet); + resource->get(test, &onLightGet); } } @@ -531,7 +569,7 @@ int main(int argc, char *argv[]) std::cout << "======================" << std::endl; std::cout << "Start Fan Plugin by Name\n" << std::endl; - name = user_plugin[0].getName().c_str(); + name = user_plugin[0].getName(); m_pm->startPlugins(key, name); sleep(5); -- 2.7.4