Imported Upstream version 0.9.1
[platform/upstream/iotivity.git] / service / soft-sensor-manager / SSMCore / src / SSMInterface / SSMCore.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 #include "SSMInterface/SSMCore.h"
21 #include "SSMInterface/SoftSensorManager.h"
22 #include "Common/InternalInterface.h"
23
24 static ISoftSensorManager       *g_pSoftSensorManager = NULL;
25
26 SSMRESULT CreateQueryEngine(IQueryEngine **ppQueryEngine)
27 {
28     SSMRESULT res = SSM_E_FAIL;
29
30     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
31     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->createQueryEngine(ppQueryEngine));
32
33 CLEANUP:
34     return res;
35 }
36
37 unsigned long ReleaseQueryEngine(IQueryEngine *pQueryEngine)
38 {
39     if (pQueryEngine == NULL)
40     {
41         return -1;
42     }
43
44     if (g_pSoftSensorManager == NULL)
45     {
46         return -1;
47     }
48
49     return g_pSoftSensorManager->releaseQueryEngine(pQueryEngine);
50 }
51
52 SSMRESULT InitializeSSMCore(std::string xmlDescription)
53 {
54     SSMRESULT res = SSM_E_FAIL;
55
56     if (g_pSoftSensorManager != NULL)
57         SSM_CLEANUP_ASSERT(SSM_E_INITIALIZED);
58
59     SSM_CLEANUP_ASSERT(CreateGlobalInstanceRepo());
60     SSM_CLEANUP_ASSERT(CreateInstance(OID_ISoftSensorManager, (IBase **)&g_pSoftSensorManager));
61     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->initializeCore(xmlDescription));
62
63 CLEANUP:
64     if (res != SSM_S_OK &&
65         res != SSM_E_INITIALIZED)
66     {
67         SAFE_RELEASE(g_pSoftSensorManager);
68         DestroyGlobalInstanceRepo();
69     }
70
71     return res;
72 }
73
74 SSMRESULT StartSSMCore()
75 {
76     SSMRESULT res = SSM_E_FAIL;
77
78     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
79     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->startCore());
80
81 CLEANUP:
82     return res;
83 }
84
85 SSMRESULT StopSSMCore()
86 {
87     SSMRESULT res = SSM_E_FAIL;
88
89     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
90     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->stopCore());
91
92 CLEANUP:
93     return res;
94 }
95
96 SSMRESULT TerminateSSMCore(bool factoryResetFlag)
97 {
98     SSMRESULT res = SSM_E_FAIL;
99
100     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
101     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->terminateCore(factoryResetFlag));
102
103 CLEANUP:
104     SAFE_RELEASE(g_pSoftSensorManager);
105     DestroyGlobalInstanceRepo();
106     return res;
107 }
108
109 const char *GetSSMError(SSMRESULT res)
110 {
111     const char *msg = NULL;
112
113     switch (res)
114     {
115         case SSM_S_OK:
116             msg = "Success";
117             break;
118
119         case SSM_E_POINTER:
120             msg = "SSM_E_POINTER";
121             break;
122
123         case SSM_E_OUTOFMEMORY:
124             msg = "SSM_E_OUTOFMEMORY";
125             break;
126
127         case SSM_E_FAIL:
128             msg = "SSM_E_FAIL";
129             break;
130
131         case SSM_E_NOTINIT:
132             msg = "SSM_E_NOTINIT";
133             break;
134
135         case SSM_E_INITIALIZED:
136             msg = "SSM_E_INITIALIZED";
137             break;
138
139         case SSM_E_INVALIDXML:
140             msg = "SSM_E_INVALIDXML";
141             break;
142
143         case SSM_E_NOINTERFACE:
144             msg = "SSM_E_NOINTERFACE";
145             break;
146
147         case SSM_E_NOTIMPL:
148             msg = "SSM_E_NOTIMPL";
149             break;
150
151         default:
152             msg = "Not defined";
153             break;
154     }
155
156     return msg;
157 }
158
159 SSMRESULT GetInstalledModelList(std::vector<ISSMResource *> *pList)
160 {
161     SSMRESULT res = SSM_E_FAIL;
162
163     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
164     g_pSoftSensorManager->getInstalledModelList(pList);
165
166 CLEANUP:
167     return res;
168 }