Classes encapsulation/abstraction changed in types 24/67324/1
authorKyungwook Tak <k.tak@samsung.com>
Tue, 26 Apr 2016 08:52:58 +0000 (17:52 +0900)
committerKyungwook Tak <k.tak@samsung.com>
Tue, 26 Apr 2016 09:10:25 +0000 (18:10 +0900)
class Context
  - To abstract class (IContext)

class CsContext and WpContext
  - To unmovable, uncopyable. To copy shouldn't be done without
    any notice. The only case to be moved was for serialization, so
    it has been replaced to dynamic allocation not to be moved/copied

class Result
  - To abstract class (IResult)
  - To struct (break encapsulation). The reason of be class of it was
    for polymorphism (can get/set member variables with IResult). But
    when it goes into resource vector to be freed after appropriate
    pointer is given to client. So it's not needed to be polymorphistic.

Change-Id: I54fd7479d4008dbcb65a3cae51ecee8a436f19d6
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
35 files changed:
src/framework/CMakeLists.txt
src/framework/client/async-logic.cpp
src/framework/client/async-logic.h
src/framework/client/content-screening.cpp
src/framework/client/handle-ext.cpp
src/framework/client/handle-ext.h
src/framework/client/handle.cpp
src/framework/client/handle.h
src/framework/client/web-protection.cpp
src/framework/common/audit/console-sink.cpp
src/framework/common/audit/console-sink.h
src/framework/common/audit/dlog-sink.cpp
src/framework/common/audit/dlog-sink.h
src/framework/common/audit/log-sink.h
src/framework/common/audit/logger.cpp
src/framework/common/binary-queue.h
src/framework/common/connection.h
src/framework/common/cs-context.cpp
src/framework/common/cs-context.h
src/framework/common/cs-detected.cpp
src/framework/common/cs-detected.h
src/framework/common/icontext.cpp [moved from src/framework/common/types.cpp with 51% similarity]
src/framework/common/icontext.h [new file with mode: 0644]
src/framework/common/iresult.h [moved from src/framework/common/raw-buffer.h with 67% similarity]
src/framework/common/serialization.h
src/framework/common/socket.h
src/framework/common/types.h
src/framework/common/wp-context.cpp
src/framework/common/wp-context.h
src/framework/common/wp-result.cpp
src/framework/common/wp-result.h
src/framework/service/logic.cpp
src/framework/service/logic.h
src/framework/ui/popup/logic.cpp
src/framework/ui/popup/logic.h

