Add 3 new Request classes for administrating Cynara 41/24641/3
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 17 Jul 2014 13:36:05 +0000 (15:36 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 18 Jul 2014 06:45:08 +0000 (08:45 +0200)
Three added classes are:
InsertOrUpdateBucketRequest - for inserting new bucket or modyfying
    default policy of existing one;
RemoveBucketRequest - for removing bucket;
SetPoliciesRequest - for modification of policies (adding, updating,
    removing).

RequestTaker class has been extended with new execute() methods for
processing newly added Request objects.
Proper shared pointers definitions were added in request/pointers.h
for supporting new Request types.

Change-Id: I0a94eb9ce8326da4ccb9bd078d3a90b6bef25bfa

src/common/CMakeLists.txt
src/common/request/InsertOrUpdateBucketRequest.cpp [new file with mode: 0644]
src/common/request/InsertOrUpdateBucketRequest.h [new file with mode: 0644]
src/common/request/RemoveBucketRequest.cpp [new file with mode: 0644]
src/common/request/RemoveBucketRequest.h [new file with mode: 0644]
src/common/request/RequestTaker.cpp
src/common/request/RequestTaker.h
src/common/request/SetPoliciesRequest.cpp [new file with mode: 0644]
src/common/request/SetPoliciesRequest.h [new file with mode: 0644]
src/common/request/pointers.h

index 9e7cece..39b9e47 100644 (file)
@@ -32,7 +32,10 @@ SET(COMMON_SOURCES
     ${COMMON_PATH}/protocol/ProtocolSerialization.cpp
     ${COMMON_PATH}/protocol/ProtocolSignal.cpp
     ${COMMON_PATH}/request/CheckRequest.cpp
+    ${COMMON_PATH}/request/InsertOrUpdateBucketRequest.cpp
+    ${COMMON_PATH}/request/RemoveBucketRequest.cpp
     ${COMMON_PATH}/request/RequestTaker.cpp
+    ${COMMON_PATH}/request/SetPoliciesRequest.cpp
     ${COMMON_PATH}/request/SignalRequest.cpp
     ${COMMON_PATH}/response/CheckResponse.cpp
     ${COMMON_PATH}/response/ResponseTaker.cpp
diff --git a/src/common/request/InsertOrUpdateBucketRequest.cpp b/src/common/request/InsertOrUpdateBucketRequest.cpp
new file mode 100644 (file)
index 0000000..47900bc
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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        InsertOrUpdateBucketRequest.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements request class for inserting or updating policy bucket
+ */
+
+#include <memory>
+
+#include "InsertOrUpdateBucketRequest.h"
+
+namespace Cynara {
+
+void InsertOrUpdateBucketRequest::execute(RequestPtr self, RequestTakerPtr taker,
+                                          RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<InsertOrUpdateBucketRequest>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/request/InsertOrUpdateBucketRequest.h b/src/common/request/InsertOrUpdateBucketRequest.h
new file mode 100644 (file)
index 0000000..b166d71
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * 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        InsertOrUpdateBucketRequest.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines request class for inserting or updating policy bucket
+ */
+
+#ifndef SRC_COMMON_REQUEST_INSERTORUPDATEBUCKETREQUEST_H_
+#define SRC_COMMON_REQUEST_INSERTORUPDATEBUCKETREQUEST_H_
+
+#include <types/PolicyBucketId.h>
+#include <types/PolicyResult.h>
+
+#include <request/pointers.h>
+#include <request/Request.h>
+#include <request/RequestTaker.h>
+
+namespace Cynara {
+
+class InsertOrUpdateBucketRequest : public Request {
+private:
+    PolicyBucketId m_bucketId;
+    PolicyResult m_result;
+
+public:
+    InsertOrUpdateBucketRequest(const PolicyBucketId &bucketId, const PolicyResult &result,
+                                ProtocolFrameSequenceNumber sequenceNumber) :
+        Request(sequenceNumber), m_bucketId(bucketId), m_result(result) {
+    }
+
+    virtual ~InsertOrUpdateBucketRequest() = default;
+
+    const PolicyBucketId &bucketId(void) const {
+        return m_bucketId;
+    }
+
+    const PolicyResult &result(void) const {
+        return m_result;
+    }
+
+    virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_REQUEST_INSERTORUPDATEBUCKETREQUEST_H_ */
diff --git a/src/common/request/RemoveBucketRequest.cpp b/src/common/request/RemoveBucketRequest.cpp
new file mode 100644 (file)
index 0000000..69a2652
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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        RemoveBucketRequest.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements request class for bucket removal
+ */
+
+#include <memory>
+
+#include "RemoveBucketRequest.h"
+
+namespace Cynara {
+
+void RemoveBucketRequest::execute(RequestPtr self, RequestTakerPtr taker,
+                                  RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<RemoveBucketRequest>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/request/RemoveBucketRequest.h b/src/common/request/RemoveBucketRequest.h
new file mode 100644 (file)
index 0000000..ff49a43
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * 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        RemoveBucketRequest.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines request class for bucket removal
+ */
+
+#ifndef SRC_COMMON_REQUEST_REMOVEBUCKETREQUEST_H_
+#define SRC_COMMON_REQUEST_REMOVEBUCKETREQUEST_H_
+
+#include <types/PolicyBucketId.h>
+
+#include <request/pointers.h>
+#include <request/Request.h>
+#include <request/RequestTaker.h>
+
+namespace Cynara {
+
+class RemoveBucketRequest : public Request {
+private:
+    PolicyBucketId m_bucketId;
+
+public:
+    RemoveBucketRequest(const PolicyBucketId &bucketId, ProtocolFrameSequenceNumber sequenceNumber)
+        : Request(sequenceNumber), m_bucketId(bucketId) {
+    }
+
+    virtual ~RemoveBucketRequest() = default;
+
+    const PolicyBucketId &bucketId(void) const {
+        return m_bucketId;
+    }
+
+    virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_REQUEST_REMOVEBUCKETREQUEST_H_ */
index 4ed8e7f..843c80e 100644 (file)
@@ -33,6 +33,20 @@ void RequestTaker::execute(RequestContextPtr context UNUSED, CheckRequestPtr req
     throw NotImplementedException();
 }
 
+void RequestTaker::execute(RequestContextPtr context UNUSED,
+                           InsertOrUpdateBucketRequestPtr request UNUSED) {
+    throw NotImplementedException();
+}
+
+void RequestTaker::execute(RequestContextPtr context UNUSED,
+                           RemoveBucketRequestPtr request UNUSED) {
+    throw NotImplementedException();
+}
+
+void RequestTaker::execute(RequestContextPtr context UNUSED, SetPoliciesRequestPtr request UNUSED) {
+    throw NotImplementedException();
+}
+
 void RequestTaker::execute(RequestContextPtr context UNUSED, SignalRequestPtr request UNUSED) {
     throw NotImplementedException();
 }
index 1739ba6..0c3ff7d 100644 (file)
@@ -33,6 +33,9 @@ public:
     virtual ~RequestTaker() = default;
 
     virtual void execute(RequestContextPtr context, CheckRequestPtr request);
+    virtual void execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr request);
+    virtual void execute(RequestContextPtr context, RemoveBucketRequestPtr request);
+    virtual void execute(RequestContextPtr context, SetPoliciesRequestPtr request);
     virtual void execute(RequestContextPtr context, SignalRequestPtr request);
 };
 
diff --git a/src/common/request/SetPoliciesRequest.cpp b/src/common/request/SetPoliciesRequest.cpp
new file mode 100644 (file)
index 0000000..e2bfb6f
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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        SetPoliciesRequest.cpp
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file implements request class for modifying policies
+ */
+
+#include <memory>
+
+#include "SetPoliciesRequest.h"
+
+namespace Cynara {
+
+void SetPoliciesRequest::execute(RequestPtr self, RequestTakerPtr taker,
+                                 RequestContextPtr context) const {
+    taker->execute(context, std::dynamic_pointer_cast<SetPoliciesRequest>(self));
+}
+
+} // namespace Cynara
diff --git a/src/common/request/SetPoliciesRequest.h b/src/common/request/SetPoliciesRequest.h
new file mode 100644 (file)
index 0000000..d876ad1
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * 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        SetPoliciesRequest.h
+ * @author      Lukasz Wojciechowski <l.wojciechow@partner.samsung.com>
+ * @version     1.0
+ * @brief       This file defines request class for modifying policies
+ */
+
+#ifndef SRC_COMMON_REQUEST_SETPOLICIESREQUEST_H_
+#define SRC_COMMON_REQUEST_SETPOLICIESREQUEST_H_
+
+#include <map>
+#include <vector>
+
+#include <types/Policy.h>
+#include <types/PolicyBucketId.h>
+#include <types/PolicyKey.h>
+
+#include <request/pointers.h>
+#include <request/Request.h>
+#include <request/RequestTaker.h>
+
+namespace Cynara {
+
+class SetPoliciesRequest : public Request {
+private:
+    std::map<PolicyBucketId, std::vector<Policy>> m_insertOrUpdatePolicies;
+    std::map<PolicyBucketId, std::vector<PolicyKey>> m_removePolicies;
+
+public:
+    SetPoliciesRequest(const std::map<PolicyBucketId, std::vector<Policy>> &insertOrUpdatePolicies,
+                       const std::map<PolicyBucketId, std::vector<PolicyKey>> &removePolicies,
+                       ProtocolFrameSequenceNumber sequenceNumber) :
+        Request(sequenceNumber), m_insertOrUpdatePolicies(insertOrUpdatePolicies),
+        m_removePolicies(removePolicies) {
+    }
+
+    virtual ~SetPoliciesRequest() = default;
+
+    const std::map<PolicyBucketId, std::vector<Policy>> &policiesToBeInsertedOrUpdated(void) const {
+        return m_insertOrUpdatePolicies;
+    }
+
+    const std::map<PolicyBucketId, std::vector<PolicyKey>> &policiesToBeRemoved(void) const {
+        return m_removePolicies;
+    }
+
+    virtual void execute(RequestPtr self, RequestTakerPtr taker, RequestContextPtr context) const;
+};
+
+} // namespace Cynara
+
+#endif /* SRC_COMMON_REQUEST_SETPOLICIESREQUEST_H_ */
index b3c22e7..e04603e 100644 (file)
@@ -30,6 +30,12 @@ namespace Cynara {
 class CheckRequest;
 typedef std::shared_ptr<CheckRequest> CheckRequestPtr;
 
+class InsertOrUpdateBucketRequest;
+typedef std::shared_ptr<InsertOrUpdateBucketRequest> InsertOrUpdateBucketRequestPtr;
+
+class RemoveBucketRequest;
+typedef std::shared_ptr<RemoveBucketRequest> RemoveBucketRequestPtr;
+
 class Request;
 typedef std::shared_ptr<Request> RequestPtr;
 
@@ -39,6 +45,9 @@ typedef std::shared_ptr<RequestContext> RequestContextPtr;
 class RequestTaker;
 typedef std::shared_ptr<RequestTaker> RequestTakerPtr;
 
+class SetPoliciesRequest;
+typedef std::shared_ptr<SetPoliciesRequest> SetPoliciesRequestPtr;
+
 class SignalRequest;
 typedef std::shared_ptr<SignalRequest> SignalRequestPtr;