Fix bug in the sample app.
Change-Id: Ie1eca80ba41c768374229196b368c4fa070595b1
Signed-off-by: heesung84.kim <heesung84.kim@samsung.com>
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
{
// 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>());
PluginManager::PluginManager()
{
- void *handle = dlopen("./libpmimpl.so", RTLD_LAZY);
+ handle = dlopen("./libpmimpl.so", RTLD_LAZY);
if (!handle)
{
fprintf(stderr, "%s\n", dlerror());
PluginManager::~PluginManager(void)
{
destroy(pluginManagerImpl);
+ free(handle);
}
int PluginManager::startPlugins(const std::string key, const std::string value)
private:
PluginManagerImpl *pluginManagerImpl;
void (*destroy)(PluginManagerImpl *);
+ void *handle;
};
}
#endif //__PLUGINMANAGER_H
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
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
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.
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.)
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;
}
// 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);
}
}
+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)
{
// Invoke resource's get API with the callback parameter
QueryParamsMap test;
- resource->get(test, &onGet);
+ resource->get(test, &onFanGet);
}
}
// Invoke resource's get API with the callback parameter
QueryParamsMap test;
- resource->get(test, &onGet);
+ resource->get(test, &onLightGet);
}
}
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);