Imported Upstream version 0.9.2
[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 #ifdef __TIZEN__
28 #include <appfw/app_common.h>
29 #endif
30
31 using namespace OIC;
32
33 PluginManager::PluginManager()
34 {
35 #ifdef __TIZEN__
36     char *app_id = NULL;
37     std::string completePath = "";
38     int res = app_get_id(&app_id);
39     if (APP_ERROR_NONE == res)
40     {
41         completePath = "/opt/usr/apps/";
42         completePath += app_id;
43         completePath += "/lib/libpmimpl.so";
44     }
45     free(app_id);
46     app_id = NULL;
47     handle = dlopen(completePath.c_str(), RTLD_LAZY);
48 #else
49     handle = dlopen("./libpmimpl.so", RTLD_LAZY);
50 #endif //#ifdef __TIZEN__
51
52     if (!handle)
53     {
54         fprintf(stderr, "%s\n", dlerror());
55         exit(EXIT_FAILURE);
56     }
57     PluginManagerImpl* (*create)(void *);
58     create = (PluginManagerImpl * (*)(void *))dlsym(handle, "create_object");
59     destroy = (void (*)(PluginManagerImpl *))dlsym(handle, "destroy_object");
60     pluginManagerImpl = (PluginManagerImpl *)create(NULL);
61 }
62
63 PluginManager::~PluginManager(void)
64 {
65     destroy(pluginManagerImpl);
66     dlclose(handle);
67 }
68
69 int PluginManager::startPlugins(const std::string key, const std::string value)
70 {
71     return pluginManagerImpl->startPlugins(key, value);
72 }
73
74 int PluginManager::stopPlugins(const std::string key, const std::string value)
75 {
76     return pluginManagerImpl->stopPlugins(key, value);
77 }
78
79 int PluginManager::rescanPlugin()
80 {
81     return pluginManagerImpl->rescanPlugin();
82 }
83
84 std::vector<Plugin> PluginManager::getPlugins(void)
85 {
86     return pluginManagerImpl->getAllPlugins();
87 }
88
89 std::string PluginManager::getState(const std::string plugID)
90 {
91     return pluginManagerImpl->getState(plugID);
92 }