Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / protocol-plugin / plugin-manager / src / PluginManager.cpp
1 //******************************************************************
2 //
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 /// @file PluginManager.cpp
22
23 /// @brief
24
25
26 #include "PluginManager.h"
27
28 using namespace OIC;
29
30 PluginManager::PluginManager()
31 {
32 /**
33  * For Tizen Platform, specifiy the absolute location of dynamic library. It is required for
34  * Tizen 2.3 EFL App to work.
35  */
36 #ifdef __TIZEN__
37     handle = dlopen("/opt/usr/apps/org.iotivity.service.ppm.ppmsampleapp/lib/libpmimpl.so",
38                                                                                         RTLD_LAZY);
39 #else
40     handle = dlopen("./libpmimpl.so", RTLD_LAZY);
41 #endif //#ifdef __TIZEN__
42
43     if (!handle)
44     {
45         fprintf(stderr, "%s\n", dlerror());
46         exit(EXIT_FAILURE);
47     }
48     PluginManagerImpl* (*create)(void *);
49     create = (PluginManagerImpl * (*)(void *))dlsym(handle, "create_object");
50     destroy = (void (*)(PluginManagerImpl *))dlsym(handle, "destroy_object");
51     pluginManagerImpl = (PluginManagerImpl *)create(NULL);
52 }
53
54 PluginManager::~PluginManager(void)
55 {
56     destroy(pluginManagerImpl);
57     dlclose(handle);
58 }
59
60 int PluginManager::startPlugins(const std::string key, const std::string value)
61 {
62     return pluginManagerImpl->startPlugins(key, value);
63 }
64
65 int PluginManager::stopPlugins(const std::string key, const std::string value)
66 {
67     return pluginManagerImpl->stopPlugins(key, value);
68 }
69
70 int PluginManager::rescanPlugin()
71 {
72     return pluginManagerImpl->rescanPlugin();
73 }
74
75 std::vector<Plugin> PluginManager::getPlugins(void)
76 {
77     return pluginManagerImpl->getAllPlugins();
78 }
79
80 std::string PluginManager::getState(const std::string plugID)
81 {
82     return pluginManagerImpl->getState(plugID);
83 }