Add Response class - base for all response classes.
Add extractResponseFromBuffer() method to all protocol classes.
Change all response objects references to shared pointers.
Change-Id: I9ac88c8e70ca8084bc2653a0b6aa545320d8de35
${COMMON_PATH}/protocol/ProtocolSignal.cpp
${COMMON_PATH}/request/CheckRequest.cpp
${COMMON_PATH}/request/RequestTaker.cpp
+ ${COMMON_PATH}/response/CheckResponse.cpp
${COMMON_PATH}/response/ResponseTaker.cpp
${COMMON_PATH}/types/PolicyBucket.cpp
${COMMON_PATH}/types/PolicyKey.cpp
#include <containers/BinaryQueue.h>
#include <request/pointers.h>
#include <request/RequestTaker.h>
+#include <response/pointers.h>
#include <response/ResponseTaker.h>
namespace Cynara {
virtual ~Protocol() = default;
virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue) = 0;
+ virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue) = 0;
};
typedef std::shared_ptr<Protocol> ProtocolPtr;
TODO_USE_ME(bufferQueue);
return RequestPtr(nullptr);
}
+
+ResponsePtr ProtocolAdmin::extractResponseFromBuffer(BinaryQueue &bufferQueue) {
+ TODO_USE_ME(bufferQueue);
+ return ResponsePtr(nullptr);
+}
+
} // namespace Cynara
virtual ~ProtocolAdmin();
virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
+ virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue);
};
} // namespace Cynara
return RequestPtr(nullptr);
}
+ResponsePtr ProtocolClient::extractResponseFromBuffer(BinaryQueue &bufferQueue) {
+ TODO_USE_ME(bufferQueue);
+ return ResponsePtr(nullptr);
+}
+
} // namespace Cynara
virtual ~ProtocolClient();
virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
+ virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue);
};
} // namespace Cynara
return RequestPtr(nullptr);
}
+ResponsePtr ProtocolSignal::extractResponseFromBuffer(BinaryQueue &bufferQueue) {
+ TODO_USE_ME(bufferQueue);
+ return ResponsePtr(nullptr);
+}
+
} // namespace Cynara
virtual ~ProtocolSignal();
virtual RequestPtr extractRequestFromBuffer(BinaryQueue &bufferQueue);
+ virtual ResponsePtr extractResponseFromBuffer(BinaryQueue &bufferQueue);
};
} // namespace Cynara
Request() = default;
virtual ~Request() = default;
- virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const = 0;
+ virtual void execute(RequestPtr self, RequestTakerPtr taker,
+ RequestContextPtr context) const = 0;
};
} // namespace Cynara
: m_desc(desc), m_responseTaker(responseTaker), m_responseQueue(responseQueue) {
}
- template <class T>
- void returnResponse(RequestContextPtr self, T &&response) const {
+ void returnResponse(RequestContextPtr self, ResponsePtr response) const {
ResponseTakerPtr taker = m_responseTaker.lock();
if (taker)
- taker->execute(self, std::move(response));
+ response->execute(response, taker, self);
}
BinaryQueue &responseQueue(void) const {
* @file pointers.h
* @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
* @version 1.0
- * @brief This file defines request base class
+ * @brief This file defines request classes pointers
*/
#ifndef SRC_COMMON_REQUEST_POINTERS_H_
--- /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 CheckRequest.cpp
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file implements check response class
+ */
+
+#include <memory>
+
+#include "CheckResponse.h"
+
+namespace Cynara {
+
+void CheckResponse::execute(ResponsePtr self, ResponseTakerPtr taker,
+ RequestContextPtr context) const {
+ taker->execute(context, std::dynamic_pointer_cast<CheckResponse>(self));
+}
+
+} // namespace Cynara
#include <types/PolicyResult.h>
+#include <request/pointers.h>
+#include <response/pointers.h>
+#include <response/Response.h>
+
namespace Cynara {
-struct CheckResponse {
+class CheckResponse : public Response {
+public:
const PolicyResult &m_resultRef;
CheckResponse(const PolicyResult &result) : m_resultRef(result) {
}
+
+ virtual ~CheckResponse() = default;
+
+ virtual void execute(ResponsePtr self, ResponseTakerPtr taker,
+ RequestContextPtr context) const;
};
} // 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 Response.h
+ * @author Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version 1.0
+ * @brief This file defines response base class
+ */
+
+#ifndef SRC_COMMON_RESPONSE_RESPONSE_H_
+#define SRC_COMMON_RESPONSE_RESPONSE_H_
+
+#include <response/pointers.h>
+#include <response/ResponseTaker.h>
+
+namespace Cynara {
+
+class Response {
+public:
+ Response() = default;
+ virtual ~Response() = default;
+
+ virtual void execute(ResponsePtr self, ResponseTakerPtr taker,
+ RequestContextPtr context) const = 0;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_RESPONSE_RESPONSE_H_ */
namespace Cynara {
-void ResponseTaker::execute(RequestContextPtr context UNUSED, CheckResponse &&response UNUSED) {
+void ResponseTaker::execute(RequestContextPtr context UNUSED, CheckResponsePtr response UNUSED) {
throw NotImplementedException();
}
ResponseTaker() = default;
virtual ~ResponseTaker() = default;
- virtual void execute(RequestContextPtr context, CheckResponse &&response);
+ virtual void execute(RequestContextPtr context, CheckResponsePtr response);
};
} // namespace Cynara
namespace Cynara {
+class CheckResponse;
+typedef std::shared_ptr<CheckResponse> CheckResponsePtr;
+
+class Response;
+typedef std::shared_ptr<Response> ResponsePtr;
+
class ResponseTaker;
typedef std::shared_ptr<ResponseTaker> ResponseTakerPtr;
typedef std::weak_ptr<ResponseTaker> ResponseTakerWeakPtr;
void Logic::execute(RequestContextPtr context, CheckRequestPtr request) {
PolicyResult result(PredefinedPolicyType::DENY);
if (check(context, request->key(), result)) {
- context->returnResponse(context, CheckResponse(result));
+ context->returnResponse(context, std::make_shared<CheckResponse>(result));
}
}