Refactor client and server side contexts 79/151679/7
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 21 Sep 2017 12:16:35 +0000 (14:16 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 12 Oct 2017 13:37:57 +0000 (15:37 +0200)
- Get rid of files and typedefs with identical names
- Simplify client & server side context

Change-Id: Ib6580b228fd6b9d8771eb81adc06d2b2fef2775b

27 files changed:
lib/client.cpp
lib/client.h
lib/context.h [deleted file]
lib/extension-encryption.cpp
lib/extension-encryption.h
lib/external-encryption.cpp
lib/external-encryption.h
lib/internal-encryption.cpp
lib/internal-encryption.h
lib/ode/extension-encryption.cpp
lib/ode/external-encryption.cpp
lib/ode/internal-encryption.cpp
lib/ode/secure-erase.cpp
lib/secure-erase.cpp
lib/secure-erase.h
server/context.h [deleted file]
server/extension-encryption.cpp
server/extension-encryption.h
server/external-encryption.cpp
server/external-encryption.h
server/internal-encryption.cpp
server/internal-encryption.h
server/main.cpp
server/secure-erase.cpp
server/secure-erase.h
server/server.cpp
server/server.h

index 25d8cb2..a548f1a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
@@ -18,8 +18,8 @@
 
 namespace {
 
-const std::string SUBSCRIBER_REGISTER = "Server::registerNotificationSubscriber";
-const std::string SUBSCRIBER_UNREGISTER = "Server::unregisterNotificationSubscriber";
+const std::string SUBSCRIBER_REGISTER = "ServerContext::registerNotificationSubscriber";
+const std::string SUBSCRIBER_UNREGISTER = "ServerContext::unregisterNotificationSubscriber";
 
 
 const std::string ODE_MANAGER_ADDRESS = "/tmp/.ode.sock";
@@ -27,16 +27,16 @@ const std::string ODE_MANAGER_ADDRESS = "/tmp/.ode.sock";
 } // namespace
 
 
-ODEContext::ODEContext() noexcept
+ClientContext::ClientContext() noexcept
 {
 }
 
-ODEContext::~ODEContext() noexcept
+ClientContext::~ClientContext() noexcept
 {
        disconnect();
 }
 
-int ODEContext::connect(const std::string& address) noexcept
+int ClientContext::connect(const std::string& address) noexcept
 {
        try {
                client.reset(new rmi::Client(address));
@@ -48,17 +48,17 @@ int ODEContext::connect(const std::string& address) noexcept
        return 0;
 }
 
-int ODEContext::connect() noexcept
+int ClientContext::connect() noexcept
 {
        return connect(ODE_MANAGER_ADDRESS);
 }
 
-void ODEContext::disconnect() noexcept
+void ClientContext::disconnect() noexcept
 {
        client.reset();
 }
 
-int ODEContext::subscribeSignal(const std::string& name,
+int ClientContext::subscribeSignal(const std::string& name,
                                                                        const SignalListener& listener,
                                                                        void* data)
 {
@@ -75,7 +75,7 @@ int ODEContext::subscribeSignal(const std::string& name,
        }
 }
 
-int ODEContext::unsubscribeSignal(int subscriberId)
+int ClientContext::unsubscribeSignal(int subscriberId)
 {
        return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId);
 }
index 70d7369..7da3a6e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
 
 typedef std::function<void(void*)> SignalListener;
 
-class ODEContext final {
-public:
-       typedef std::unique_ptr<rmi::Client> ODEControlContext;
+typedef std::unique_ptr<rmi::Client> RmiClientPtr;
 
-       ODEContext() noexcept;
-       ~ODEContext() noexcept;
+class ClientContext final {
+public:
+       ClientContext() noexcept;
+       ~ClientContext() noexcept;
 
        int connect() noexcept;
        int connect(const std::string& address) noexcept;
@@ -42,17 +42,11 @@ public:
        template<typename Interface, typename... Args>
        Interface createInterface(Args&&... args) noexcept
        {
-               return Interface(getODEControlContext(), std::forward<Args>(args)...);
+               return Interface(client, std::forward<Args>(args)...);
        }
 
 private:
-       ODEControlContext& getODEControlContext()
-       {
-               return client;
-       }
-
-       ODEControlContext client;
+       RmiClientPtr client;
 };
 
-ODEContext& GetODEContext(void* handle);
 #endif //__ODE_CLIENT_H__
diff --git a/lib/context.h b/lib/context.h
deleted file mode 100644 (file)
index a1bc546..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- *  Copyright (c) 2015 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
- */
-
-#ifndef __ODE_CONTEXT__
-#define __ODE_CONTEXT__
-
-#include "client.h"
-
-using ODEControlContext = ::ODEContext::ODEControlContext;
-
-#endif //!__ODE_CONTEXT__
index 40c399a..9ab36da 100644 (file)
@@ -17,7 +17,7 @@
 
 namespace ode {
 
-ExtensionEncryptionClient::ExtensionEncryptionClient(ODEControlContext& ctx) :
+ExtensionEncryptionClient::ExtensionEncryptionClient(RmiClientPtr& ctx) :
        context(ctx)
 {
 }
index 328f683..7c3cdd5 100644 (file)
 #include <string>
 
 #include "rmi/extension-encryption.h"
-#include "context.h"
+#include "client.h"
 
 namespace ode {
 
 class ExtensionEncryptionClient final: public ExtensionEncryption {
 public:
-       ExtensionEncryptionClient(ODEControlContext& ctxt);
+       ExtensionEncryptionClient(RmiClientPtr& ctxt);
        ~ExtensionEncryptionClient();
 
        int setMountPassword(const std::string& password);
@@ -45,7 +45,7 @@ public:
        int getState();
 
 private:
-       ODEControlContext& context;
+       RmiClientPtr& context;
 };
 
 } // namespace ode
index 08b89cd..9870b8c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
@@ -17,7 +17,7 @@
 
 namespace ode {
 
-ExternalEncryptionClient::ExternalEncryptionClient(ODEControlContext& ctx) :
+ExternalEncryptionClient::ExternalEncryptionClient(RmiClientPtr& ctx) :
        context(ctx)
 {
 }
index e50f60b..705b740 100644 (file)
 #include <string>
 
 #include "rmi/external-encryption.h"
-#include "context.h"
+#include "client.h"
 
 namespace ode {
 
 class ExternalEncryptionClient final: public ExternalEncryption {
 public:
-       ExternalEncryptionClient(ODEControlContext& ctxt);
+       ExternalEncryptionClient(RmiClientPtr& ctxt);
        ~ExternalEncryptionClient();
 
        int setMountPassword(const std::string& password);
@@ -50,7 +50,7 @@ public:
        unsigned int getSupportedOptions();
 
 private:
-       ODEControlContext& context;
+       RmiClientPtr& context;
 };
 
 } // namespace ode
index 77d556a..614e023 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
@@ -17,7 +17,7 @@
 
 namespace ode {
 
-InternalEncryptionClient::InternalEncryptionClient(ODEControlContext& ctx) :
+InternalEncryptionClient::InternalEncryptionClient(RmiClientPtr& ctx) :
        context(ctx)
 {
 }
index 1cff276..fe68ee5 100644 (file)
 #include <string>
 
 #include "rmi/internal-encryption.h"
-#include "context.h"
+#include "client.h"
 
 namespace ode {
 
 class InternalEncryptionClient final: public InternalEncryption {
 public:
-       InternalEncryptionClient(ODEControlContext& ctxt);
+       InternalEncryptionClient(RmiClientPtr& ctxt);
        ~InternalEncryptionClient();
 
        int setMountPassword(const std::string& password);
@@ -50,7 +50,7 @@ public:
        unsigned int getSupportedOptions();
 
 private:
-       ODEControlContext& context;
+       RmiClientPtr& context;
 };
 
 } // namespace ode
index abaf4c5..39ac413 100644 (file)
@@ -26,7 +26,7 @@ int ode_extension_encryption_set_mount_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -35,7 +35,7 @@ int ode_extension_encryption_set_mount_password(const char* password)
 
 int ode_extension_encryption_mount()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -44,7 +44,7 @@ int ode_extension_encryption_mount()
 
 int ode_extension_encryption_umount()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -55,7 +55,7 @@ int ode_extension_encryption_format(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -66,7 +66,7 @@ int ode_extension_encryption_is_password_initialized(bool* result)
 {
        RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
        int ret = extension.isPasswordInitialized();
@@ -81,7 +81,7 @@ int ode_extension_encryption_init_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -92,7 +92,7 @@ int ode_extension_encryption_clean_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -105,7 +105,7 @@ int ode_extension_encryption_change_password(const char* old_password,
        RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
 
@@ -117,7 +117,7 @@ int ode_extension_encryption_verify_password(const char* password, bool* result)
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
        int ret = extension.verifyPassword(password);
@@ -132,7 +132,7 @@ int ode_extension_encryption_get_state(int* state)
 {
        RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExtensionEncryptionClient extension = client.createInterface<ExtensionEncryptionClient>();
        int ret = extension.getState();
@@ -143,13 +143,13 @@ int ode_extension_encryption_get_state(int* state)
        return ODE_ERROR_NONE;
 }
 
-static std::unique_ptr<ODEContext> mountEventCallbackContext;
+static std::unique_ptr<ClientContext> mountEventCallbackContext;
 
 int ode_extension_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data)
 {
        RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER);
 
-       mountEventCallbackContext.reset(new ODEContext);
+       mountEventCallbackContext.reset(new ClientContext);
        RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
 
        int ret = mountEventCallbackContext->subscribeSignal("ExtensionEncryption::mount", callback, user_data);
index 7a4c014..f10b7e8 100644 (file)
@@ -26,7 +26,7 @@ int ode_external_encryption_set_mount_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -35,7 +35,7 @@ int ode_external_encryption_set_mount_password(const char* password)
 
 int ode_external_encryption_mount()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -44,7 +44,7 @@ int ode_external_encryption_mount()
 
 int ode_external_encryption_umount()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -55,7 +55,7 @@ int ode_external_encryption_encrypt(const char* password, unsigned int options)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -66,7 +66,7 @@ int ode_external_encryption_decrypt(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -75,7 +75,7 @@ int ode_external_encryption_decrypt(const char* password)
 
 int ode_external_encryption_recovery()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -86,7 +86,7 @@ int ode_external_encryption_is_password_initialized(bool* result)
 {
        RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        int ret = external.isPasswordInitialized();
@@ -101,7 +101,7 @@ int ode_external_encryption_init_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -112,7 +112,7 @@ int ode_external_encryption_clean_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -125,7 +125,7 @@ int ode_external_encryption_change_password(const char* old_password,
        RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
 
@@ -137,7 +137,7 @@ int ode_external_encryption_verify_password(const char* password, bool* result)
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        int ret = external.verifyPassword(password);
@@ -152,7 +152,7 @@ int ode_external_encryption_get_state(int* state)
 {
        RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        int ret = external.getState();
@@ -167,20 +167,20 @@ int ode_external_encryption_get_supported_options(unsigned int* options)
 {
        RET_ON_FAILURE(options, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        ExternalEncryptionClient external = client.createInterface<ExternalEncryptionClient>();
        *options = external.getSupportedOptions();
        return ODE_ERROR_NONE;
 }
 
-static std::unique_ptr<ODEContext> mountEventCallbackContext;
+static std::unique_ptr<ClientContext> mountEventCallbackContext;
 
 int ode_external_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data)
 {
        RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER);
 
-       mountEventCallbackContext.reset(new ODEContext);
+       mountEventCallbackContext.reset(new ClientContext);
        RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
 
        int ret = mountEventCallbackContext->subscribeSignal("ExternalEncryption::mount", callback, user_data);
index 624b269..8364cbf 100644 (file)
@@ -26,7 +26,7 @@ int ode_internal_encryption_set_mount_password(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -35,7 +35,7 @@ int ode_internal_encryption_set_mount_password(const char* password)
 
 int ode_internal_encryption_mount()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -44,7 +44,7 @@ int ode_internal_encryption_mount()
 
 int ode_internal_encryption_umount()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -55,7 +55,7 @@ int ode_internal_encryption_encrypt(const char* password, unsigned int options)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -66,7 +66,7 @@ int ode_internal_encryption_decrypt(const char* password)
 {
        RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -75,7 +75,7 @@ int ode_internal_encryption_decrypt(const char* password)
 
 int ode_internal_encryption_recovery()
 {
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -86,7 +86,7 @@ int ode_internal_encryption_is_password_initialized(bool* result)
 {
     RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-    ODEContext client;
+    ClientContext client;
     RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        int ret = internal.isPasswordInitialized();
@@ -101,7 +101,7 @@ int ode_internal_encryption_init_password(const char* password)
 {
     RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-    ODEContext client;
+    ClientContext client;
     RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -112,7 +112,7 @@ int ode_internal_encryption_clean_password(const char* password)
 {
     RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
 
-    ODEContext client;
+    ClientContext client;
     RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -125,7 +125,7 @@ int ode_internal_encryption_change_password(const char* old_password,
        RET_ON_FAILURE(old_password, ODE_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(new_password, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
 
@@ -137,7 +137,7 @@ int ode_internal_encryption_verify_password(const char* password, bool* result)
     RET_ON_FAILURE(password, ODE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(result, ODE_ERROR_INVALID_PARAMETER);
 
-    ODEContext client;
+    ClientContext client;
     RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        int ret = internal.verifyPassword(password);
@@ -152,7 +152,7 @@ int ode_internal_encryption_get_state(int* state)
 {
        RET_ON_FAILURE(state, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        int ret = internal.getState();
@@ -167,20 +167,20 @@ int ode_internal_encryption_get_supported_options(unsigned int* options)
 {
        RET_ON_FAILURE(options, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        InternalEncryptionClient internal = client.createInterface<InternalEncryptionClient>();
        *options = internal.getSupportedOptions();
        return ODE_ERROR_NONE;
 }
 
-static std::unique_ptr<ODEContext> mountEventCallbackContext;
+static std::unique_ptr<ClientContext> mountEventCallbackContext;
 
 int ode_internal_encryption_set_mount_event_cb(ode_mount_event_cb callback, void *user_data)
 {
        RET_ON_FAILURE(callback, ODE_ERROR_INVALID_PARAMETER);
 
-       mountEventCallbackContext.reset(new ODEContext);
+       mountEventCallbackContext.reset(new ClientContext);
        RET_ON_FAILURE(mountEventCallbackContext->connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
 
     int ret = mountEventCallbackContext->subscribeSignal("InternalEncryptionServer::mount", callback, user_data);
index 5bda353..64d97f8 100644 (file)
@@ -26,7 +26,7 @@ int ode_secure_clean(const char* name)
 {
        RET_ON_FAILURE(name, ODE_ERROR_INVALID_PARAMETER);
 
-       ODEContext client;
+       ClientContext client;
        RET_ON_FAILURE(client.connect() == 0, ODE_ERROR_CONNECTION_REFUSED);
        SecureEraseClient secure = client.createInterface<SecureEraseClient>();
 
index 579437e..f582efa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
@@ -17,7 +17,7 @@
 
 namespace ode {
 
-SecureEraseClient::SecureEraseClient(ODEControlContext& ctx) :
+SecureEraseClient::SecureEraseClient(RmiClientPtr& ctx) :
        context(ctx)
 {
 }
index 0434a51..e4fa918 100644 (file)
 #include <string>
 
 #include "rmi/secure-erase.h"
-#include "context.h"
+#include "client.h"
 
 namespace ode {
 
 class SecureEraseClient final: public SecureErase {
 public:
-       SecureEraseClient(ODEControlContext& ctxt);
+       SecureEraseClient(RmiClientPtr& ctxt);
        ~SecureEraseClient();
 
        int clean(const std::string& name);
 
 private:
-       ODEControlContext& context;
+       RmiClientPtr& context;
 };
 
 } // namespace ode
diff --git a/server/context.h b/server/context.h
deleted file mode 100644 (file)
index 718bbab..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- *  Copyright (c) 2015 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
- */
-
-#ifndef __ODE_CONTEXT_H__
-#define __ODE_CONTEXT_H__
-
-#include "server.h"
-
-using ODEControlContext = Server;
-
-#endif //__ODE_CONTEXT_H__
index e085d05..3f091fc 100644 (file)
@@ -73,22 +73,22 @@ bool findKillAndUmount(const std::string &devPath)
 
 } // namsepace
 
-ExtensionEncryptionServer::ExtensionEncryptionServer(ODEControlContext &ctx) :
-       context(ctx),
+ExtensionEncryptionServer::ExtensionEncryptionServer(ServerContext &srv) :
+       server(srv),
        currentReq(Request::NONE)
 {
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::setMountPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::mount)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::umount)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::format)(std::string));
-       context.expose(this, "", (int)(ExtensionEncryptionServer::isPasswordInitialized)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::initPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::cleanPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::changePassword)(std::string, std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::verifyPassword)(std::string));
-       context.expose(this, "", (int)(ExtensionEncryptionServer::getState)());
-
-       context.createNotification("ExtensionEncryptionServer::mount");
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::setMountPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::mount)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::umount)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::format)(std::string));
+       server.expose(this, "", (int)(ExtensionEncryptionServer::isPasswordInitialized)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::initPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::cleanPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::changePassword)(std::string, std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExtensionEncryptionServer::verifyPassword)(std::string));
+       server.expose(this, "", (int)(ExtensionEncryptionServer::getState)());
+
+       server.createNotification("ExtensionEncryptionServer::mount");
 
        // TODO: think about handling more than one card / more than one engine
        // it would require global API change to select which card is handled atm
@@ -165,7 +165,7 @@ int ExtensionEncryptionServer::mount()
                }
        }
 
-       context.notify("ExtensionEncryptionServer::mount");
+       server.notify("ExtensionEncryptionServer::mount");
        return 0;
 }
 
index 5f2a08f..ede4249 100644 (file)
 #include <memory>
 #include <condition_variable>
 
-#include "context.h"
 #include "rmi/extension-encryption.h"
 #include "key-manager/key-manager.h"
 #include "engine/encryption/cryptsetup-engine.h"
+#include "server.h"
 
 namespace ode {
 
@@ -33,7 +33,7 @@ typedef CryptsetupEngine EXTENSION_ENGINE;
 
 class ExtensionEncryptionServer final: public ExtensionEncryption {
 public:
-       ExtensionEncryptionServer(ODEControlContext& ctxt);
+       ExtensionEncryptionServer(ServerContext& srv);
        ~ExtensionEncryptionServer();
 
        int setMountPassword(const std::string& password);
@@ -110,7 +110,7 @@ private:
        bool isOpened() const;
        bool isMounted() const;
 
-       ODEControlContext& context;
+       ServerContext& server;
 
        // currently inserted card information, empty if no card:
        DevInfo info[DEVICE_MAX];
index 41648a7..886ce6b 100644 (file)
@@ -188,23 +188,23 @@ void setOptions(unsigned int options)
 
 } // namsepace
 
-ExternalEncryptionServer::ExternalEncryptionServer(ODEControlContext &ctx) :
-       context(ctx)
+ExternalEncryptionServer::ExternalEncryptionServer(ServerContext &srv) :
+       server(srv)
 {
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::setMountPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::mount)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::umount)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::encrypt)(std::string, unsigned int));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::decrypt)(std::string));
-       context.expose(this, "", (int)(ExternalEncryptionServer::isPasswordInitialized)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::initPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::cleanPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::changePassword)(std::string, std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::verifyPassword)(std::string));
-       context.expose(this, "", (int)(ExternalEncryptionServer::getState)());
-       context.expose(this, "", (unsigned int)(ExternalEncryptionServer::getSupportedOptions)());
-
-       context.createNotification("ExternalEncryptionServer::mount");
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::setMountPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::mount)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::umount)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::encrypt)(std::string, unsigned int));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::decrypt)(std::string));
+       server.expose(this, "", (int)(ExternalEncryptionServer::isPasswordInitialized)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::initPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::cleanPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::changePassword)(std::string, std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(ExternalEncryptionServer::verifyPassword)(std::string));
+       server.expose(this, "", (int)(ExternalEncryptionServer::getState)());
+       server.expose(this, "", (unsigned int)(ExternalEncryptionServer::getSupportedOptions)());
+
+       server.createNotification("ExternalEncryptionServer::mount");
 
        engine.reset(new EXTERNAL_ENGINE(
                EXTERNAL_PATH, EXTERNAL_PATH,
@@ -255,7 +255,7 @@ int ExternalEncryptionServer::mount()
                return -3;
        }
 
-       context.notify("ExternalEncryptionServer::mount");
+       server.notify("ExternalEncryptionServer::mount");
 
        return 0;
 }
@@ -307,7 +307,7 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int
                        setOptions(options & getSupportedOptions());
                        INFO(SINK, "Encryption completed");
                        ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted");
-                       context.notify("ExternalEncryptionServer::mount");
+                       server.notify("ExternalEncryptionServer::mount");
                        INFO(SINK, "Sync disk...");
                        sync();
                } catch (runtime::Exception &e) {
index 0ec5dd4..15ba976 100644 (file)
 
 #include <klay/dbus/connection.h>
 
-#include "context.h"
 #include "rmi/external-encryption.h"
 #include "key-manager/key-manager.h"
 #include "engine/encryption/ecryptfs-engine.h"
+#include "server.h"
 
 namespace ode {
 
@@ -34,7 +34,7 @@ typedef EcryptfsEngine EXTERNAL_ENGINE;
 
 class ExternalEncryptionServer final: public ExternalEncryption {
 public:
-       ExternalEncryptionServer(ODEControlContext& ctxt);
+       ExternalEncryptionServer(ServerContext& srv);
        ~ExternalEncryptionServer();
 
        int setMountPassword(const std::string& password);
@@ -58,7 +58,7 @@ public:
        unsigned int getSupportedOptions();
 
 private:
-       ODEControlContext& context;
+       ServerContext& server;
 
        std::unique_ptr<EXTERNAL_ENGINE> engine;
        KeyManager::data mountKey;
index 30ff4a0..f03b006 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
@@ -228,23 +228,23 @@ void setOptions(unsigned int options)
 
 }
 
-InternalEncryptionServer::InternalEncryptionServer(ODEControlContext& ctx) :
-       context(ctx)
+InternalEncryptionServer::InternalEncryptionServer(ServerContext& srv) :
+       server(srv)
 {
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::setMountPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::mount)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::umount)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::encrypt)(std::string, unsigned int));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::decrypt)(std::string));
-       context.expose(this, "", (int)(InternalEncryptionServer::isPasswordInitialized)());
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::initPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::cleanPassword)(std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::changePassword)(std::string, std::string));
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::verifyPassword)(std::string));
-       context.expose(this, "", (int)(InternalEncryptionServer::getState)());
-       context.expose(this, "", (unsigned int)(InternalEncryptionServer::getSupportedOptions)());
-
-       context.createNotification("InternalEncryptionServer::mount");
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::setMountPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::mount)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::umount)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::encrypt)(std::string, unsigned int));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::decrypt)(std::string));
+       server.expose(this, "", (int)(InternalEncryptionServer::isPasswordInitialized)());
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::initPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::cleanPassword)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::changePassword)(std::string, std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(InternalEncryptionServer::verifyPassword)(std::string));
+       server.expose(this, "", (int)(InternalEncryptionServer::getState)());
+       server.expose(this, "", (unsigned int)(InternalEncryptionServer::getSupportedOptions)());
+
+       server.createNotification("InternalEncryptionServer::mount");
 
        std::string source = findDevPath();
 
