Fix prevent bug in the PluginManager.
authorheesung84.kim <heesung84.kim@samsung.com>
Thu, 18 Dec 2014 05:41:00 +0000 (14:41 +0900)
committerheesung84.kim <heesung84.kim@samsung.com>
Thu, 18 Dec 2014 08:09:11 +0000 (17:09 +0900)
Fix bug in the sample app.

Change-Id: Ie1eca80ba41c768374229196b368c4fa070595b1
Signed-off-by: heesung84.kim <heesung84.kim@samsung.com>
service/protocol-plugin/build/linux/Makefile
service/protocol-plugin/plugin-manager/src/Config.cpp
service/protocol-plugin/plugin-manager/src/PluginManager.cpp
service/protocol-plugin/plugin-manager/src/PluginManager.h
service/protocol-plugin/readme
service/protocol-plugin/sample-app/linux/mqtt/mqttclient.cpp

index dafa22e..a3f6aa1 100644 (file)
@@ -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
index 528c7dd..d473421 100644 (file)
@@ -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<char> buffer((istreambuf_iterator<char>(xmlFile)), istreambuf_iterator<char>());
index c3abdb8..7e0f0ed 100644 (file)
@@ -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)
index 2ae8b73..12c11ab 100644 (file)
@@ -96,6 +96,7 @@ namespace OIC
         private:
             PluginManagerImpl *pluginManagerImpl;
             void (*destroy)(PluginManagerImpl *);
+            void *handle;
     };
 }
 #endif //__PLUGINMANAGER_H
index 351756b..c9f3ad2 100644 (file)
@@ -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.)
 
index eda93d4..59ec85d 100644 (file)
@@ -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<OCResource> 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<OCResource> resource)
 {
@@ -270,7 +308,7 @@ void getFanRepresentation(std::shared_ptr<OCResource> 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<OCResource> 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);