Add parameters for offline mode 51/272451/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 17 Mar 2022 03:34:54 +0000 (12:34 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Thu, 17 Mar 2022 03:34:54 +0000 (12:34 +0900)
Callback registration for language change is unnecessary
if code operates as offline mode.

Change-Id: I89067c8305a81c8ffc3b0bf67f7bb10789051767
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/client/pkginfo_client.cc
src/common/system_locale.cc
src/common/system_locale.hh

index 4d179f9..43ad8ff 100644 (file)
@@ -151,7 +151,7 @@ bool PkgInfoClient::RequestHandlerDirectAccess() {
   result_parcel_.reset(
       reinterpret_cast<pkgmgr_common::parcel::AbstractParcelable *>(
           dl_func(req_type_, &raw[0], raw.size(),
-              pkgmgr_common::SystemLocale::GetInst().Get().c_str())));
+              pkgmgr_common::SystemLocale::GetInst(false).Get().c_str())));
 
   return true;
 }
index 06c4442..449a716 100644 (file)
@@ -12,14 +12,16 @@ constexpr const char DEFAULT_LOCALE[] = "No Locale";
 
 namespace pkgmgr_common {
 
-SystemLocale& SystemLocale::GetInst() {
-  static SystemLocale inst;
+SystemLocale& SystemLocale::GetInst(bool is_online) {
+  static SystemLocale inst(is_online);
 
   return inst;
 }
 
-SystemLocale::SystemLocale() {
-  vconf_notify_key_changed(VCONFKEY_LANGSET, LanChangedCb, this);
+SystemLocale::SystemLocale(bool is_online) : is_online_(is_online) {
+  if (is_online_)
+    vconf_notify_key_changed(VCONFKEY_LANGSET, LanChangedCb, this);
+
   char* lang = vconf_get_str(VCONFKEY_LANGSET);
   lang_ = lang ? std::string(lang) : "";
   free(lang);
@@ -27,7 +29,8 @@ SystemLocale::SystemLocale() {
 }
 
 SystemLocale::~SystemLocale() {
-  vconf_ignore_key_changed(VCONFKEY_LANGSET, LanChangedCb);
+  if (is_online_)
+    vconf_ignore_key_changed(VCONFKEY_LANGSET, LanChangedCb);
 }
 
 void SystemLocale::RegisterEvent(IEvent* listener) {
index 76a02b8..d7416b9 100644 (file)
@@ -23,7 +23,7 @@ class EXPORT_API SystemLocale {
     virtual void OnChanged(const std::string& locale) = 0;
   };
 
-  static SystemLocale& GetInst();
+  static SystemLocale& GetInst(bool is_online = true);
   const std::string& Get() const;
   void RegisterEvent(IEvent* listener);
   void UnRegisterEvent();
@@ -31,9 +31,10 @@ class EXPORT_API SystemLocale {
  private:
   std::string lang_;
   std::string locale_;
+  bool is_online_;
   IEvent* listener_ = nullptr;
 
-  SystemLocale();
+  SystemLocale(bool is_online);
   ~SystemLocale();
   void SetLocale();
   static void LanChangedCb(keynode_t* node, void* user_data);