2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <types_internal.h>
18 #include "fact_request.h"
20 ctx::fact_request::fact_request(int type, const char* client, int req_id, const char* subj, const char* desc, const char* zone, fact_reader* reader)
21 : request_info(type, client, req_id, subj, desc)
29 ctx::fact_request::~fact_request()
31 reply(ERR_OPERATION_FAILED);
34 bool ctx::fact_request::reply(int error)
36 IF_FAIL_RETURN(!replied && _reader, true);
37 _reader->reply_result(_req_id, error, _zone_name.c_str());
38 return (replied = true);
41 bool ctx::fact_request::reply(int error, ctx::json& request_result)
43 IF_FAIL_RETURN(!replied && _reader, true);
44 IF_FAIL_RETURN(_type != REQ_READ_SYNC, true);
45 _reader->reply_result(_req_id, error, _zone_name.c_str(), &request_result);
46 return (replied = true);
49 bool ctx::fact_request::reply(int error, ctx::json& request_result, ctx::json& data_read)
51 IF_FAIL_RETURN(!replied && _reader, true);
52 _reader->reply_result(_req_id, error, _zone_name.c_str(), &request_result, &data_read);
53 return (replied = true);
56 bool ctx::fact_request::publish(int error, ctx::json& data)
58 IF_FAIL_RETURN(_reader, true);
59 _reader->publish_fact(_req_id, error, _zone_name.c_str(), _subject.c_str(), &get_description(), &data);
63 void ctx::fact_request::set_zone_name(const char* zone_name)
66 _zone_name = zone_name;