Store the dbus connection while launching the service
[platform/core/context/context-service.git] / src / agent / legacy / trigger / FactRequest.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <Types.h>
18 #include "FactRequest.h"
19
20 using namespace ctx;
21 using namespace ctx::trigger;
22
23 FactRequest::FactRequest(int type, int reqId, const char* subj, const char* desc, ContextMonitor* ctxMonitor) :
24         RequestInfo(type, reqId, subj, desc),
25         __ctxMonitor(ctxMonitor),
26         __replied(false)
27 {
28 }
29
30 FactRequest::~FactRequest()
31 {
32         reply(ERR_OPERATION_FAILED);
33 }
34
35 const char* FactRequest::getClient()
36 {
37         return "TRIGGER";
38 }
39
40 bool FactRequest::reply(int error)
41 {
42         IF_FAIL_RETURN(!__replied && __ctxMonitor, true);
43         __ctxMonitor->replyResult(__reqId, error);
44         __replied = (error != ERR_NONE);
45         return true;
46 }
47
48 bool FactRequest::reply(int error, CtxJson1& requestResult)
49 {
50         IF_FAIL_RETURN(!__replied && __ctxMonitor, true);
51         __ctxMonitor->replyResult(__reqId, error, &requestResult);
52         __replied = (error != ERR_NONE);
53         return true;
54 }
55
56 bool FactRequest::reply(int error, CtxJson1& requestResult, CtxJson1& dataRead)
57 {
58         IF_FAIL_RETURN(!__replied && __ctxMonitor, true);
59         __ctxMonitor->replyResult(__reqId, error, __subject.c_str(), &getDescription(), &dataRead);
60         return (__replied = true);
61 }
62
63 bool FactRequest::publish(int error, CtxJson1& data)
64 {
65         IF_FAIL_RETURN(__ctxMonitor, true);
66         __ctxMonitor->publishFact(__reqId, error, __subject.c_str(), &getDescription(), &data);
67         return true;
68 }