#include <main/Cynara.h>
#include <request/CheckRequest.h>
+#include <request/RequestContext.h>
#include <response/CheckResponse.h>
#include <storage/Storage.h>
Logic::~Logic() {
}
-void Logic::execute(const RequestContext &context, CheckRequestPtr request) {
+void Logic::execute(RequestContextPtr context, CheckRequestPtr request) {
PolicyResult result(PredefinedPolicyType::DENY);
if (check(context, request->key(), result)) {
- context.returnResponse(CheckResponse(result));
+ context->returnResponse(context, CheckResponse(result));
}
}
-bool Logic::check(const RequestContext &context UNUSED, const PolicyKey &key,
+bool Logic::check(RequestContextPtr context UNUSED, const PolicyKey &key,
PolicyResult& result) {
result = Cynara::getStorage()->checkPolicy(key);
#include <types/PolicyResult.h>
#include <request/pointers.h>
-#include <request/RequestContext.h>
#include <request/RequestTaker.h>
namespace Cynara {
Logic();
virtual ~Logic();
- virtual void execute(const RequestContext &context, CheckRequestPtr request);
+ virtual void execute(RequestContextPtr context, CheckRequestPtr request);
private:
- bool check(const RequestContext &context, const PolicyKey &key, PolicyResult& result);
+ bool check(RequestContextPtr context, const PolicyKey &key, PolicyResult& result);
};
namespace Cynara {
void CheckRequest::execute(RequestPtr self, RequestTaker &taker,
- const RequestContext &context) const {
+ RequestContextPtr context) const {
taker.execute(context, std::dynamic_pointer_cast<CheckRequest>(self));
}
#include <request/pointers.h>
#include <request/Request.h>
-#include <request/RequestContext.h>
#include <request/RequestTaker.h>
namespace Cynara {
return m_key;
}
- virtual void execute(RequestPtr self, RequestTaker &taker, const RequestContext &context) const;
+ virtual void execute(RequestPtr self, RequestTaker &taker, RequestContextPtr context) const;
};
} // namespace Cynara
#define SRC_SERVICE_REQUEST_REQUEST_H_
#include <request/pointers.h>
-#include <request/RequestContext.h>
+#include <request/pointers.h>
#include <request/RequestTaker.h>
namespace Cynara {
Request() = default;
virtual ~Request() = default;
- virtual void execute(RequestPtr self, RequestTaker &taker,
- const RequestContext &context) const = 0;
+ virtual void execute(RequestPtr self, RequestTaker &taker, RequestContextPtr context) const = 0;
};
} // namespace Cynara
#ifndef SRC_SERVICE_REQUEST_REQUESTCONTEXT_H_
#define SRC_SERVICE_REQUEST_REQUESTCONTEXT_H_
+#include <memory>
+
#include <common.h>
+#include <request/pointers.h>
+#include <response/pointers.h>
#include <response/ResponseTaker.h>
namespace Cynara {
class RequestContext {
private:
int m_desc;
- ResponseTaker &m_responseTaker;
+ ResponseTakerWeakPtr m_responseTaker;
BinaryQueue &m_responseQueue;
public:
- RequestContext(int desc, ResponseTaker &responseTaker, BinaryQueue &responseQueue)
+ RequestContext(int desc, ResponseTakerPtr responseTaker, BinaryQueue &responseQueue)
: m_desc(desc), m_responseTaker(responseTaker), m_responseQueue(responseQueue) {
}
template <class T>
- void returnResponse(T &&response) const {
- m_responseTaker.appendResponseToBuffer(m_responseQueue, std::move(response));
+ void returnResponse(RequestContextPtr self, T &&response) const {
+ ResponseTakerPtr taker = m_responseTaker.lock();
+ if (taker)
+ taker->execute(self, std::move(response));
+ }
+
+ BinaryQueue &responseQueue(void) const {
+ return m_responseQueue;
}
};
* @brief This file implements RequestTaker class
*/
+#include <common.h>
+
#include <exceptions/NotImplementedException.h>
#include "RequestTaker.h"
namespace Cynara {
-void RequestTaker::execute(const RequestContext &context UNUSED, CheckRequestPtr request UNUSED) {
+void RequestTaker::execute(RequestContextPtr context UNUSED, CheckRequestPtr request UNUSED) {
throw NotImplementedException();
}
#define SRC_SERVICE_REQUEST_REQUESTTAKER_H_
#include <request/pointers.h>
-#include <request/RequestContext.h>
namespace Cynara {
RequestTaker() = default;
virtual ~RequestTaker() = default;
- virtual void execute(const RequestContext &context, CheckRequestPtr request);
+ virtual void execute(RequestContextPtr context, CheckRequestPtr request);
};
} // namespace Cynara
namespace Cynara {
+class CheckRequest;
+typedef std::shared_ptr<CheckRequest> CheckRequestPtr;
+
class Request;
typedef std::shared_ptr<Request> RequestPtr;
-class CheckRequest;
-typedef std::shared_ptr<CheckRequest> CheckRequestPtr;
+class RequestContext;
+typedef std::shared_ptr<RequestContext> RequestContextPtr;
} // namespace Cynara
namespace Cynara {
-void ResponseTaker::appendResponseToBuffer(BinaryQueue &queue UNUSED,
- CheckResponse &&response UNUSED) {
+void ResponseTaker::execute(RequestContextPtr context UNUSED, CheckResponse &&response UNUSED) {
throw NotImplementedException();
}
#include <common.h>
+#include <request/pointers.h>
#include <response/CheckResponse.h>
namespace Cynara {
ResponseTaker() = default;
virtual ~ResponseTaker() = default;
- virtual void appendResponseToBuffer(BinaryQueue &queue, CheckResponse &&response);
+ virtual void execute(RequestContextPtr context, CheckResponse &&response);
};
} // namespace Cynara
--- /dev/null
+/*
+ * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * @file pointers.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file defines response classes pointers
+ */
+
+#ifndef SRC_SERVICE_RESPONSE_POINTERS_H_
+#define SRC_SERVICE_RESPONSE_POINTERS_H_
+
+#include <memory>
+
+namespace Cynara {
+
+class ResponseTaker;
+typedef std::shared_ptr<ResponseTaker> ResponseTakerPtr;
+typedef std::weak_ptr<ResponseTaker> ResponseTakerWeakPtr;
+
+} // namespace Cynara
+
+#endif /* SRC_SERVICE_RESPONSE_POINTERS_H_ */
return !(m_writeQueue.empty() && m_writeBuffer.empty());
}
+ResponseTakerPtr Descriptor::responseTaker(void) const {
+ return std::static_pointer_cast<ResponseTaker>(m_protocol);
+}
+
void Descriptor::pushReadBuffer(const RawBuffer &readbuffer) {
m_readQueue.appendCopy(readbuffer.data(), readbuffer.size());
}
#include <protocol/Protocol.h>
#include <request/Request.h>
+#include <response/pointers.h>
namespace Cynara {
return m_protocol;
}
- ResponseTaker &responseTaker(void) {
- return *m_protocol;
- }
+ ResponseTakerPtr responseTaker(void) const;
BinaryQueue &writeQueue(void) {
return m_writeQueue;
LOGD("request extracted");
//build context
- RequestContext context(fd, desc.responseTaker(), desc.writeQueue());
+ auto context = std::make_shared<RequestContext>(fd, desc.responseTaker(),
+ desc.writeQueue());
//pass request to request taker
req->execute(req, requestTaker(), context);
}