1 //******************************************************************
3 // Copyright 2014 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
11 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
23 * @brief This file contains the declaration of classes and its members related to SSMClient.
26 #ifndef RESOURCECLIENT_H_
27 #define RESOURCECLIENT_H_
31 #include "OCResource.h"
32 #include "OCPlatform.h"
33 #include "ISSMClientListener.h"
46 * This is CSemaphore constructor.
53 *This is CSemaphore destructor.
60 * This is a function to creat a semaphore
61 * This is syncronus call.
62 * @param maximumRequestTimeOut
63 * [IN] Request Time out.
68 void create(int maximumRequestTimeOut)
70 hSemaphore = CreateSemaphore(NULL, 1, 1, NULL);
71 m_MaxTimeOut = maximumRequestTimeOut;
75 * This is a function to wait for semaphore
82 WaitForSingleObject(hSemaphore, m_MaxTimeOut);
86 * This is a function to release semaphore
93 ReleaseSemaphore(hSemaphore, 1, NULL);
99 #include <semaphore.h>
101 #define SEM_SUCCESS 0
107 timespec m_MaxTimeOut;
111 * This is CSemaphore constructor.
115 m_MaxTimeOut.tv_sec = 0;
116 m_MaxTimeOut.tv_nsec = 0;
119 *This is CSemaphore destructor.
125 * This is a function to creat a semaphore
126 * This is syncronus call.
127 * @param maximumRequestTimeOut
128 * [IN] Request Time out.
133 void create(int maximumRequestTimeOut)
135 if ( sem_init(&hSemaphore, 1, 0) < SEM_SUCCESS )
137 perror("Error : sem_init.");
140 m_MaxTimeOut.tv_sec = maximumRequestTimeOut;
145 sem_wait( &hSemaphore );
149 * This is a function to release semaphore
156 sem_post(&hSemaphore);
163 * @brief SSMClient is a wrapper class to provide SoftSensorManager functionality to Application.
164 * Basically, SoftSensorManager is developed in Resource model (i.e. messaging with basic functions of put, get, and post).
165 * SSMClient abstracts the resource based operations from client applications and provides c++ style functions.
170 SSMReturn m_retResponse;
173 * @brief SoftSensorManager Resource.
175 std::shared_ptr< OCResource > m_SSMResource;
177 * @brief attribute map .
179 AttributeMap m_responseAttributeMap;
181 * @brief query engine.
183 std::string m_queryEngineId;
185 * @brief app listener
187 ISSMClientListener *m_appListener;
190 * @brief internal find resource function
192 void _findResource(void);
195 * @brief internal Query engine function
197 void _createQueryEngine(void);
200 * @brief internal release query function
202 void _releaseQueryEngine(std::string queryEngineId);
206 * Constructor for SSMClient.
212 * This API sends query strings of applications to SoftSensorManager on Iotivity Base messaging.
214 * @param [in] queryString - A conditions query statement where the caller application specifies sensors for required data and conditions when the caller wants to get the data.
215 * @param [in] listener - The address of listener class. When an application which inherits the ISSMClientListener calls this operation, it sends its address for the listener so that
216 * SSMClient can callback message to the application.
217 * @param [out] cqid - A query id generated from SoftSensorManager service for the queryString request.
221 SSMReturn registerQuery(std::string queryString, ISSMClientListener *listener,
224 * This API is to cancel the registered sends query strings of applications to SoftSensorManager on Iotivity Base messaging.
226 * @param [in] listener - The address of listener class. When an application which inherits the ISSMClientListener calls this operation, it sends its address for the listener so that
227 * SSMClient can callback message to the application.
228 * @param [in] cqid - A query id generated from SoftSensorManager service for the queryString request.
231 SSMReturn unregisterQuery(std::string cqid);
233 // friend option. for callback from SSMResource
234 void onFoundResource(std::shared_ptr< OCResource > resource);
235 void onCreateQueryEngine(const HeaderOptions &headerOptions, const OCRepresentation &rep,
237 void onReleaseQueryEngine(const HeaderOptions &headerOptions, const OCRepresentation &rep,
239 void onRegisterQuery(const HeaderOptions &headerOptions, const OCRepresentation &rep,
241 void onUnregisterQuery(const HeaderOptions &headerOptions, const OCRepresentation &rep,
243 void onObserve(const HeaderOptions &headerOptions, const OCRepresentation &rep, const int &eCode,
244 const int &sequenceNumber);
247 #endif /* RESOURCECLIENT_H_ */