Engine activation status check in loaders 78/72778/3
authorKyungwook Tak <k.tak@samsung.com>
Thu, 2 Jun 2016 10:40:18 +0000 (19:40 +0900)
committerkyungwook tak <k.tak@samsung.com>
Fri, 3 Jun 2016 01:36:09 +0000 (18:36 -0700)
Change-Id: Ie33f5218584eb9ee992147dce7c79339ea5dbe29
Signed-off-by: Kyungwook Tak <k.tak@samsung.com>
src/framework/service/cs-loader.cpp
src/framework/service/cs-loader.h
src/framework/service/wp-loader.cpp
src/framework/service/wp-loader.h

index ee5e77c..cdda3bf 100644 (file)
@@ -31,8 +31,7 @@ namespace Csr {
 
 namespace {
 
-int getValueCstr(std::string &value,
-                                const std::function<int(const char **)> &getfunc)
+int getValueCstr(std::string &value, const std::function<int(const char **)> &getfunc)
 {
        const char *cvalue = nullptr;
        auto retval = getfunc(&cvalue);
@@ -45,6 +44,19 @@ int getValueCstr(std::string &value,
 
 } // namespace anonymous
 
+void CsLoader::checkEngineActivated(csre_cs_context_h c)
+{
+       csre_cs_activated_e a = CSRE_CS_NOT_ACTIVATED;
+
+       int ret = this->getEngineActivated(c, &a);
+
+       if (ret != CSRE_ERROR_NONE)
+               toException(ret);
+
+       if (a == CSRE_CS_NOT_ACTIVATED)
+               ThrowExc(EngineNotActivated, "engine is not activated yet");
+}
+
 int CsLoader::contextCreate(csre_cs_context_h &c)
 {
        return this->m_pc.fpContextCreate(&c);
@@ -65,6 +77,8 @@ int CsLoader::scanData(csre_cs_context_h c,
        if (c == nullptr || data.empty() || pdetected == nullptr)
                throw std::invalid_argument("cs loader scan data");
 
+       this->checkEngineActivated(c);
+
        return this->m_pc.fpScanData(c, data.data(), data.size(), pdetected);
 }
 
@@ -74,6 +88,8 @@ int CsLoader::scanFile(csre_cs_context_h c, const std::string &filepath,
        if (c == nullptr || filepath.empty() || pdetected == nullptr)
                throw std::invalid_argument("cs loader scan file");
 
+       this->checkEngineActivated(c);
+
        return this->m_pc.fpScanFile(c, filepath.c_str(), pdetected);
 }
 
@@ -83,6 +99,8 @@ int CsLoader::scanAppOnCloud(csre_cs_context_h c, const std::string &appdir,
        if (c == nullptr || appdir.empty() || pdetected == nullptr)
                throw std::invalid_argument("cs loader scan app on cloud");
 
+       this->checkEngineActivated(c);
+
        return this->m_pc.fpScanAppOnCloud(c, appdir.c_str(), pdetected);
 }
 
@@ -180,17 +198,22 @@ int CsLoader::getEngineLatestUpdateTime(csre_cs_context_h c, time_t *ptime)
        return this->m_pc.fpGetEngineLatestUpdateTime(c, ptime);
 }
 
-int CsLoader::getEngineActivated(csre_cs_context_h c,
-                                                                csre_cs_activated_e *pactivated)
+int CsLoader::getEngineActivated(csre_cs_context_h c, csre_cs_activated_e *pactivated)
 {
        if (c == nullptr || pactivated == nullptr)
                throw std::invalid_argument("cs loader get engine activated");
 
-       return this->m_pc.fpGetEngineActivated(c, pactivated);
+       auto ret = this->m_pc.fpGetEngineActivated(c, pactivated);
+
+       if (ret == CSRE_ERROR_ENGINE_NOT_ACTIVATED) {
+               *pactivated = CSRE_CS_NOT_ACTIVATED;
+               return CSRE_ERROR_NONE;
+       } else {
+               return ret;
+       }
 }
 
-int CsLoader::getEngineVendorLogo(csre_cs_context_h c,
-                                                                 std::vector<unsigned char> &value)
+int CsLoader::getEngineVendorLogo(csre_cs_context_h c, std::vector<unsigned char> &value)
 {
        if (c == nullptr)
                throw std::invalid_argument("cs loader get engine vendor logo");
index 829acce..a237c90 100644 (file)
@@ -112,6 +112,8 @@ private:
        virtual void init(const std::string &, const std::string &, const std::string &) override;
        virtual void deinit(void) override;
 
+       void checkEngineActivated(csre_cs_context_h);
+
        PluginContext m_pc;
 };
 
index 573491d..e4a826c 100644 (file)
@@ -31,8 +31,7 @@ namespace Csr {
 
 namespace {
 
-int getValueCstr(std::string &value,
-                                const std::function<int(const char **)> &getfunc)
+int getValueCstr(std::string &value, const std::function<int(const char **)> &getfunc)
 {
        const char *cvalue = nullptr;
        auto retval = getfunc(&cvalue);
@@ -45,6 +44,19 @@ int getValueCstr(std::string &value,
 
 } // namespace anonymous
 
+void WpLoader::checkEngineActivated(csre_wp_context_h c)
+{
+       csre_wp_activated_e a = CSRE_WP_NOT_ACTIVATED;
+
+       int ret = this->getEngineActivated(c, &a);
+
+       if (ret != CSRE_ERROR_NONE)
+               toException(ret);
+
+       if (a == CSRE_WP_NOT_ACTIVATED)
+               ThrowExc(EngineNotActivated, "engine is not activated yet");
+}
+
 int WpLoader::contextCreate(csre_wp_context_h &c)
 {
        return this->m_pc.fpContextCreate(&c);
@@ -64,6 +76,8 @@ int WpLoader::checkUrl(csre_wp_context_h c, const std::string &url,
        if (c == nullptr || url.empty() || presult == nullptr)
                throw std::invalid_argument("wp loader check url error");
 
+       this->checkEngineActivated(c);
+
        return this->m_pc.fpCheckUrl(c, (const char *)url.c_str(), presult);
 }
 
@@ -158,11 +172,17 @@ int WpLoader::getEngineActivated(csre_wp_context_h c,
        if (c == nullptr || pactivated == nullptr)
                throw std::invalid_argument("wp loader get engine activated");
 
-       return this->m_pc.fpGetEngineActivated(c, pactivated);
+       auto ret = this->m_pc.fpGetEngineActivated(c, pactivated);
+
+       if (ret == CSRE_ERROR_ENGINE_NOT_ACTIVATED) {
+               *pactivated = CSRE_WP_NOT_ACTIVATED;
+               return CSRE_ERROR_NONE;
+       } else {
+               return ret;
+       }
 }
 
-int WpLoader::getEngineVendorLogo(csre_wp_context_h c,
-                                                                 std::vector<unsigned char> &value)
+int WpLoader::getEngineVendorLogo(csre_wp_context_h c, std::vector<unsigned char> &value)
 {
        if (c == nullptr)
                throw std::invalid_argument("wp loader get engine vendor logo");
index 94ef88f..b32a7c4 100644 (file)
@@ -99,6 +99,8 @@ private:
        virtual void init(const std::string &, const std::string &, const std::string &) override;
        virtual void deinit(void) override;
 
+       void checkEngineActivated(csre_wp_context_h);
+
        PluginContext m_pc;
 };