1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
20 #ifndef _QueryEngine_H_
21 #define _QueryEngine_H_
23 #include "SSMInterface/SSMCore.h"
24 #include "Common/PlatformLayer.h"
25 #include "Common/InternalInterface.h"
26 #include "ContextQuery.h"
27 #include "ConditionedQueryResult.h"
31 * @brief CQueryEngine Interface
32 * This class manages ContextQuery.
35 * CObject<CQueryEngine> *pQueryEngine;
36 * CreateInstance(OID_IQueryEngineInternal, (IBase**)&pQueryEngine);
37 * pQeuryEngine->ExecuteContextQuery(contextquery,cqid);
40 public CObjectRoot<CObjectMultiThreadModel>
41 , public IQueryEngineInternal
42 , public IThreadClient
43 , public IConditionedQueryEvent
46 CObjectPtr<IPropagationEngine> m_pPropagationEngine;
47 std::map<int, IConditionedQuery *> m_conditionedQueries;
48 CSimpleMutex m_mtxQueries;
50 IQueryEngineEvent *m_pQueryEngineEvent;
51 std::map<int, CContextQuery *> m_contextQueries;
52 CObjectPtr<ITasker> m_pTasker;
55 SSMRESULT processQueryResult(int userTriggerId, std::vector<result_model> *result);
56 SSMRESULT validateQueryResult(IConditionedQueryResult *pConditionedQueryResult,
57 std::vector<result_model> *resultData);
60 enum EventType {EVENT_TYPE_INNER, EVENT_TYPE_OUTER};
61 SSMRESULT finalConstruct();
63 void onExecute(void *pArg);
64 void onTerminate(void *pArg);
67 * @fn onConditionedQueryEvent
68 * @brief IConditionedQueryEvent interface's event callbacks for receiving query results
70 * @param [in] std::string ContextQuery - Entered ContetxQuery
71 * @param [out] int* cqid - ID of ContextQuery
77 SSMRESULT onConditionedQueryEvent(int userTriggerId,
78 IConditionedQueryResult *pConditionedQueryResult);
80 SSMRESULT queryInterface(const OID &objectID, IBase **ppObject)
85 if (IsEqualOID(objectID, OID_IQueryEngineInternal))
87 IBase *pBase = (IQueryEngineInternal *)this;
93 return SSM_E_NOINTERFACE;
97 * @fn executeContextQuery
98 * @brief Execute ContextQuery and return ContextQuery ID
100 * @param [in] std::string ContextQuery - Entered ContetxQuery
101 * @param [out] int* cqid - ID of ContextQuery
107 SSMRESULT executeContextQuery(std::string contextQuery, int *cqid);
109 //TODO: Registration with multiple instance support
111 * @fn registerQueryEvent
112 * @brief Register QueryEngineEvent to QueryEngine.
114 * @param [in] IQueryEngineEvent* pQueryEngineEvent - register QueryEngineEvent
120 SSMRESULT registerQueryEvent(IQueryEngineEvent *pQueryEngineEvent);
124 * @fn unregisterQueryEvent
125 * @brief Unregister QueryEngineEvent to QueryEngine.
127 * @param [in] IQueryEngineEvent* pQueryEngineEvent - unregister QueryEngineEvent
133 SSMRESULT unregisterQueryEvent(IQueryEngineEvent *pQueryEngineEvent);
136 * @fn killContextQuery
137 * @brief Kill registered ContextQuery according to cqid
139 * @param [in] int cqid - Context Query corresponding to the cqid will be terminated
146 SSMRESULT killContextQuery(int cqid);
149 #endif /*_QueryEngine_H_*/