--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#include "theme/dbus/command.h"
+
+namespace ttm {
+namespace dbus {
+
+const char kCmdDataKey[] = "__DATA__";
+const char kCmdResultKey[] = "__RESULT__";
+
+} // namespace dbus
+} // namespace ttm
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * 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 THEME_DBUS_COMMAND_H_
+#define THEME_DBUS_COMMAND_H_
+
+namespace ttm {
+namespace dbus {
+
+enum class Command : int {
+ GET_IDS,
+ SET_ID,
+ GET,
+ RESULT,
+ ADD,
+ UPDATE,
+ REMOVE,
+ CHANGED,
+ REMOVED
+};
+
+extern const char kCmdDataKey[];
+extern const char kCmdResultKey[];
+
+} // namespace dbus
+} // namespace ttm
+
+#endif // THEME_DBUS_COMMAND_H_
static tizen_base::Bundle ErrorResultBundle() {
tizen_base::Bundle b;
- b.Add(CMD_RESULT_KEY, "error");
+ b.Add(dbus::kCmdResultKey, "error");
return b;
}
#include <bundle_cpp.h>
+#include "theme/dbus/command.h"
+
namespace ttm {
namespace dbus {
-#define CMD_GET_IDS_KEY "__GET_IDS__"
-#define CMD_SET_ID_KEY "__SET_ID__"
-#define CMD_GET_KEY "__GET__"
-#define CMD_RESULT_KEY "__RESULT__"
-#define CMD_ADD_KEY "__ADD__"
-#define CMD_UPDATE_KEY "__UPDATE__"
-#define CMD_REMOVE_KEY "__REMOVE__"
-#define CMD_CHANGED_KEY "__CHANGED__"
-#define CMD_REMOVED_KEY "__REMOVED__"
-
-enum class Command : int {
- GET_IDS,
- SET_ID,
- GET,
- RESULT,
- ADD,
- UPDATE,
- REMOVE,
- CHANGED,
- REMOVED
-};
-
class IRequestHandler {
public:
virtual ~IRequestHandler() = default;
#include "theme/loader/theme_info.h"
#include "theme/loader/theme_info_loader.h"
+#include "theme/dbus/command.h"
#include "theme/dbus/request_broker.h"
#include "theme/utils/logging.h"
const tizen_base::Bundle& args) {
switch (cmd) {
case dbus::Command::CHANGED: {
- tizen_base::Bundle b(args.GetString(CMD_CHANGED_KEY));
+ tizen_base::Bundle b(args.GetString(dbus::kCmdDataKey));
const ThemeInfo* info = new ThemeInfo(b);
for (auto& listener : listeners_) {
std::shared_ptr<IThemeEvent> ev = listener.second;
break;
}
case dbus::Command::REMOVED: {
- std::string id = args.GetString(CMD_REMOVE_KEY);
+ std::string id = args.GetString(dbus::kCmdDataKey);
for (auto& listener : listeners_) {
std::shared_ptr<IThemeEvent> ev = listener.second;
ev->OnThemeUnloaded(id);
tizen_base::Bundle b;
tizen_base::Bundle reply =
dbus::RequestBroker::GetInst().SendData(dbus::Command::GET_IDS, b);
- if (reply.GetString(CMD_RESULT_KEY) == "error")
+ if (reply.GetString(dbus::kCmdResultKey) == "error")
return {};
- return reply.GetStringArray(CMD_GET_IDS_KEY);
+ return reply.GetStringArray(dbus::kCmdDataKey);
}
void ThemeInfoLoader::SetCurrent(const std::string& id) {
tizen_base::Bundle b;
- b.Add(CMD_SET_ID_KEY, id);
+ b.Add(dbus::kCmdDataKey, id);
tizen_base::Bundle reply =
dbus::RequestBroker::GetInst().SendData(dbus::Command::SET_ID, b);
return cache_;
tizen_base::Bundle b;
- b.Add(CMD_GET_KEY, "");
+ b.Add(dbus::kCmdDataKey, "");
tizen_base::Bundle reply =
dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
- std::string str = reply.GetString(CMD_GET_KEY);
+ std::string str = reply.GetString(dbus::kCmdDataKey);
tizen_base::Bundle serialized(str);
cache_ = std::make_shared<ThemeInfo>(serialized);
return cache_;
tizen_base::Bundle b;
- b.Add(CMD_GET_KEY, id);
+ b.Add(dbus::kCmdDataKey, id);
tizen_base::Bundle reply =
dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
- tizen_base::Bundle serialized(
- reply.GetString(CMD_GET_KEY));
+ tizen_base::Bundle serialized(reply.GetString(dbus::kCmdDataKey));
- std::shared_ptr<ThemeInfo> info = std::make_shared<ThemeInfo>(serialized);
+ std::shared_ptr<ThemeInfo> info =
+ std::make_shared<ThemeInfo>(serialized);
return info;
}
}
// FIXME: this parser should parse more theme information.
- ThemeInfoBuilder builder("testid");
+ ThemeInfoBuilder builder(id);
builder.PutString("pkgid", pkgid).
PutString("uid", std::to_string(uid)).
PutString("version", root["version"].asString()).
default:
return false;
}
+ if (reply.GetString(dbus::kCmdResultKey) != "ok")
+ return false;
return true;
}
#include <bundle_cpp.h>
+#include "theme/dbus/command.h"
#include "theme_provider/theme_info_proxy.h"
namespace ttm {
tizen_base::Bundle b;
if (cmd != dbus::Command::SET_ID) {
// this temporary return value should be fixed.
- b.Add(CMD_RESULT_KEY, "error");
+ b.Add(dbus::kCmdResultKey, "error");
return b;
}
- bool r = proxy_->SetCurrentTheme(args.GetString(CMD_SET_ID_KEY));
- b.Add(CMD_RESULT_KEY, r ? "ok" : "error");
+ bool r = proxy_->SetCurrentTheme(args.GetString(dbus::kCmdDataKey));
+ b.Add(dbus::kCmdResultKey, r ? "ok" : "error");
return b;
}
#include <bundle_cpp.h>
+#include "theme/dbus/command.h"
#include "theme/loader/theme_info.h"
#include "theme/utils/logging.h"
#include "theme_provider/theme_info_proxy.h"
tizen_base::Bundle PackageEventRequestHandler::OnRequest(dbus::Command cmd,
const tizen_base::Bundle& args) {
+ tizen_base::Bundle b;
bool result = false;
+ if (args.IsEmpty()) {
+ b.Add(dbus::kCmdResultKey, "error");
+ return b;
+ }
+
+ loader::ThemeInfo theme(args);
switch (cmd) {
case dbus::Command::ADD: {
- tizen_base::Bundle b(args.GetString(CMD_ADD_KEY));
- result = InstallTheme(b);
+ result = InstallTheme(theme);
break;
}
case dbus::Command::REMOVE: {
- result = UninstallTheme(args.GetString(CMD_REMOVE_KEY));
+ result = UninstallTheme(theme);
break;
}
case dbus::Command::UPDATE: {
- tizen_base::Bundle b(args.GetString(CMD_UPDATE_KEY));
- result = UpdateTheme(b);
+ result = UpdateTheme(theme);
break;
}
default: {
}
}
- tizen_base::Bundle b;
// this temporary return value should be fixed.
- b.Add(CMD_RESULT_KEY, result ? "ok" : "error");
+ b.Add(dbus::kCmdResultKey, result ? "ok" : "error");
return b;
}
-bool PackageEventRequestHandler::InstallTheme(const tizen_base::Bundle& args) {
- return proxy_->SaveTheme(loader::ThemeInfo(args));
+bool PackageEventRequestHandler::InstallTheme(const loader::ThemeInfo& theme) {
+ return proxy_->SaveTheme(theme);
}
-bool PackageEventRequestHandler::UpdateTheme(const tizen_base::Bundle& args) {
- return proxy_->UpdateTheme(loader::ThemeInfo(args));
+bool PackageEventRequestHandler::UpdateTheme(const loader::ThemeInfo& theme) {
+ return proxy_->UpdateTheme(theme);
}
bool PackageEventRequestHandler::UninstallTheme(
- const std::string& id) {
- return proxy_->RemoveTheme(id);
+ const loader::ThemeInfo& theme) {
+ return proxy_->RemoveTheme(theme.GetId());
}
} // namespace provider
#include <memory>
#include <string>
+#include "theme/dbus/command.h"
#include "theme/dbus/request_handler.h"
+#include "theme/loader/theme_info.h"
namespace ttm {
namespace provider {
const tizen_base::Bundle& args);
private:
- bool InstallTheme(const tizen_base::Bundle& args);
- bool UpdateTheme(const tizen_base::Bundle& args);
- bool UninstallTheme(const std::string& id);
+ bool InstallTheme(const loader::ThemeInfo& theme);
+ bool UpdateTheme(const loader::ThemeInfo& theme);
+ bool UninstallTheme(const loader::ThemeInfo& theme);
std::shared_ptr<ThemeInfoProxy> proxy_;
};
#include <string>
+#include "theme/dbus/command.h"
#include "theme/loader/theme_info.h"
#include "theme_provider/theme_info_proxy.h"
tizen_base::Bundle b;
switch (cmd) {
case dbus::Command::GET: {
- std::string id = args.GetString(CMD_GET_KEY);
+ std::string id = args.GetString(dbus::kCmdDataKey);
std::shared_ptr<loader::ThemeInfo> themeinfo = proxy_->LoadTheme(id);
if (themeinfo == nullptr) {
- b.Add(CMD_RESULT_KEY, "error");
+ b.Add(dbus::kCmdResultKey, "error");
return b;
}
- b.Add(CMD_RESULT_KEY, "ok");
- b.Add(CMD_GET_KEY,
+ b.Add(dbus::kCmdResultKey, "ok");
+ b.Add(dbus::kCmdDataKey,
reinterpret_cast<char*>(themeinfo->Serialize().ToRaw().first.get()));
return b;
}
case dbus::Command::GET_IDS: {
std::vector<std::string> ids = proxy_->GetThemeIds();
- b.Add(CMD_RESULT_KEY, "ok");
- b.Add(CMD_GET_IDS_KEY, ids);
+ b.Add(dbus::kCmdResultKey, "ok");
+ b.Add(dbus::kCmdDataKey, ids);
return b;
}
default: {
// this temporary return value should be fixed.
- b.Add(CMD_RESULT_KEY, "error");
+ b.Add(dbus::kCmdResultKey, "error");
return b;
}
}
#include <cstdio>
+#include "theme/dbus/command.h"
#include "theme/dbus/request_broker.h"
#include "theme/dbus/request_handler.h"
#include "theme/loader/theme_info.h"
g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(nullptr));
tizen_base::Bundle b;
b = broker_.SendData(ttm::dbus::Command::ADD, b);
- std::string result = b.GetString(CMD_RESULT_KEY);
+ std::string result = b.GetString(ttm::dbus::kCmdResultKey);
EXPECT_EQ(result, "error");
}
WillOnce(DoAll(SetArgPointee<6>(error), Return(nullptr)));
tizen_base::Bundle b;
b = broker_.SendData(ttm::dbus::Command::ADD, b);
- std::string result = b.GetString(CMD_RESULT_KEY);
+ std::string result = b.GetString(ttm::dbus::kCmdResultKey);
EXPECT_EQ(result, "error");
}
g_dbus_message_get_body(_)).WillOnce(Return(nullptr));
tizen_base::Bundle b;
b = broker_.SendData(ttm::dbus::Command::ADD, b);
- std::string result = b.GetString(CMD_RESULT_KEY);
+ std::string result = b.GetString(ttm::dbus::kCmdResultKey);
EXPECT_EQ(result, "error");
}
WillOnce(Return(msg));
tizen_base::Bundle b;
ttm::loader::ThemeInfo ti;
- b.Add(CMD_RESULT_KEY, "ok");
- b.Add(CMD_GET_KEY,
+ b.Add(ttm::dbus::kCmdResultKey, "ok");
+ b.Add(ttm::dbus::kCmdDataKey,
reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
- b.Add(CMD_GET_IDS_KEY, std::vector<std::string>());
+ b.Add(ttm::dbus::kCmdDataKey, std::vector<std::string>());
GVariant *gv = g_variant_new("(s)", b.ToRaw().first.get());
EXPECT_CALL(GetMock<GioMock>(),
g_dbus_message_get_body(_)).WillOnce(Return(gv));
#include <cstdio>
#include <memory>
+#include "theme/dbus/command.h"
#include "theme/dbus/request_handler.h"
#include "theme_provider/control_request_handler.h"
#include "theme_provider/package_event_request_handler.h"
proxy_->SaveTheme(info);
tizen_base::Bundle b;
- b.Add(CMD_SET_ID_KEY, "testid");
+ b.Add(ttm::dbus::kCmdDataKey, "testid");
handler.OnRequest(ttm::dbus::Command::SET_ID, b);
auto cur = proxy_->GetLoadedTheme();
PackageEventRequestHandler handler(proxy_);
ThemeInfo info(b_);
- tizen_base::Bundle b;
- b.Add(CMD_ADD_KEY,
- reinterpret_cast<char*>(info.Serialize().ToRaw().first.get()));
- handler.OnRequest(ttm::dbus::Command::ADD, b);
+ handler.OnRequest(ttm::dbus::Command::ADD, info.Serialize());
auto theme = proxy_->LoadTheme("testid");
EXPECT_NE(theme, nullptr);
v2.Add("description", "test_v2");
ThemeInfo info2(v2);
- b = info2.Serialize();
- b.Add(CMD_UPDATE_KEY,
- reinterpret_cast<char*>(info2.Serialize().ToRaw().first.get()));
- handler.OnRequest(ttm::dbus::Command::UPDATE, b);
+ handler.OnRequest(ttm::dbus::Command::UPDATE, info2.Serialize());
theme = proxy_->LoadTheme("testid");
EXPECT_NE(theme, nullptr);
EXPECT_EQ(theme->GetId(), "testid");
EXPECT_EQ(theme->GetVersion(), "2.0");
- b.Add(CMD_REMOVE_KEY, "testid");
- handler.OnRequest(ttm::dbus::Command::REMOVE, b);
+ handler.OnRequest(ttm::dbus::Command::REMOVE, info2.Serialize());
theme = proxy_->LoadTheme("testid");
EXPECT_EQ(theme, nullptr);
}
proxy_->SaveTheme(info2);
tizen_base::Bundle b;
- b.Add(CMD_GET_KEY, "testid");
+ b.Add(ttm::dbus::kCmdDataKey, "testid");
auto rb = handler.OnRequest(ttm::dbus::Command::GET, b);
- tizen_base::Bundle result(rb.GetString(CMD_GET_KEY));
+ tizen_base::Bundle result(rb.GetString(ttm::dbus::kCmdDataKey));
ThemeInfo theme(result);
EXPECT_EQ(theme.GetId(), "testid");
rb = handler.OnRequest(ttm::dbus::Command::GET_IDS, {});
- std::vector<std::string> ids = rb.GetStringArray(CMD_GET_IDS_KEY);
+ std::vector<std::string> ids = rb.GetStringArray(ttm::dbus::kCmdDataKey);
EXPECT_EQ(ids.size(), 2);
}
#include <memory>
#include <string>
+#include "theme/dbus/command.h"
#include "theme/loader/theme_event.h"
#include "theme/loader/theme_info.h"
#include "theme/loader/theme_info_loader.h"
WillOnce(Return(msg));
tizen_base::Bundle b;
std::vector<std::string> ids_vec;
- b.Add(CMD_RESULT_KEY, "ok");
- b.Add(CMD_GET_IDS_KEY, ids_vec);
+ b.Add(ttm::dbus::kCmdResultKey, "ok");
+ b.Add(ttm::dbus::kCmdDataKey, ids_vec);
auto br = b.ToRaw();
char* b_raw = reinterpret_cast<char*>(br.first.get());
EXPECT_CALL(GetMock<GioMock>(),
WillOnce(Return(msg));
tizen_base::Bundle b;
ThemeInfo ti;
- b.Add(CMD_RESULT_KEY, "ok");
- b.Add(CMD_GET_KEY,
+ b.Add(ttm::dbus::kCmdResultKey, "ok");
+ b.Add(ttm::dbus::kCmdDataKey,
reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
auto br = b.ToRaw();
char* b_raw = reinterpret_cast<char*>(br.first.get());
WillOnce(Return(msg));
tizen_base::Bundle b;
ThemeInfo ti;
- b.Add(CMD_RESULT_KEY, "ok");
- b.Add(CMD_GET_KEY,
+ b.Add(ttm::dbus::kCmdResultKey, "ok");
+ b.Add(ttm::dbus::kCmdDataKey,
reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
auto br = b.ToRaw();
char* b_raw = reinterpret_cast<char*>(br.first.get());