2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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.
18 * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
20 * @brief This file implements main class of logic layer in cynara service
25 #include <exceptions/PluginNotFoundException.h>
28 #include <main/Cynara.h>
29 #include <request/CheckRequest.h>
30 #include <request/RequestContext.h>
31 #include <request/SignalRequest.h>
32 #include <response/CheckResponse.h>
33 #include <storage/Storage.h>
35 #include <sockets/SocketManager.h>
46 void Logic::execute(RequestContextPtr context UNUSED, SignalRequestPtr request) {
47 LOGD("Processing signal: [%d]", request->signalNumber());
49 switch (request->signalNumber()) {
51 LOGI("SIGTERM received!");
52 m_socketManager->mainLoopStop();
57 void Logic::execute(RequestContextPtr context, CheckRequestPtr request) {
58 PolicyResult result(PredefinedPolicyType::DENY);
59 if (check(context, request->key(), result)) {
60 context->returnResponse(context, std::make_shared<CheckResponse>(result, request->sequenceNumber()));
64 bool Logic::check(RequestContextPtr context UNUSED, const PolicyKey &key,
65 PolicyResult& result) {
66 result = m_storage->checkPolicy(key);
68 switch (result.policyType()) {
69 case PredefinedPolicyType::ALLOW :
70 LOGD("check of policy key <%s> returned ALLOW", key.toString().c_str());
72 case PredefinedPolicyType::DENY :
73 LOGD("check of policy key <%s> returned DENY", key.toString().c_str());
76 //todo pass question to proper plugin that:
77 // 1) returns false when answer has to be waited for (UI)
78 // 2) returns true if Response is to be generated
79 // In case 1) context should be saved in plugin in order to return answer when ready.
81 //in case no proper plugin is found
82 throw PluginNotFoundException(result);