index 70266d5..ef7eafc 100644 (file)
@@ -33,7 +33,7 @@ SET(${TARGET_CSR_COMMON}_SRCS
        common/wp-context.cpp
        common/wp-result.cpp
        common/kvp-container.cpp
-       common/types.cpp
+       common/icontext.cpp
        common/dispatcher.cpp
        common/mainloop.cpp
        common/service.cpp
@@ -41,7 +41,8 @@ SET(${TARGET_CSR_COMMON}_SRCS
 )
 
 INCLUDE_DIRECTORIES(
-       common
+       ./
+       ${PROJECT_SOURCE_DIR}/src/include
        ${${TARGET_CSR_COMMON}_DEP_INCLUDE_DIRS}
 )
 
index afb1a0d..20c6d40 100644 (file)
@@ -29,7 +29,7 @@
 namespace Csr {
 namespace Client {
 
-AsyncLogic::AsyncLogic(std::shared_ptr<Context> &context, const Callback &cb,
+AsyncLogic::AsyncLogic(ContextShPtr &context, const Callback &cb,
                                           void *userdata, const std::function<bool()> &isStopped) :
        m_origCtx(context),
        m_ctx(new CsContext),
@@ -178,7 +178,7 @@ std::pair<Callback::Id, Task> AsyncLogic::scanFiles(const
        });
 }
 
-void AsyncLogic::add(Result *r)
+void AsyncLogic::add(IResult *r)
 {
        m_ctx->add(r);
 }
index b3c45bf..8d0a8d7 100644 (file)
@@ -34,7 +34,7 @@ namespace Client {
 
 class AsyncLogic {
 public:
-       AsyncLogic(std::shared_ptr<Context> &context, const Callback &cb,
+       AsyncLogic(ContextShPtr &context, const Callback &cb,
                           void *userdata,
                           const std::function<bool()> &isStopped);
        virtual ~AsyncLogic();
@@ -49,12 +49,12 @@ private:
        template<typename T>
        void copyKvp(CsContext::Key);
 
-       void add(Result *);
+       void add(IResult *);
 
-       std::shared_ptr<Context> &m_origCtx; // for registering results for auto-release
+       ContextShPtr &m_origCtx; // for registering results for auto-release
 
        // TODO: append it to handle context when destroyed
-       std::unique_ptr<Context> m_ctx;
+       ContextPtr m_ctx;
 
        Callback m_cb;
        void *m_userdata;
index da46430..e0d2785 100644 (file)
@@ -26,7 +26,7 @@
 #include "client/utils.h"
 #include "client/handle-ext.h"
 #include "client/async-logic.h"
-#include "common/raw-buffer.h"
+#include "common/types.h"
 #include "common/cs-context.h"
 #include "common/cs-detected.h"
 #include "common/command-id.h"
@@ -113,7 +113,7 @@ int csr_cs_context_create(csr_cs_context_h *phandle)
                return CSR_ERROR_INVALID_PARAMETER;
 
        *phandle = reinterpret_cast<csr_cs_context_h>(
-                                  new Client::HandleExt(std::shared_ptr<Context>(new CsContext())));
+                                  new Client::HandleExt(ContextShPtr(new CsContext())));
 
        return CSR_ERROR_NONE;
 
@@ -228,6 +228,7 @@ int csr_cs_scan_data(csr_cs_context_h handle, const unsigned char *data,
                *pdetected = reinterpret_cast<csr_cs_detected_h>(ret.second);
        } else {
                *pdetected = nullptr;
+               delete ret.second;
        }
 
        return CSR_ERROR_NONE;
@@ -264,6 +265,7 @@ int csr_cs_scan_file(csr_cs_context_h handle, const char *file_path,
                *pdetected = reinterpret_cast<csr_cs_detected_h>(ret.second);
        } else {
                *pdetected = nullptr;
+               delete ret.second;
        }
 
        return CSR_ERROR_NONE;
@@ -477,10 +479,7 @@ int csr_cs_detected_get_severity(csr_cs_detected_h detected,
        if (detected == nullptr || pseverity == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       int intSeverity;
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::Severity), intSeverity);
-       *pseverity = static_cast<csr_cs_severity_level_e>(intSeverity);
+       *pseverity = reinterpret_cast<CsDetected *>(detected)->severity;
 
        return CSR_ERROR_NONE;
 
@@ -496,10 +495,7 @@ int csr_cs_detected_get_threat_type(csr_cs_detected_h detected,
        if (detected == nullptr || pthreat_type == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       int intThreat;
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::Threat), intThreat);
-       *pthreat_type = static_cast<csr_cs_threat_type_e>(intThreat);
+       *pthreat_type = reinterpret_cast<CsDetected *>(detected)->threat;
 
        return CSR_ERROR_NONE;
 
@@ -515,8 +511,7 @@ int csr_cs_detected_get_malware_name(csr_cs_detected_h detected,
        if (detected == nullptr || pmalware_name == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::MalwareName), pmalware_name);
+       *pmalware_name = reinterpret_cast<CsDetected *>(detected)->malwareName.c_str();
 
        return CSR_ERROR_NONE;
 
@@ -532,8 +527,7 @@ int csr_cs_detected_get_detailed_url(csr_cs_detected_h detected,
        if (detected == nullptr || pdetailed_url == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::DetailedUrl), pdetailed_url);
+       *pdetailed_url = reinterpret_cast<CsDetected *>(detected)->detailedUrl.c_str();
 
        return CSR_ERROR_NONE;
 
@@ -549,8 +543,7 @@ int csr_cs_detected_get_timestamp(csr_cs_detected_h detected,
        if (detected == nullptr || ptimestamp == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::TimeStamp), *ptimestamp);
+       *ptimestamp = reinterpret_cast<CsDetected *>(detected)->ts;
 
        return CSR_ERROR_NONE;
 
@@ -566,8 +559,7 @@ int csr_cs_detected_get_file_name(csr_cs_detected_h detected,
        if (detected == nullptr || pfile_name == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::TargetName), pfile_name);
+       *pfile_name = reinterpret_cast<CsDetected *>(detected)->targetName.c_str();
 
        return CSR_ERROR_NONE;
 
@@ -583,10 +575,7 @@ int csr_cs_detected_get_user_response(csr_cs_detected_h detected,
        if (detected == nullptr || presponse == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       int intResponse;
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::UserResponse), intResponse);
-       *presponse = static_cast<csr_cs_user_response_e>(intResponse);
+       *presponse = reinterpret_cast<CsDetected *>(detected)->response;
 
        return CSR_ERROR_NONE;
 
@@ -601,8 +590,7 @@ int csr_cs_detected_is_app(csr_cs_detected_h detected, bool *pis_app)
        if (detected == nullptr || pis_app == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::IsApp), *pis_app);
+       *pis_app = reinterpret_cast<CsDetected *>(detected)->isApp;
 
        return CSR_ERROR_NONE;
 
@@ -617,8 +605,7 @@ int csr_cs_detected_get_pkg_id(csr_cs_detected_h detected, const char **ppkg_id)
        if (detected == nullptr || ppkg_id == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::PkgId), ppkg_id);
+       *ppkg_id = reinterpret_cast<CsDetected *>(detected)->pkgId.c_str();
 
        return CSR_ERROR_NONE;
 
@@ -631,17 +618,14 @@ int csr_cs_judge_detected_malware(csr_cs_context_h handle,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || detected == nullptr ||  !_isValid(action))
+       if (handle == nullptr || detected == nullptr || !_isValid(action))
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
-       const char *file_path = nullptr;
-       reinterpret_cast<Result *>(detected)->get(
-               static_cast<int>(CsDetected::Key::TargetName), &file_path);
        auto ret = hExt->dispatch<int>(
                                   CommandId::JUDGE_STATUS,
                                   hExt->getContext(),
-                                  std::string(file_path),
+                                  reinterpret_cast<CsDetected *>(detected)->targetName,
                                   static_cast<int>(action));
 
        if (ret != CSR_ERROR_NONE) {
@@ -660,7 +644,7 @@ int csr_cs_get_detected_malware(csr_cs_context_h handle, const char *file_path,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || file_path == nullptr ||  pdetected == nullptr)
+       if (handle == nullptr || file_path == nullptr || pdetected == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -698,7 +682,7 @@ int csr_cs_get_detected_malwares(csr_cs_context_h handle,
        EXCEPTION_SAFE_START
 
        if (handle == nullptr || dir_paths == nullptr || count == 0
-                       ||  plist == nullptr || pcount == nullptr)
+                       || plist == nullptr || pcount == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -734,7 +718,7 @@ int csr_cs_get_detected_malwares(csr_cs_context_h handle,
        ResultListPtr resultListPtr(new ResultList);
 
        while (auto dptr = cptrList.pop())
-               resultListPtr->emplace_back(std::unique_ptr<Result>(dptr));
+               resultListPtr->emplace_back(dptr);
 
        *plist = reinterpret_cast<csr_cs_detected_list_h>(resultListPtr.get());
        *pcount = resultListPtr->size();
@@ -752,7 +736,7 @@ int csr_cs_get_ignored_malware(csr_cs_context_h handle, const char *file_path,
 {
        EXCEPTION_SAFE_START
 
-       if (handle == nullptr || file_path == nullptr ||  pdetected == nullptr)
+       if (handle == nullptr || file_path == nullptr || pdetected == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -790,7 +774,7 @@ int csr_cs_get_ignored_malwares(csr_cs_context_h handle,
        EXCEPTION_SAFE_START
 
        if (handle == nullptr || dir_paths == nullptr || count == 0
-                       ||  plist == nullptr || pcount == nullptr)
+                       || plist == nullptr || pcount == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
        auto hExt = reinterpret_cast<Client::HandleExt *>(handle);
@@ -826,7 +810,7 @@ int csr_cs_get_ignored_malwares(csr_cs_context_h handle,
        ResultListPtr resultListPtr(new ResultList);
 
        while (auto dptr = cptrList.pop())
-               resultListPtr->emplace_back(std::unique_ptr<Result>(dptr));
+               resultListPtr->emplace_back(dptr);
 
        *plist = reinterpret_cast<csr_cs_detected_list_h>(resultListPtr.get());
        *pcount = resultListPtr->size();
index 83cc706..f06305f 100644 (file)
@@ -30,7 +30,7 @@
 namespace Csr {
 namespace Client {
 
-HandleExt::HandleExt(std::shared_ptr<Context> &&context) :
+HandleExt::HandleExt(ContextShPtr &&context) :
        Handle(std::move(context)),
        m_stop(false)
 {
index 73b8b43..387e6fc 100644 (file)
  */
 #pragma once
 
-#include "client/handle.h"
-#include "client/callback.h"
-#include "common/types.h"
-
 #include <mutex>
 #include <thread>
 #include <atomic>
+
 #include <string>
 #include <map>
+#include <set>
 #include <utility>
 
-#include <set>
-#include <string>
+#include "client/handle.h"
+#include "client/callback.h"
+#include "common/icontext.h"
 
 namespace Csr {
 namespace Client {
 
 class HandleExt : public Handle {
 public:
-       explicit HandleExt(std::shared_ptr<Context> &&);
+       explicit HandleExt(ContextShPtr &&);
        virtual ~HandleExt();
 
        void dispatchAsync(const Task &task);
index 779a898..ee4a5e1 100644 (file)
@@ -27,7 +27,7 @@
 namespace Csr {
 namespace Client {
 
-Handle::Handle(std::shared_ptr<Context> &&context) :
+Handle::Handle(ContextShPtr &&context) :
        m_ctx(std::move(context))
 {
        if (!m_ctx)
@@ -38,12 +38,12 @@ Handle::~Handle()
 {
 }
 
-std::shared_ptr<Context> &Handle::getContext() noexcept
+ContextShPtr &Handle::getContext() noexcept
 {
        return m_ctx;
 }
 
-void Handle::add(Result *result)
+void Handle::add(IResult *result)
 {
        if (result == nullptr)
                throw std::logic_error("result shouldn't be null");
index 56906ff..88eecf8 100644 (file)
@@ -24,7 +24,7 @@
 #include <utility>
 #include <memory>
 
-#include "common/types.h"
+#include "common/icontext.h"
 #include "common/dispatcher.h"
 
 namespace Csr {
@@ -32,20 +32,20 @@ namespace Client {
 
 class Handle {
 public:
-       explicit Handle(std::shared_ptr<Context> &&);
+       explicit Handle(ContextShPtr &&);
        virtual ~Handle();
 
        template<typename Type, typename ...Args>
        Type dispatch(Args &&...);
 
-       void add(Result *);
+       void add(IResult *);
        void add(ResultListPtr &&);
 
-       std::shared_ptr<Context> &getContext(void) noexcept;
+       ContextShPtr &getContext(void) noexcept;
 
 private:
        std::unique_ptr<Dispatcher> m_dispatcher;
-       std::shared_ptr<Context> m_ctx;
+       ContextShPtr m_ctx;
 };
 
 template<typename Type, typename ...Args>
index 9011793..0dd8049 100644 (file)
@@ -135,10 +135,7 @@ int csr_wp_result_get_risk_level(csr_wp_check_result_h result,
        if (result == nullptr || plevel == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       int intRiskLevel;
-       reinterpret_cast<Result *>(result)->get(
-               static_cast<int>(WpResult::Key::RiskLevel), intRiskLevel);
-       *plevel = static_cast<csr_wp_risk_level_e>(intRiskLevel);
+       *plevel = reinterpret_cast<WpResult *>(result)->riskLevel;
 
        return CSR_ERROR_NONE;
 
@@ -154,8 +151,7 @@ int csr_wp_result_get_detailed_url(csr_wp_check_result_h result,
        if (result == nullptr || pdetailed_url == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       reinterpret_cast<Result *>(result)->get(
-               static_cast<int>(WpResult::Key::DetailedUrl), pdetailed_url);
+       *pdetailed_url = reinterpret_cast<WpResult *>(result)->detailedUrl.c_str();
 
        return CSR_ERROR_NONE;
 
@@ -172,10 +168,7 @@ int csr_wp_result_get_user_response(csr_wp_check_result_h result,
        if (result == nullptr || presponse == nullptr)
                return CSR_ERROR_INVALID_PARAMETER;
 
-       int intResponse;
-       reinterpret_cast<Result *>(result)->get(
-               static_cast<int>(WpResult::Key::UserResponse), intResponse);
-       *presponse = static_cast<csr_wp_user_response_e>(intResponse);
+       *presponse = reinterpret_cast<WpResult *>(result)->response;
 
        return CSR_ERROR_NONE;
 
index 2d195d5..3ea2e13 100644 (file)
@@ -19,7 +19,7 @@
  * @version     1.0
  * @brief
  */
-#include "console-sink.h"
+#include "common/audit/console-sink.h"
 
 #include <iostream>
 
index 308c7ac..023015c 100644 (file)
@@ -23,8 +23,8 @@
 
 #include <string>
 
-#include "audit/log-sink.h"
-#include "audit/logger.h"
+#include "common/audit/log-sink.h"
+#include "common/audit/logger.h"
 
 namespace Csr {
 namespace Audit {
index 36f0400..ece0e2e 100644 (file)
@@ -19,7 +19,7 @@
  * @version     1.0
  * @brief
  */
-#include "dlog-sink.h"
+#include "common/audit/dlog-sink.h"
 
 #include <iostream>
 #include <dlog.h>
index 33cd98c..de53a43 100644 (file)
@@ -23,8 +23,8 @@
 
 #include <string>
 
-#include "audit/log-sink.h"
-#include "audit/logger.h"
+#include "common/audit/log-sink.h"
+#include "common/audit/logger.h"
 
 namespace Csr {
 namespace Audit {
index cc6f082..43335c6 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <string>
 
-#include "audit/logger.h"
+#include "common/audit/logger.h"
 
 namespace Csr {
 namespace Audit {
index ff77721..60e6ade 100644 (file)
  * @version     1.0
  * @brief
  */
-#include "logger.h"
+#include "common/audit/logger.h"
 
 #include <sys/types.h>
 #include <unistd.h>
 
 #include <stdexcept>
 
-#include "log-sink.h"
-#include "console-sink.h"
-#include "dlog-sink.h"
+#include "common/audit/log-sink.h"
+#include "common/audit/console-sink.h"
+#include "common/audit/dlog-sink.h"
 
 namespace Csr {
 namespace Audit {
index 5e544c7..320835e 100644 (file)
@@ -27,7 +27,7 @@
 #include <cstddef>
 
 #include "common/serialization.h"
-#include "common/raw-buffer.h"
+#include "common/types.h"
 
 namespace Csr {
 
index 877c4e1..ef85038 100644 (file)
@@ -25,7 +25,7 @@
 #include <mutex>
 
 #include "common/socket.h"
-#include "common/raw-buffer.h"
+#include "common/types.h"
 
 namespace Csr {
 
index cfe4252..64c57af 100644 (file)
 namespace Csr {
 
 CsContext::CsContext() :
-       m_popupMessage(),
-       m_askUser(CSR_CS_NOT_ASK_USER),
-       m_coreUsage(CSR_CS_USE_CORE_DEFAULT),
-       m_isScanOnCloud(false)
+       IContext(),
+       popupMessage(),
+       askUser(CSR_CS_NOT_ASK_USER),
+       coreUsage(CSR_CS_USE_CORE_DEFAULT),
+       isScanOnCloud(false)
 {
 }
 
@@ -44,73 +45,28 @@ CsContext::CsContext(IStream &stream)
        int intAskUser;
        int intCoreUsage;
        Deserializer<std::string, int, int, bool>::Deserialize(stream,
-                       m_popupMessage, intAskUser, intCoreUsage, m_isScanOnCloud);
+                       popupMessage, intAskUser, intCoreUsage, isScanOnCloud);
 
-       m_askUser = static_cast<csr_cs_ask_user_e>(intAskUser);
-       m_coreUsage = static_cast<csr_cs_core_usage_e>(intCoreUsage);
+       askUser = static_cast<csr_cs_ask_user_e>(intAskUser);
+       coreUsage = static_cast<csr_cs_core_usage_e>(intCoreUsage);
 }
 
 void CsContext::Serialize(IStream &stream) const
 {
        Serializer<std::string, int, int, bool>::Serialize(stream,
-                       m_popupMessage, static_cast<int>(m_askUser), static_cast<int>(m_coreUsage),
-                       m_isScanOnCloud);
-}
-
-CsContext::CsContext(CsContext &&other) :
-       Context(std::move(other)),
-       m_popupMessage(std::move(other.m_popupMessage)),
-       m_askUser(other.m_askUser),
-       m_coreUsage(other.m_coreUsage),
-       m_isScanOnCloud(other.m_isScanOnCloud)
-{
-}
-
-CsContext &CsContext::operator=(CsContext &&other)
-{
-       if (this == &other)
-               return *this;
-
-       Context::operator=(std::move(other));
-
-       m_popupMessage = std::move(other.m_popupMessage);
-       m_askUser = other.m_askUser;
-       m_coreUsage = other.m_coreUsage;
-       m_isScanOnCloud = other.m_isScanOnCloud;
-
-       return *this;
-}
-
-CsContext::CsContext(const CsContext &other) :
-       Context(other),
-       m_popupMessage(other.m_popupMessage),
-       m_askUser(other.m_askUser),
-       m_coreUsage(other.m_coreUsage),
-       m_isScanOnCloud(other.m_isScanOnCloud)
-{
-}
-
-CsContext &CsContext::operator=(const CsContext &other)
-{
-       Context::operator=(other);
-
-       m_popupMessage = other.m_popupMessage;
-       m_askUser = other.m_askUser;
-       m_coreUsage = other.m_coreUsage;
-       m_isScanOnCloud = other.m_isScanOnCloud;
-
-       return *this;
+                       popupMessage, static_cast<int>(askUser), static_cast<int>(coreUsage),
+                       isScanOnCloud);
 }
 
 void CsContext::set(int key, int value)
 {
        switch (static_cast<Key>(key)) {
        case Key::AskUser:
-               m_askUser = static_cast<csr_cs_ask_user_e>(value);
+               askUser = static_cast<csr_cs_ask_user_e>(value);
                break;
 
        case Key::CoreUsage:
-               m_coreUsage = static_cast<csr_cs_core_usage_e>(value);
+               coreUsage = static_cast<csr_cs_core_usage_e>(value);
                break;
 
        default:
@@ -123,7 +79,7 @@ void CsContext::set(int key, const std::string &value)
 {
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               m_popupMessage = value;
+               popupMessage = value;
                break;
 
        default:
@@ -136,7 +92,7 @@ void CsContext::set(int key, const char *value)
 {
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               m_popupMessage = value;
+               popupMessage = value;
                break;
 
        default:
@@ -149,7 +105,7 @@ void CsContext::set(int key, bool value)
 {
        switch (static_cast<Key>(key)) {
        case Key::ScanOnCloud:
-               m_isScanOnCloud = value;
+               isScanOnCloud = value;
                break;
 
        default:
@@ -162,11 +118,11 @@ void CsContext::get(int key, int &value) const
 {
        switch (static_cast<Key>(key)) {
        case Key::AskUser:
-               value = static_cast<int>(m_askUser);
+               value = static_cast<int>(askUser);
                break;
 
        case Key::CoreUsage:
-               value = static_cast<int>(m_coreUsage);
+               value = static_cast<int>(coreUsage);
                break;
 
        default:
@@ -179,7 +135,7 @@ void CsContext::get(int key, std::string &value) const
 {
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               value = m_popupMessage;
+               value = popupMessage;
                break;
 
        default:
@@ -195,7 +151,7 @@ void CsContext::get(int key, const char **value) const
 
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               *value = m_popupMessage.c_str();
+               *value = popupMessage.c_str();
                break;
 
        default:
@@ -208,7 +164,7 @@ void CsContext::get(int key, bool &value) const
 {
        switch (static_cast<Key>(key)) {
        case Key::ScanOnCloud:
-               value = m_isScanOnCloud;
+               value = isScanOnCloud;
                break;
 
        default:
index 9712a96..13428db 100644 (file)
 #pragma once
 
 #include <string>
+#include <memory>
 
-#include "common/types.h"
+#include "common/icontext.h"
 #include "csr/content-screening-types.h"
 
 namespace Csr {
 
-class CsContext : public Context {
-public:
+struct CsContext;
+using CsContextPtr = std::unique_ptr<CsContext>;
+using CsContextShPtr = std::shared_ptr<CsContext>;
+
+struct CsContext : public IContext {
        enum class Key : int {
                PopupMessage = 0x01, // string
 
@@ -45,11 +49,10 @@ public:
        CsContext(IStream &);
        virtual void Serialize(IStream &) const override;
 
-       CsContext(CsContext &&);
-       CsContext &operator=(CsContext &&);
-
-       CsContext(const CsContext &);
-       CsContext &operator=(const CsContext &);
+       CsContext(CsContext &&) = delete;
+       CsContext &operator=(CsContext &&) = delete;
+       CsContext(const CsContext &) = delete;
+       CsContext &operator=(const CsContext &) = delete;
 
        virtual void set(int, int) override;
        virtual void set(int, const std::string &) override;
@@ -61,11 +64,10 @@ public:
        virtual void get(int, const char **) const override;
        virtual void get(int, bool &) const override;
 
-private:
-       std::string m_popupMessage;
-       csr_cs_ask_user_e m_askUser;
-       csr_cs_core_usage_e m_coreUsage;
-       bool m_isScanOnCloud;
+       std::string popupMessage;
+       csr_cs_ask_user_e askUser;
+       csr_cs_core_usage_e coreUsage;
+       bool isScanOnCloud;
 };
 
 }
index ed09eab..5c11108 100644 (file)
 namespace Csr {
 
 CsDetected::CsDetected() :
-       m_targetName(),
-       m_malwareName(),
-       m_detailedUrl(),
-       m_severity(CSR_CS_SEVERITY_LOW),
-       m_threat(CSR_CS_THREAT_GENERIC),
-       m_response(CSR_CS_NO_ASK_USER),
-       m_isApp(false),
-       m_ts(0)
+       targetName(),
+       malwareName(),
+       detailedUrl(),
+       severity(CSR_CS_SEVERITY_LOW),
+       threat(CSR_CS_THREAT_GENERIC),
+       response(CSR_CS_NO_ASK_USER),
+       isApp(false),
+       ts(0)
 {
 }
 
@@ -43,45 +43,36 @@ CsDetected::~CsDetected()
 {
 }
 
-CsDetected::CsDetected(IStream &stream) : Result(stream)
+CsDetected::CsDetected(IStream &stream)
 {
-       if (!hasValue())
-               return;
-
        int intSeverity;
        int intThreat;
        int intResponse;
        Deserializer<std::string, std::string, std::string, int, int, int, time_t>::Deserialize(
-               stream, m_targetName, m_malwareName, m_detailedUrl, intSeverity, intThreat,
-               intResponse, m_ts);
+               stream, targetName, malwareName, detailedUrl, intSeverity, intThreat,
+               intResponse, ts);
 
-       m_severity = static_cast<csr_cs_severity_level_e>(intSeverity);
-       m_threat = static_cast<csr_cs_threat_type_e>(intThreat);
-       m_response = static_cast<csr_cs_user_response_e>(intResponse);
+       severity = static_cast<csr_cs_severity_level_e>(intSeverity);
+       threat = static_cast<csr_cs_threat_type_e>(intThreat);
+       response = static_cast<csr_cs_user_response_e>(intResponse);
 }
 
 void CsDetected::Serialize(IStream &stream) const
 {
-       Result::Serialize(stream);
-
-       if (!hasValue())
-               return;
-
        Serializer<std::string, std::string, std::string, int, int, int, time_t>::Serialize(
-               stream, m_targetName, m_malwareName, m_detailedUrl,
-               static_cast<int>(m_severity), static_cast<int>(m_threat),
-               static_cast<int>(m_response), m_ts);
+               stream, targetName, malwareName, detailedUrl,
+               static_cast<int>(severity), static_cast<int>(threat),
+               static_cast<int>(response), ts);
 }
 
 CsDetected::CsDetected(CsDetected &&other) :
-       Result(std::move(other)),
-       m_targetName(std::move(other.m_targetName)),
-       m_malwareName(std::move(other.m_malwareName)),
-       m_detailedUrl(std::move(other.m_detailedUrl)),
-       m_severity(other.m_severity),
-       m_threat(other.m_threat),
-       m_response(other.m_response),
-       m_ts(other.m_ts)
+       targetName(std::move(other.targetName)),
+       malwareName(std::move(other.malwareName)),
+       detailedUrl(std::move(other.detailedUrl)),
+       severity(other.severity),
+       threat(other.threat),
+       response(other.response),
+       ts(other.ts)
 {
 }
 
@@ -90,195 +81,20 @@ CsDetected &CsDetected::operator=(CsDetected &&other)
        if (this == &other)
                return *this;
 
-       Result::operator=(std::move(other));
-
-       m_targetName = std::move(other.m_targetName);
-       m_malwareName = std::move(other.m_malwareName);
-       m_detailedUrl = std::move(other.m_detailedUrl);
-       m_severity = other.m_severity;
-       m_threat = other.m_threat;
-       m_response = other.m_response;
-       m_ts = other.m_ts;
+       targetName = std::move(other.targetName);
+       malwareName = std::move(other.malwareName);
+       detailedUrl = std::move(other.detailedUrl);
+       severity = other.severity;
+       threat = other.threat;
+       response = other.response;
+       ts = other.ts;
 
        return *this;
 }
 
-void CsDetected::set(int key, int value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::Severity:
-               m_severity = static_cast<csr_cs_severity_level_e>(value);
-               break;
-
-       case Key::Threat:
-               m_threat = static_cast<csr_cs_threat_type_e>(value);
-               break;
-
-       case Key::UserResponse:
-               m_response = static_cast<csr_cs_user_response_e>(value);
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as int."));
-       }
-
-       setValueFlag();
-}
-
-void CsDetected::set(int key, bool value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::IsApp:
-               m_isApp = value;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as bool."));
-       }
-
-       setValueFlag();
-}
-
-void CsDetected::set(int key, const std::string &value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::TargetName:
-               m_targetName = value;
-               break;
-
-       case Key::MalwareName:
-               m_malwareName = value;
-               break;
-
-       case Key::DetailedUrl:
-               m_detailedUrl = value;
-               break;
-
-       case Key::PkgId:
-               m_pkgId = value;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as string."));
-       }
-
-       setValueFlag();
-}
-
-void CsDetected::set(int key, const char *value)
+bool CsDetected::hasValue(void) const noexcept
 {
-       switch (static_cast<Key>(key)) {
-       case Key::TargetName:
-               m_targetName = value;
-               break;
-
-       case Key::MalwareName:
-               m_malwareName = value;
-               break;
-
-       case Key::DetailedUrl:
-               m_detailedUrl = value;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as string."));
-       }
-
-       setValueFlag();
-}
-
-void CsDetected::set(int key, time_t value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::TimeStamp:
-               m_ts = value;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as time_t."));
-       }
-
-       setValueFlag();
-}
-
-void CsDetected::get(int key, int &value) const
-{
-       switch (static_cast<Key>(key)) {
-       case Key::Severity:
-               value = static_cast<int>(m_severity);
-               break;
-
-       case Key::Threat:
-               value = static_cast<int>(m_threat);
-               break;
-
-       case Key::UserResponse:
-               value = static_cast<int>(m_response);
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to get as int."));
-       }
-}
-
-void CsDetected::get(int key, bool &value) const
-{
-       switch (static_cast<Key>(key)) {
-       case Key::IsApp:
-               value = m_isApp;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to get as bool."));
-       }
-}
-
-void CsDetected::get(int key, const char **value) const
-{
-       if (value == nullptr)
-               throw std::logic_error("invalud argument. output storage pointer is null.");
-
-       switch (static_cast<Key>(key)) {
-       case Key::TargetName:
-               *value = m_targetName.c_str();
-               break;
-
-       case Key::MalwareName:
-               *value = m_malwareName.c_str();
-               break;
-
-       case Key::DetailedUrl:
-               *value = m_detailedUrl.c_str();
-               break;
-
-       case Key::PkgId:
-               *value = m_pkgId.c_str();
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to get as string."));
-       }
-}
-
-void CsDetected::get(int key, time_t &value) const
-{
-       switch (static_cast<Key>(key)) {
-       case Key::TimeStamp:
-               value = m_ts;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to get as time_t."));
-       }
+       return !targetName.empty();
 }
 
 }
index a99ab72..e9460a5 100644 (file)
@@ -22,8 +22,9 @@
 #pragma once
 
 #include <string>
+#include <ctime>
 
-#include "common/types.h"
+#include "common/iresult.h"
 #include "csr/content-screening-types.h"
 
 namespace Csr {
@@ -32,24 +33,7 @@ class CsDetected;
 using CsDetectedPtr = std::unique_ptr<CsDetected>;
 using CsDetectedList = std::vector<CsDetectedPtr>;
 
-class CsDetected : public Result {
-public:
-       // key for set/get
-       enum class Key : int {
-               TargetName   = 0x01, // string
-               MalwareName  = 0x02, // string
-               DetailedUrl  = 0x03, // string
-               PkgId        = 0x04, // string
-
-               Severity     = 0x10, // int
-               Threat       = 0x11, // int
-               UserResponse = 0x12, // int
-
-               TimeStamp    = 0x20, // time_t
-
-               IsApp        = 0x30  // bool
-       };
-
+struct CsDetected : public IResult {
        CsDetected();
        virtual ~CsDetected();
 
@@ -59,28 +43,18 @@ public:
        CsDetected(CsDetected &&);
        CsDetected &operator=(CsDetected &&);
 
-       virtual void set(int, int) override;
-       virtual void set(int, bool) override;
-       virtual void set(int, const std::string &) override;
-       virtual void set(int, const char *) override;
-       virtual void set(int, time_t) override;
-
-       virtual void get(int, int &) const override;
-       virtual void get(int, bool &) const override;
-       virtual void get(int, const char **) const override;
-       virtual void get(int, time_t &) const override;
+       bool hasValue(void) const noexcept;
 
-private:
-       std::string m_targetName; // file path or app id which contains malware
+       std::string targetName; // file path or app id which contains malware
 
-       std::string m_malwareName;
-       std::string m_detailedUrl;
-       std::string m_pkgId;
-       csr_cs_severity_level_e m_severity;
-       csr_cs_threat_type_e m_threat;
-       csr_cs_user_response_e m_response;
-       bool m_isApp;
-       time_t m_ts;
+       std::string malwareName;
+       std::string detailedUrl;
+       std::string pkgId;
+       csr_cs_severity_level_e severity;
+       csr_cs_threat_type_e threat;
+       csr_cs_user_response_e response;
+       bool isApp;
+       time_t ts;
 };
 
 }
similarity index 51%
rename from src/framework/common/types.cpp
rename to src/framework/common/icontext.cpp
index 41ae644..ac31011 100644 (file)
  *  limitations under the License
  */
 /*
- * @file        types.cpp
+ * @file        icontext.cpp
  * @author      Kyungwook Tak (k.tak@samsung.com)
  * @version     1.0
- * @brief       CSR internal serializable types
+ * @brief       Abstract class of context for both of cs / wp
  */
-#include "common/types.h"
+#include "common/icontext.h"
 
 #include <stdexcept>
 #include <utility>
 
 namespace Csr {
 
-Context::Context()
+IContext::IContext()
 {
 }
 
-Context::~Context()
+IContext::~IContext()
 {
 }
 
-// don't copy results.. context copy operation only should be used for option copy
-Context::Context(const Context &) :
-       ISerializable(),
-       m_results()
-{
-}
-
-Context &Context::operator=(const Context &)
-{
-       return *this;
-}
-
-Context::Context(Context &&other) :
-       m_results(std::move(other.m_results))
-{
-}
-
-Context &Context::operator=(Context &&other)
-{
-       if (this == &other)
-               return *this;
-
-       m_results = std::move(other.m_results);
-
-       return *this;
-}
-
-void Context::add(ResultPtr &&item)
+void IContext::add(ResultPtr &&item)
 {
        std::lock_guard<std::mutex> l(m_mutex);
        m_results.emplace_back(std::forward<ResultPtr>(item));
 }
 
-void Context::add(Result *item)
+void IContext::add(IResult *item)
 {
        std::lock_guard<std::mutex> l(m_mutex);
        m_results.emplace_back(item);
 }
 
-void Context::add(ResultListPtr &&item)
+void IContext::add(ResultListPtr &&item)
 {
        std::lock_guard<std::mutex> l(m_mutex);
        m_resultLists.emplace_back(std::forward<ResultListPtr>(item));
 }
 
-size_t Context::size() const
+size_t IContext::size() const
 {
        std::lock_guard<std::mutex> l(m_mutex);
        return m_results.size();
 }
 
-Result::Result() : m_hasVal(false)
-{
-}
-
-Result::~Result()
-{
-}
-
-Result::Result(IStream &stream)
-{
-       Deserializer<bool>::Deserialize(stream, m_hasVal);
-}
-
-void Result::Serialize(IStream &stream) const
-{
-       Serializer<bool>::Serialize(stream, m_hasVal);
-}
-
-Result::Result(Result &&)
-{
-}
-
-Result &Result::operator=(Result &&)
-{
-       return *this;
-}
-
-bool Result::hasValue() const
-{
-       return m_hasVal;
-}
-
 } // namespace Csr
diff --git a/src/framework/common/icontext.h b/src/framework/common/icontext.h
new file mode 100644 (file)
index 0000000..a291860
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *  Copyright (c) 2016 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        icontext.h
+ * @author      Kyungwook Tak (k.tak@samsung.com)
+ * @version     1.0
+ * @brief       Abstract class of context for both of cs / wp
+ */
+#pragma once
+
+#include <vector>
+#include <memory>
+#include <mutex>
+
+#include "common/dispatcher.h"
+#include "common/serialization.h"
+#include "common/kvp-container.h"
+#include "common/iresult.h"
+
+namespace Csr {
+
+class IContext;
+using ContextPtr = std::unique_ptr<IContext>;
+using ContextShPtr = std::shared_ptr<IContext>;
+
+class IContext : public ISerializable, public KvpContainer {
+public:
+       IContext();
+       virtual ~IContext();
+
+       IContext(IContext &&) = delete;
+       IContext &operator=(IContext &&) = delete;
+       IContext(const IContext &) = delete;
+       IContext &operator=(const IContext &) = delete;
+
+       void add(ResultPtr &&);
+       void add(IResult *);
+       void add(ResultListPtr &&);
+       size_t size(void) const;
+       // for destroying with context
+       std::vector<ResultPtr> m_results;
+       std::vector<ResultListPtr> m_resultLists;
+
+private:
+       mutable std::mutex m_mutex;
+};
+
+} // namespace Csr
similarity index 67%
rename from src/framework/common/raw-buffer.h
rename to src/framework/common/iresult.h
index 8700300..0dd4a64 100644 (file)
  *  limitations under the License
  */
 /*
- * @file        raw-buffer.h
+ * @file        iresult.h
  * @author      Kyungwook Tak (k.tak@samsung.com)
  * @version     1.0
- * @brief
+ * @brief       Abstract class for handle all result resources by a single interface
  */
 #pragma once
 
-#include <vector>
+#include "common/serialization.h"
 
 namespace Csr {
 
-using RawBuffer = std::vector<unsigned char>;
+class IResult;
+using ResultPtr = std::unique_ptr<IResult>;
+using ResultList = std::vector<ResultPtr>;
+using ResultListPtr = std::unique_ptr<ResultList>;
+
+class IResult : public ISerializable {
+public:
+       virtual ~IResult() {}
+};
 
 }
index 153b98c..14856cb 100644 (file)
@@ -323,6 +323,12 @@ struct Deserialization {
                object = new T(stream);
        }
 
+       template <typename T>
+       static void Deserialize(IStream &stream, std::shared_ptr<T> &object)
+       {
+               object.reset(new T(stream));
+       }
+
        // char
        static void Deserialize(IStream &stream, char &value)
        {
index 65c431c..971ed94 100644 (file)
@@ -23,7 +23,7 @@
 
 #include <string>
 
-#include "common/raw-buffer.h"
+#include "common/types.h"
 
 namespace Csr {
 
index bced3a9..0aeceaf 100644 (file)
  * @file        types.h
  * @author      Kyungwook Tak (k.tak@samsung.com)
  * @version     1.0
- * @brief       CSR internal serializable types
+ * @brief       Typedefs of primitives
  */
 #pragma once
 
 #include <vector>
-#include <memory>
-#include <mutex>
-
-#include "common/dispatcher.h"
-#include "common/serialization.h"
-#include "common/kvp-container.h"
+#include <functional>
+#include <set>
+#include <string>
 
 namespace Csr {
 
 using Task = std::function<void()>;
 using StrSet = std::set<std::string>;
-
-class Result : public ISerializable, public KvpContainer {
-public:
-       Result();
-       virtual ~Result();
-
-       Result(Result &&);
-       Result &operator=(Result &&);
-
-       bool hasValue(void) const;
-
-protected:
-       Result(IStream &);
-       virtual void Serialize(IStream &) const override;
-
-       inline void setValueFlag(void)
-       {
-               m_hasVal = true;
-       }
-
-private:
-       bool m_hasVal;
-};
-
-using ResultPtr = std::unique_ptr<Result>;
-using ResultList = std::vector<ResultPtr>;
-using ResultListPtr = std::unique_ptr<ResultList>;
-
-class Context : public ISerializable, public KvpContainer {
-public:
-       Context();
-       virtual ~Context();
-
-       Context(Context &&);
-       Context &operator=(Context &&);
-
-       // TODO: Handling results vector between contexts should be refined..
-       //       copy ctor/assignments for serializing and results vector isn't included here.
-       Context(const Context &);
-       Context &operator=(const Context &);
-
-       void add(ResultPtr &&);
-       void add(Result *);
-       void add(ResultListPtr &&);
-       size_t size(void) const;
-       // for destroying with context
-       std::vector<ResultPtr> m_results;
-       std::vector<ResultListPtr> m_resultLists;
-
-private:
-       mutable std::mutex m_mutex;
-};
+using RawBuffer = std::vector<unsigned char>;
 
 } // namespace Csr
index c7f48da..d759248 100644 (file)
@@ -28,8 +28,8 @@
 namespace Csr {
 
 WpContext::WpContext() :
-       m_popupMessage(),
-       m_askUser(CSR_WP_NOT_ASK_USER)
+       popupMessage(),
+       askUser(CSR_WP_NOT_ASK_USER)
 {
 }
 
@@ -41,59 +41,22 @@ WpContext::WpContext(IStream &stream)
 {
        int intAskUser;
        Deserializer<std::string, int>::Deserialize(stream,
-                       m_popupMessage, intAskUser);
+                       popupMessage, intAskUser);
 
-       m_askUser = static_cast<csr_wp_ask_user_e>(intAskUser);
+       askUser = static_cast<csr_wp_ask_user_e>(intAskUser);
 }
 
 void WpContext::Serialize(IStream &stream) const
 {
-       Serializer<std::string, int>::Serialize(stream, m_popupMessage,
-                                                                                       static_cast<int>(m_askUser));
-}
-
-WpContext::WpContext(WpContext &&other) :
-       Context(std::move(other)),
-       m_popupMessage(std::move(other.m_popupMessage)),
-       m_askUser(other.m_askUser)
-{
-}
-
-WpContext &WpContext::operator=(WpContext &&other)
-{
-       if (this == &other)
-               return *this;
-
-       Context::operator=(std::move(other));
-
-       m_popupMessage = std::move(other.m_popupMessage);
-       m_askUser = other.m_askUser;
-
-       return *this;
-}
-
-WpContext::WpContext(const WpContext &other) :
-       Context(other),
-       m_popupMessage(other.m_popupMessage),
-       m_askUser(other.m_askUser)
-{
-}
-
-WpContext &WpContext::operator=(const WpContext &other)
-{
-       Context::operator=(other);
-
-       m_popupMessage = other.m_popupMessage;
-       m_askUser = other.m_askUser;
-
-       return *this;
+       Serializer<std::string, int>::Serialize(stream, popupMessage,
+                                                                                       static_cast<int>(askUser));
 }
 
 void WpContext::set(int key, int value)
 {
        switch (static_cast<Key>(key)) {
        case Key::AskUser:
-               m_askUser = static_cast<csr_wp_ask_user_e>(value);
+               askUser = static_cast<csr_wp_ask_user_e>(value);
                break;
 
        default:
@@ -106,7 +69,7 @@ void WpContext::set(int key, const std::string &value)
 {
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               m_popupMessage = value;
+               popupMessage = value;
                break;
 
        default:
@@ -119,7 +82,7 @@ void WpContext::set(int key, const char *value)
 {
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               m_popupMessage = value;
+               popupMessage = value;
                break;
 
        default:
@@ -132,7 +95,7 @@ void WpContext::get(int key, int &value) const
 {
        switch (static_cast<Key>(key)) {
        case Key::AskUser:
-               value = static_cast<int>(m_askUser);
+               value = static_cast<int>(askUser);
                break;
 
        default:
@@ -145,7 +108,7 @@ void WpContext::get(int key, std::string &value) const
 {
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               value = m_popupMessage;
+               value = popupMessage;
                break;
 
        default:
@@ -161,7 +124,7 @@ void WpContext::get(int key, const char **value) const
 
        switch (static_cast<Key>(key)) {
        case Key::PopupMessage:
-               *value = m_popupMessage.c_str();
+               *value = popupMessage.c_str();
                break;
 
        default:
index 532846a..930142c 100644 (file)
 #pragma once
 
 #include <string>
+#include <memory>
 
-#include "common/types.h"
+#include "common/icontext.h"
 #include "csr/web-protection-types.h"
 
 namespace Csr {
 
-class WpContext : public Context {
-public:
+struct WpContext;
+using WpContextPtr = std::unique_ptr<WpContext>;
+using WpContextShPtr = std::shared_ptr<WpContext>;
+
+struct WpContext : public IContext {
        enum class Key : int {
                PopupMessage = 0x01, // string
                AskUser      = 0x10, // int
@@ -41,11 +45,10 @@ public:
        WpContext(IStream &);
        virtual void Serialize(IStream &) const override;
 
-       WpContext(WpContext &&);
-       WpContext &operator=(WpContext &&);
-
-       WpContext(const WpContext &);
-       WpContext &operator=(const WpContext &);
+       WpContext(WpContext &&) = delete;
+       WpContext &operator=(WpContext &&) = delete;
+       WpContext(const WpContext &) = delete;
+       WpContext &operator=(const WpContext &) = delete;
 
        virtual void set(int, int) override;
        virtual void set(int, const std::string &) override;
@@ -55,9 +58,8 @@ public:
        virtual void get(int, std::string &) const override;
        virtual void get(int, const char **) const override;
 
-private:
-       std::string m_popupMessage;
-       csr_wp_ask_user_e m_askUser;
+       std::string popupMessage;
+       csr_wp_ask_user_e askUser;
 };
 
 } // end of namespace Csr
index a0fb091..fd2bcbc 100644 (file)
@@ -28,9 +28,9 @@
 namespace Csr {
 
 WpResult::WpResult() :
-       m_riskLevel(CSR_WP_RISK_LOW),
-       m_detailedUrl(),
-       m_response(CSR_WP_NO_ASK_USER)
+       riskLevel(CSR_WP_RISK_LOW),
+       detailedUrl(),
+       response(CSR_WP_NO_ASK_USER)
 {
 }
 
@@ -38,36 +38,27 @@ WpResult::~WpResult()
 {
 }
 
-WpResult::WpResult(IStream &stream) : Result(stream)
+WpResult::WpResult(IStream &stream)
 {
-       if (!hasValue())
-               return;
-
        int intRiskLevel;
        int intResponse;
        Deserializer<int, std::string, int>::Deserialize(stream,
-                       intRiskLevel, m_detailedUrl, intResponse);
+                       intRiskLevel, detailedUrl, intResponse);
 
-       m_riskLevel = static_cast<csr_wp_risk_level_e>(intRiskLevel);
-       m_response = static_cast<csr_wp_user_response_e>(intResponse);
+       riskLevel = static_cast<csr_wp_risk_level_e>(intRiskLevel);
+       response = static_cast<csr_wp_user_response_e>(intResponse);
 }
 
 void WpResult::Serialize(IStream &stream) const
 {
-       Result::Serialize(stream);
-
-       if (!hasValue())
-               return;
-
        Serializer<int, std::string, int>::Serialize(stream,
-                       static_cast<int>(m_riskLevel), m_detailedUrl, static_cast<int>(m_response));
+                       static_cast<int>(riskLevel), detailedUrl, static_cast<int>(response));
 }
 
 WpResult::WpResult(WpResult &&other) :
-       Result(std::move(other)),
-       m_riskLevel(other.m_riskLevel),
-       m_detailedUrl(std::move(other.m_detailedUrl)),
-       m_response(other.m_response)
+       riskLevel(other.riskLevel),
+       detailedUrl(std::move(other.detailedUrl)),
+       response(other.response)
 {
 }
 
@@ -76,95 +67,11 @@ WpResult &WpResult::operator=(WpResult &&other)
        if (this == &other)
                return *this;
 
-       Result::operator=(std::move(other));
-
-       m_detailedUrl = std::move(other.m_detailedUrl);
-       m_riskLevel = other.m_riskLevel;
-       m_response = other.m_response;
+       detailedUrl = std::move(other.detailedUrl);
+       riskLevel = other.riskLevel;
+       response = other.response;
 
        return *this;
 }
 
-void WpResult::set(int key, int value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::RiskLevel:
-               m_riskLevel = static_cast<csr_wp_risk_level_e>(value);
-               break;
-
-       case Key::UserResponse:
-               m_response = static_cast<csr_wp_user_response_e>(value);
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as int. value=" << value));
-       }
-
-       setValueFlag();
-}
-
-void WpResult::set(int key, const std::string &value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::DetailedUrl:
-               m_detailedUrl = value;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as std::string. value=" << value));
-       }
-
-       setValueFlag();
-}
-
-void WpResult::set(int key, const char *value)
-{
-       switch (static_cast<Key>(key)) {
-       case Key::DetailedUrl:
-               m_detailedUrl = value;
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as char*. value=" << value));
-       }
-
-       setValueFlag();
-}
-
-void WpResult::get(int key, int &value) const
-{
-       switch (static_cast<Key>(key)) {
-       case Key::RiskLevel:
-               value = static_cast<int>(m_riskLevel);
-               break;
-
-       case Key::UserResponse:
-               value = static_cast<int>(m_response);
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as int. value=" << value));
-       }
-}
-
-void WpResult::get(int key, const char **value) const
-{
-       if (value == nullptr)
-               throw std::logic_error("invalid argument. output storage pointer is null.");
-
-       switch (static_cast<Key>(key)) {
-       case Key::DetailedUrl:
-               *value = m_detailedUrl.c_str();
-               break;
-
-       default:
-               throw std::logic_error(FORMAT("Invalid key[" << key <<
-                                                                         "] comes in to set as char**. value=" << value));
-       }
-}
-
 }
index 07fdf63..f1944ff 100644 (file)
 
 #include <string>
 
-#include "common/types.h"
+#include "common/iresult.h"
 #include "csr/web-protection-types.h"
 
 namespace Csr {
 
-class WpResult : public Result {
-public:
-       // key for set/get
-       enum class Key : int {
-               DetailedUrl  = 0x01, // string
-
-               RiskLevel    = 0x10, // int
-               UserResponse = 0x11  // int
-       };
-
+struct WpResult : public IResult {
        WpResult();
        virtual ~WpResult();
 
@@ -47,17 +38,9 @@ public:
        WpResult(WpResult &&);
        WpResult &operator=(WpResult &&);
 
-       virtual void set(int, int) override;
-       virtual void set(int, const std::string &) override;
-       virtual void set(int, const char *) override;
-
-       virtual void get(int, int &) const override;
-       virtual void get(int, const char **) const override;
-
-private:
-       csr_wp_risk_level_e m_riskLevel;
-       std::string m_detailedUrl;
-       csr_wp_user_response_e m_response;
+       csr_wp_risk_level_e riskLevel;
+       std::string detailedUrl;
+       csr_wp_user_response_e response;
 };
 
 }
index a8f2ff4..0eddb7b 100644 (file)
@@ -99,75 +99,76 @@ RawBuffer Logic::dispatch(const RawBuffer &in)
        switch (info.first) {
        // Content scanning
        case CommandId::SCAN_DATA: {
-               CsContext context;
+               CsContextShPtr cptr;
                RawBuffer data;
-               info.second.Deserialize(context, data);
-               return scanData(context, data);
+               info.second.Deserialize(cptr, data);
+
+               return scanData(*cptr, data);
        }
 
        case CommandId::SCAN_FILE: {
-               CsContext context;
+               CsContextShPtr cptr;
                std::string filepath;
-               info.second.Deserialize(context, filepath);
-               return scanFile(context, filepath);
+               info.second.Deserialize(cptr, filepath);
+               return scanFile(*cptr, filepath);
        }
 
        case CommandId::DIR_GET_RESULTS: {
-               CsContext context;
+               CsContextShPtr cptr;
                std::string dir;
-               info.second.Deserialize(context, dir);
-               return dirGetResults(context, dir);
+               info.second.Deserialize(cptr, dir);
+               return dirGetResults(*cptr, dir);
        }
 
        case CommandId::DIR_GET_FILES: {
-               CsContext context;
+               CsContextShPtr cptr;
                std::string dir;
-               info.second.Deserialize(context, dir);
-               return dirGetFiles(context, dir);
+               info.second.Deserialize(cptr, dir);
+               return dirGetFiles(*cptr, dir);
        }
 
        case CommandId::JUDGE_STATUS: {
-               CsContext context;
+               CsContextShPtr cptr;
                std::string filepath;
-               info.second.Deserialize(context, filepath);
-               return judgeStatus(context, filepath);
+               info.second.Deserialize(cptr, filepath);
+               return judgeStatus(*cptr, filepath);
        }
 
        case CommandId::GET_DETECTED: {
-               CsContext context;
+               CsContextShPtr cptr;
                std::string filepath;
-               info.second.Deserialize(context, filepath);
-               return getDetected(context, filepath);
+               info.second.Deserialize(cptr, filepath);
+               return getDetected(*cptr, filepath);
        }
 
        case CommandId::GET_DETECTED_LIST: {
-               CsContext context;
+               CsContextShPtr cptr;
                StrSet dirSet;
-               info.second.Deserialize(context, dirSet);
-               return getDetectedList(context, dirSet);
+               info.second.Deserialize(cptr, dirSet);
+               return getDetectedList(*cptr, dirSet);
        }
 
        case CommandId::GET_IGNORED: {
-               CsContext context;
+               CsContextShPtr cptr;
                std::string filepath;
-               info.second.Deserialize(context, filepath);
-               return getIgnored(context, filepath);
+               info.second.Deserialize(cptr, filepath);
+               return getIgnored(*cptr, filepath);
        }
 
        case CommandId::GET_IGNORED_LIST: {
-               CsContext context;
+               CsContextShPtr cptr;
                StrSet dirSet;
-               info.second.Deserialize(context, dirSet);
-               return getIgnoredList(context, dirSet);
+               info.second.Deserialize(cptr, dirSet);
+               return getIgnoredList(*cptr, dirSet);
        }
 
        // Web protection
        /* TODO: should we separate command->logic mapping of CS and WP ? */
        case CommandId::CHECK_URL: {
-               WpContext context;
+               WpContextShPtr cptr;
                std::string url;
-               info.second.Deserialize(context, url);
-               return checkUrl(context, url);
+               info.second.Deserialize(cptr, url);
+               return checkUrl(*cptr, url);
        }
 
        default:
@@ -241,7 +242,7 @@ RawBuffer Logic::getDetected(const CsContext &context,
        printCsContext(context);
 
        CsDetected detected;
-       detected.set(static_cast<int>(CsDetected::Key::TargetName), "test_file");
+       detected.targetName = "test_file";
 
        return BinaryQueue::Serialize(CSR_ERROR_NONE, detected).pop();
 }
@@ -256,7 +257,7 @@ RawBuffer Logic::getDetectedList(const CsContext &context, const StrSet &dirSet)
        printCsContext(context);
 
        CsDetectedPtr detected(new CsDetected());
-       detected->set(static_cast<int>(CsDetected::Key::TargetName), "test_file");
+       detected->targetName = "test_file";
 
        CsDetectedList list;
        list.emplace_back(std::move(detected));
@@ -272,7 +273,7 @@ RawBuffer Logic::getIgnored(const CsContext &context,
        printCsContext(context);
 
        CsDetected detected;
-       detected.set(static_cast<int>(CsDetected::Key::TargetName), "test_file");
+       detected.targetName = "test_file";
 
        return BinaryQueue::Serialize(CSR_ERROR_NONE, detected).pop();
 }
@@ -287,7 +288,7 @@ RawBuffer Logic::getIgnoredList(const CsContext &context, const StrSet &dirSet)
        printCsContext(context);
 
        CsDetectedPtr detected(new CsDetected());
-       detected->set(static_cast<int>(CsDetected::Key::TargetName), "test_file");
+       detected->targetName = "test_file";
 
        CsDetectedList list;
        list.emplace_back(std::move(detected));
@@ -312,12 +313,10 @@ RawBuffer Logic::checkUrl(const WpContext &context, const std::string &url)
        }
 
        auto wr = convert(result);
-       int level;
-       wr.get(static_cast<int>(WpResult::Key::RiskLevel), level);
 
        DEBUG("checking level.. prepare for asking user");
 
-       switch (static_cast<csr_wp_risk_level_e>(level)) {
+       switch (wr.riskLevel) {
        case CSR_WP_RISK_UNVERIFIED:
                DEBUG("url[" << url << "] risk level is unverified");
                return BinaryQueue::Serialize(ret, wr).pop();
@@ -337,7 +336,8 @@ RawBuffer Logic::checkUrl(const WpContext &context, const std::string &url)
                break;
 
        default:
-               throw std::logic_error(FORMAT("Invalid level: " << level));
+               throw std::logic_error(FORMAT("Invalid level: " <<
+                                                                         static_cast<int>(wr.riskLevel)));
        }
 
        return BinaryQueue::Serialize(ret, wr).pop();
@@ -346,14 +346,10 @@ RawBuffer Logic::checkUrl(const WpContext &context, const std::string &url)
 void Logic::getUserResponse(const WpContext &c, const std::string &url,
                                                        csr_wp_risk_level_e level, WpResult &wr)
 {
-       int isAsk;
-       c.get(static_cast<int>(WpContext::Key::AskUser), isAsk);
-
-       if (static_cast<csr_wp_ask_user_e>(isAsk) == CSR_WP_NOT_ASK_USER)
+       if (c.askUser == CSR_WP_NOT_ASK_USER)
                return;
 
-       std::string popupMessage;
-       c.get(static_cast<int>(WpContext::Key::PopupMessage), popupMessage);
+       auto &popupMessage = c.popupMessage;
 
        Ui::AskUser askUser;
        Ui::WpResponse response = Ui::WpResponse::CONFIRM;
@@ -365,11 +361,9 @@ void Logic::getUserResponse(const WpContext &c, const std::string &url,
                response = askUser.wpAskPermission(popupMessage, item);
 
                if (response == Ui::WpResponse::ALLOW)
-                       wr.set(static_cast<int>(WpResult::Key::UserResponse),
-                                  CSR_WP_PROCESSING_ALLOWED);
+                       wr.response = CSR_WP_PROCESSING_ALLOWED;
                else if (response == Ui::WpResponse::DENY)
-                       wr.set(static_cast<int>(WpResult::Key::UserResponse),
-                                  CSR_WP_PROCESSING_DISALLOWED);
+                       wr.response = CSR_WP_PROCESSING_DISALLOWED;
                else
                        throw std::runtime_error("Invalid response from popup service.");
        } else {
@@ -377,8 +371,7 @@ void Logic::getUserResponse(const WpContext &c, const std::string &url,
                response = askUser.wpNotify(popupMessage, item);
 
                if (response == Ui::WpResponse::CONFIRM)
-                       wr.set(static_cast<int>(WpResult::Key::UserResponse),
-                                  CSR_WP_PROCESSING_DISALLOWED);
+                       wr.response = CSR_WP_PROCESSING_DISALLOWED;
                else
                        throw std::runtime_error("Invalid response from popup service.");
        }
@@ -429,8 +422,8 @@ WpResult Logic::convert(csre_wp_check_result_h &r)
 
        WpResult wr;
 
-       wr.set(static_cast<int>(WpResult::Key::DetailedUrl), detailedUrl);
-       wr.set(static_cast<int>(WpResult::Key::RiskLevel), static_cast<int>(level));
+       wr.detailedUrl = detailedUrl;
+       wr.riskLevel = level;
 
        return wr;
 }
index 3aa4973..9f580c5 100644 (file)
@@ -29,7 +29,6 @@
 #include "common/wp-context.h"
 #include "common/wp-result.h"
 #include "common/command-id.h"
-#include "common/raw-buffer.h"
 #include "common/binary-queue.h"
 #include "service/cs-loader.h"
 #include "service/wp-loader.h"
index bb5a218..b76ca59 100644 (file)
@@ -27,7 +27,6 @@
 #include <Elementary.h>
 
 #include "common/binary-queue.h"
-#include "common/raw-buffer.h"
 #include "common/audit/logger.h"
 #include "ui/common.h"
 
index 8a24401..9d8fcc0 100644 (file)
@@ -25,7 +25,7 @@
 #include <functional>
 #include <utility>
 
-#include "common/raw-buffer.h"
+#include "common/types.h"
 #include "common/binary-queue.h"
 #include "ui/common.h"
 #include "popup.h"