From dd59df9cad474f561cc6833aa5a729931bed8b92 Mon Sep 17 00:00:00 2001 From: Kyungwook Tak Date: Thu, 2 Jun 2016 19:40:18 +0900 Subject: [PATCH] Engine activation status check in loaders Change-Id: Ie33f5218584eb9ee992147dce7c79339ea5dbe29 Signed-off-by: Kyungwook Tak --- src/framework/service/cs-loader.cpp | 37 ++++++++++++++++++++++++++++++------- src/framework/service/cs-loader.h | 2 ++ src/framework/service/wp-loader.cpp | 30 +++++++++++++++++++++++++----- src/framework/service/wp-loader.h | 2 ++ 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/src/framework/service/cs-loader.cpp b/src/framework/service/cs-loader.cpp index ee5e77c..cdda3bf 100644 --- a/src/framework/service/cs-loader.cpp +++ b/src/framework/service/cs-loader.cpp @@ -31,8 +31,7 @@ namespace Csr { namespace { -int getValueCstr(std::string &value, - const std::function &getfunc) +int getValueCstr(std::string &value, const std::function &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 &value) +int CsLoader::getEngineVendorLogo(csre_cs_context_h c, std::vector &value) { if (c == nullptr) throw std::invalid_argument("cs loader get engine vendor logo"); diff --git a/src/framework/service/cs-loader.h b/src/framework/service/cs-loader.h index 829acce..a237c90 100644 --- a/src/framework/service/cs-loader.h +++ b/src/framework/service/cs-loader.h @@ -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; }; diff --git a/src/framework/service/wp-loader.cpp b/src/framework/service/wp-loader.cpp index 573491d..e4a826c 100644 --- a/src/framework/service/wp-loader.cpp +++ b/src/framework/service/wp-loader.cpp @@ -31,8 +31,7 @@ namespace Csr { namespace { -int getValueCstr(std::string &value, - const std::function &getfunc) +int getValueCstr(std::string &value, const std::function &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 &value) +int WpLoader::getEngineVendorLogo(csre_wp_context_h c, std::vector &value) { if (c == nullptr) throw std::invalid_argument("wp loader get engine vendor logo"); diff --git a/src/framework/service/wp-loader.h b/src/framework/service/wp-loader.h index 94ef88f..b32a7c4 100644 --- a/src/framework/service/wp-loader.h +++ b/src/framework/service/wp-loader.h @@ -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; }; -- 2.7.4