Disconnect all clients from cynara when policy rules change 41/25241/2
authorLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 31 Jul 2014 14:36:13 +0000 (16:36 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Thu, 31 Jul 2014 15:48:29 +0000 (17:48 +0200)
All actions that should be run when cynara policies change
are grouped in onPoliciesChanged() function.

Change-Id: I30687fc35258b448fcccc2d54955b57d8cbc82af

src/service/logic/Logic.cpp
src/service/logic/Logic.h

index 739add2..377bcce 100644 (file)
@@ -91,7 +91,7 @@ bool Logic::check(RequestContextPtr context UNUSED, const PolicyKey &key,
 
 void Logic::execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr request) {
     m_storage->addOrUpdateBucket(request->bucketId(), request->result());
-    m_storage->save();
+    onPoliciesChanged();
 
     context->returnResponse(context, std::make_shared<CodeResponse>(CodeResponse::Code::OK,
                             request->sequenceNumber()));
@@ -101,7 +101,7 @@ void Logic::execute(RequestContextPtr context, RemoveBucketRequestPtr request) {
     auto code = CodeResponse::Code::OK;
     try {
         m_storage->deleteBucket(request->bucketId());
-        m_storage->save();
+        onPoliciesChanged();
     } catch (const BucketNotExistsException &ex) {
         code = CodeResponse::Code::NO_BUCKET;
     } catch (const DefaultBucketDeletionException &ex) {
@@ -116,7 +116,7 @@ void Logic::execute(RequestContextPtr context, SetPoliciesRequestPtr request) {
     try {
         m_storage->insertPolicies(request->policiesToBeInsertedOrUpdated());
         m_storage->deletePolicies(request->policiesToBeRemoved());
-        m_storage->save();
+        onPoliciesChanged();
     } catch (const BucketNotExistsException &ex) {
         code = CodeResponse::Code::NO_BUCKET;
     }
@@ -124,4 +124,10 @@ void Logic::execute(RequestContextPtr context, SetPoliciesRequestPtr request) {
                             request->sequenceNumber()));
 }
 
+void Logic::onPoliciesChanged(void) {
+    m_storage->save();
+    m_socketManager->disconnectAllClients();
+    //todo remove all saved contexts (if there will be any saved contexts)
+}
+
 } // namespace Cynara
index e21419a..4e8a476 100644 (file)
@@ -62,6 +62,7 @@ private:
 
     bool check(RequestContextPtr context, const PolicyKey &key, PolicyResult& result);
 
+    void onPoliciesChanged(void);
 };
 
 } // namespace Cynara