@@ -290,7 +290,7 @@ int InternalEncryptionServer::mount()
                engine->mount(mountKey, getOptions());
                mountKey.clear();
 
-               context.notify("InternalEncryptionServer::mount");
+               server.notify("InternalEncryptionServer::mount");
 
                runtime::File("/tmp/.lazy_mount").create(O_WRONLY);
                runtime::File("/tmp/.unlock_mnt").create(O_WRONLY);
@@ -371,7 +371,7 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int
 
                        INFO(SINK, "Encryption completed");
                        ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "encrypted");
-                       context.notify("InternalEncryptionServer::mount");
+                       server.notify("InternalEncryptionServer::mount");
 
                        INFO(SINK, "Syncing disk and rebooting...");
                        ::sync();
index ea48de3..57de876 100644 (file)
 #include <string>
 #include <memory>
 
-#include "context.h"
 #include "rmi/internal-encryption.h"
 #include "key-manager/key-manager.h"
 #include "engine/encryption/dmcrypt-engine.h"
+#include "server.h"
 
 namespace ode {
 
@@ -31,7 +31,7 @@ typedef DMCryptEngine INTERNAL_ENGINE;
 
 class InternalEncryptionServer final: public InternalEncryption {
 public:
-       InternalEncryptionServer(ODEControlContext& ctxt);
+       InternalEncryptionServer(ServerContext& srv);
        ~InternalEncryptionServer();
 
        int setMountPassword(const std::string& password);
@@ -55,7 +55,7 @@ public:
        unsigned int getSupportedOptions();
 
 private:
-       ODEControlContext& context;
+       ServerContext& server;
 
        std::unique_ptr<INTERNAL_ENGINE> engine;
        KeyManager::data mountKey;
index 8c15275..1a85a3c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
@@ -42,8 +42,8 @@ int main(int argc, char *argv[])
 
        try {
                ScopedGMainLoop gmainloop;
-               Server server;
-               server.run();
+               ode::ServerContext server;
+               server.start();
        } catch (std::exception &e) {
                std::cerr << e.what() << std::endl;
                return 1;
index f4d036e..d11af7e 100644 (file)
@@ -19,7 +19,6 @@
 #include <unistd.h>
 #include <mntent.h>
 
-#include "ext4-tool.h"
 #include "secure-erase.h"
 
 namespace ode {
@@ -47,10 +46,10 @@ std::string findDevPath(const std::string &mntPath)
 }
 } /* namespace */
 
-SecureEraseServer::SecureEraseServer(ODEControlContext &ctx) :
-       context(ctx)
+SecureEraseServer::SecureEraseServer(ServerContext &srv) :
+       server(srv)
 {
-       context.expose(this, PRIVILEGE_PLATFORM, (int)(SecureEraseServer::clean)(std::string));
+       server.expose(this, PRIVILEGE_PLATFORM, (int)(SecureEraseServer::clean)(std::string));
 
        engine.reset(new ERASE_ENGINE(ProgressBar([](int v) {
                        ::vconf_set_str(VCONFKEY_ODE_ERASE_PROGRESS, std::to_string(v).c_str());
index acfd91f..339dbbf 100644 (file)
@@ -20,9 +20,9 @@
 #include <string>
 #include <memory>
 
-#include "context.h"
 #include "rmi/secure-erase.h"
 #include "engine/erase/mmc-engine.h"
+#include "server.h"
 
 namespace ode {
 
@@ -30,14 +30,14 @@ typedef MMCEraseEngine ERASE_ENGINE;
 
 class SecureEraseServer final: public SecureErase {
 public:
-       SecureEraseServer(ODEControlContext& ctxt);
+       SecureEraseServer(ServerContext& srv);
        ~SecureEraseServer();
 
        int erase(const std::string& name);
        int clean(const std::string& name);
 
 private:
-       ODEControlContext& context;
+       ServerContext& server;
 
        std::unique_ptr<ERASE_ENGINE> engine;
 };
index 5baf9f7..2d60439 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
 #include "external-encryption.h"
 #include "extension-encryption.h"
 #include "key-manager/key-generator.h"
-
 #include "server.h"
 
 using namespace std::placeholders;
 
+audit::LogSink *SINK = nullptr;
+
+namespace ode {
+
 namespace {
 
 const std::string ODE_MANAGER_ADDRESS = "/tmp/.ode.sock";
-
-std::unique_ptr<ode::SecureEraseServer> secureErase;
-std::unique_ptr<ode::InternalEncryptionServer> internalEncryption;
-std::unique_ptr<ode::ExternalEncryptionServer> externalEncryption;
-std::unique_ptr<ode::ExtensionEncryptionServer> extensionEncryption;
 std::unique_ptr<audit::DlogLogSink> _sink = nullptr;
 
 } // namespace
 
 audit::LogSink *SINK = nullptr;
 
-Server::Server()
+ServerContext::ServerContext() : rmi::Service(ODE_MANAGER_ADDRESS)
 {
        _sink.reset(new audit::DlogLogSink("ODE"));
-       SINK = dynamic_cast<audit::LogSink*>((_sink).get());
+       SINK = _sink.get();
 
        INFO(SINK, "ODE server starting.");
 
-       service.reset(new rmi::Service(ODE_MANAGER_ADDRESS));
-
-       service->setPrivilegeChecker(std::bind(&Server::checkPeerPrivilege, this, _1, _2));
+       setPrivilegeChecker(std::bind(&ServerContext::checkPeerPrivilege, this, _1, _2));
 
-       service->expose(this, "", (runtime::FileDescriptor)(Server::registerNotificationSubscriber)(std::string));
-       service->expose(this, "", (int)(Server::unregisterNotificationSubscriber)(std::string, int));
+       expose(this, "", (runtime::FileDescriptor)(ServerContext::registerNotificationSubscriber)(std::string));
+       expose(this, "", (int)(ServerContext::unregisterNotificationSubscriber)(std::string, int));
 
-       secureErase.reset(new ode::SecureEraseServer(*this));
-       internalEncryption.reset(new ode::InternalEncryptionServer(*this));
-       externalEncryption.reset(new ode::ExternalEncryptionServer(*this));
-       extensionEncryption.reset(new ode::ExtensionEncryptionServer(*this));
+       secureErase.reset(new SecureEraseServer(*this));
+       internalEncryption.reset(new InternalEncryptionServer(*this));
+       externalEncryption.reset(new ExternalEncryptionServer(*this));
+       extensionEncryption.reset(new ExtensionEncryptionServer(*this));
 
-       ode::KeyGenerator::init();
+       KeyGenerator::init();
 }
 
-Server::~Server()
+ServerContext::~ServerContext()
 {
-       ode::KeyGenerator::cleanup();
+       KeyGenerator::cleanup();
 }
 
-void Server::run()
-{
-       // Prepare execution environment
-       service->start();
-}
-
-void Server::terminate()
-{
-       service->stop();
-}
-
-bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege)
+bool ServerContext::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege)
 {
        cynara *p_cynara;
 
@@ -107,14 +92,16 @@ bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string&
        return true;
 }
 
-runtime::FileDescriptor Server::registerNotificationSubscriber(const std::string& name)
+runtime::FileDescriptor ServerContext::registerNotificationSubscriber(const std::string& name)
 {
        INFO(SINK, "registerNotificationSubscriber");
        INFO(SINK, name);
-       return runtime::FileDescriptor(service->subscribeNotification(name), true);
+       return runtime::FileDescriptor(subscribeNotification(name), true);
 }
 
-int Server::unregisterNotificationSubscriber(const std::string& name, int id)
+int ServerContext::unregisterNotificationSubscriber(const std::string& name, int id)
 {
-       return service->unsubscribeNotification(name, id);
+       return unsubscribeNotification(name, id);
 }
+
+} // namespace ode
index d7a439d..fb12ab0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2015-2017 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.
 #include <string>
 #include <memory>
 
-#include <klay/filesystem.h>
 #include <klay/file-descriptor.h>
 #include <klay/rmi/service.h>
 
-class Server final {
-public:
-       Server();
-       ~Server();
-
-       void run();
-       void terminate();
-
-       template<typename Type, typename... Args>
-       void setMethodHandler(const std::string& privilege, const std::string& method,
-                                                 const typename rmi::MethodHandler<Type, Args...>::type& handler)
-       {
-               service->setMethodHandler<Type, Args...>(privilege, method, handler);
-       }
-
-       template <typename... Args>
-       void notify(const std::string& name, Args&&... args)
-       {
-               service->notify<Args...>(name, std::forward<Args>(args)...);
-       }
-
-       uid_t getPeerUid() const
-       {
-               return service->getPeerUid();
-       }
+namespace ode {
 
-       gid_t getPeerGid() const
-       {
-               return service->getPeerGid();
-       }
+class SecureEraseServer;
+class InternalEncryptionServer;
+class ExternalEncryptionServer;
+class ExtensionEncryptionServer;
 
-       pid_t getPeerPid() const
-       {
-               return service->getPeerPid();
-       }
+class ServerContext final: public rmi::Service {
+public:
+       ServerContext();
+       ~ServerContext();
 
        bool checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege);
 
-
-       void createNotification(const std::string& name)
-       {
-               service->createNotification(name);
-       }
-
        runtime::FileDescriptor registerNotificationSubscriber(const std::string& name);
        int unregisterNotificationSubscriber(const std::string& name, int id);
 
 private:
-       std::string securityLabel;
-       std::unique_ptr<rmi::Service> service;
+       std::unique_ptr<SecureEraseServer> secureErase;
+       std::unique_ptr<InternalEncryptionServer> internalEncryption;
+       std::unique_ptr<ExternalEncryptionServer> externalEncryption;
+       std::unique_ptr<ExtensionEncryptionServer> extensionEncryption;
 };
 
+} // namespace ode
+
 #endif //__ODE_SERVER_H__