Modifying version number for building on tizen 3.0
[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     SSM_CLEANUP_ASSERT(CreateGlobalInstanceRepo());
57     SSM_CLEANUP_ASSERT(CreateInstance(OID_ISoftSensorManager, (IBase **)&g_pSoftSensorManager));
58     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->initializeCore(xmlDescription));
59
60 CLEANUP:
61     if (res != SSM_S_OK)
62     {
63         SAFE_RELEASE(g_pSoftSensorManager);
64     }
65     return res;
66 }
67
68 SSMRESULT StartSSMCore()
69 {
70     SSMRESULT res = SSM_E_FAIL;
71
72     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
73     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->startCore());
74
75 CLEANUP:
76     return res;
77 }
78
79 SSMRESULT StopSSMCore()
80 {
81     SSMRESULT res = SSM_E_FAIL;
82
83     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
84     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->stopCore());
85
86 CLEANUP:
87     return res;
88 }
89
90 SSMRESULT TerminateSSMCore(bool factoryResetFlag)
91 {
92     SSMRESULT res = SSM_E_FAIL;
93
94     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
95     SSM_CLEANUP_ASSERT(g_pSoftSensorManager->terminateCore(factoryResetFlag));
96
97 CLEANUP:
98     SAFE_RELEASE(g_pSoftSensorManager);
99     DestroyGlobalInstanceRepo();
100     return res;
101 }
102
103 const char *GetSSMError(SSMRESULT res)
104 {
105     const char *msg = NULL;
106
107     switch (res)
108     {
109         case SSM_S_OK:
110             msg = "Success";
111             break;
112
113         case SSM_E_POINTER:
114             msg = "SSM_E_POINTER";
115             break;
116
117         case SSM_E_OUTOFMEMORY:
118             msg = "SSM_E_OUTOFMEMORY";
119             break;
120
121         case SSM_E_FAIL:
122             msg = "SSM_E_FAIL";
123             break;
124
125         case SSM_E_NOINTERFACE:
126             msg = "SSM_E_NOINTERFACE";
127             break;
128
129         case SSM_E_NOTIMPL:
130             msg = "SSM_E_NOTIMPL";
131             break;
132
133         default:
134             msg = "Not defined";
135             break;
136     }
137
138     return msg;
139 }
140
141 SSMRESULT GetInstalledModelList(OUT std::vector<ISSMResource *> *pList)
142 {
143     SSMRESULT res = SSM_E_FAIL;
144
145     SSM_CLEANUP_NULL_ASSERT(g_pSoftSensorManager);
146     g_pSoftSensorManager->getInstalledModelList(pList);
147
148 CLEANUP:
149     return res;
150 }