[SSM] Fix IOT-322, 323 issues
[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(OUT 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(IN 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(IN 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     }
69     return res;
70 }
71
72 SSMRESULT StartSSMCore()
73 {
74     SSMRESULT res = SSM_E_FAIL;
75
76     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
77     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->startCore());
78
79 CLEANUP:
80     return res;
81 }
82
83 SSMRESULT StopSSMCore()
84 {
85     SSMRESULT res = SSM_E_FAIL;
86
87     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
88     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->stopCore());
89
90 CLEANUP:
91     return res;
92 }
93
94 SSMRESULT TerminateSSMCore(bool factoryResetFlag)
95 {
96     SSMRESULT res = SSM_E_FAIL;
97
98     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
99     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->terminateCore(factoryResetFlag));
100
101 CLEANUP:
102     SAFE_RELEASE(g_pSoftSensorManager);
103     DestroyGlobalInstanceRepo();
104     return res;
105 }
106
107 const char *GetSSMError(SSMRESULT res)
108 {
109     const char *msg = NULL;
110
111     switch (res)
112     {
113         case SSM_S_OK:
114             msg = "Success";
115             break;
116
117         case SSM_E_POINTER:
118             msg = "SSM_E_POINTER";
119             break;
120
121         case SSM_E_OUTOFMEMORY:
122             msg = "SSM_E_OUTOFMEMORY";
123             break;
124
125         case SSM_E_FAIL:
126             msg = "SSM_E_FAIL";
127             break;
128
129         case SSM_E_NOTINIT:
130             msg = "SSM_E_NOTINIT";
131             break;
132
133         case SSM_E_INITIALIZED:
134             msg = "SSM_E_INITIALIZED";
135             break;
136
137         case SSM_E_INVALIDXML:
138             msg = "SSM_E_INVALIDXML";
139             break;
140
141         case SSM_E_NOINTERFACE:
142             msg = "SSM_E_NOINTERFACE";
143             break;
144
145         case SSM_E_NOTIMPL:
146             msg = "SSM_E_NOTIMPL";
147             break;
148
149         default:
150             msg = "Not defined";
151             break;
152     }
153
154     return msg;
155 }
156
157 SSMRESULT GetInstalledModelList(OUT std::vector<ISSMResource *> *pList)
158 {
159     SSMRESULT res = SSM_E_FAIL;
160
161     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
162     g_pSoftSensorManager->getInstalledModelList(pList);
163
164 CLEANUP:
165     return res;
166 }