#include <string>
+#include "theme/loader/theme_info.h"
#include "theme/loader/theme_info_loader.h"
+#include "theme/dbus/request_broker.h"
+
+#include "theme/utils/logging.h"
namespace ttm {
namespace loader {
tizen_base::Bundle ThemeInfoLoader::OnRequest(dbus::Command cmd,
const tizen_base::Bundle& args) {
- return {};
+ switch (cmd) {
+ case dbus::Command::GET_IDS:
+ case dbus::Command::SET_ID:
+ case dbus::Command::GET:
+ case dbus::Command::RESULT:
+ case dbus::Command::ADD:
+ case dbus::Command::UPDATE:
+ case dbus::Command::REMOVE:
+ case dbus::Command::CHANGED:
+ case dbus::Command::REMOVED:
+ break;
+ default:
+ LOG(ERROR) << "Invalid command type";
+ break;
+ }
+
+ tizen_base::Bundle b;
+ return b;
}
std::string ThemeInfoLoader::AddEvent(std::shared_ptr<IThemeEvent> ev) {
- return "";
+ std::size_t hash = std::hash<std::shared_ptr<IThemeEvent>>{}(ev);
+ std::string key(std::to_string(hash));
+ listeners_.insert(
+ std::pair<std::string, std::shared_ptr<IThemeEvent>>(key, ev));
+
+ return key;
}
int ThemeInfoLoader::RemoveEvent(const std::string& id) {
+ std::map<std::string, std::shared_ptr<IThemeEvent>>::iterator it;
+
+ it = listeners_.find(id);
+ if (it == listeners_.end()) {
+ LOG(ERROR) << "Invalid id : " << id;
+ return -1;
+ }
+
+ listeners_.erase(it);
return 0;
}
std::vector<std::string> ThemeInfoLoader::QueryThemeId() {
- return {};
+ tizen_base::Bundle b;
+ std::string val("get_ids");
+ b.Add("__QUERY__", val.c_str());
+
+ tizen_base::Bundle reply =
+ dbus::RequestBroker::GetInst().SendData(dbus::Command::GET_IDS, b);
+
+ return reply.GetStringArray(val);
}
void ThemeInfoLoader::SetCurrent(const std::string& id) {
+ tizen_base::Bundle b;
+ b.Add("__SET_CURRENT__", id);
+
+ tizen_base::Bundle reply =
+ dbus::RequestBroker::GetInst().SendData(dbus::Command::SET_ID, b);
}
-std::shared_ptr<ThemeInfo> ThemeInfoLoader::LoadCurrent() const {
- return nullptr;
+std::shared_ptr<ThemeInfo> ThemeInfoLoader::LoadCurrent() {
+ if (cache_)
+ return cache_;
+
+ tizen_base::Bundle b;
+ b.Add("__LOAD__", "__CURRENT__");
+
+ tizen_base::Bundle reply =
+ dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
+
+ cache_ = std::make_shared<ThemeInfo>(reply);
+
+ return cache_;
}
std::shared_ptr<ThemeInfo> ThemeInfoLoader::Load(const std::string& id) const {
- return nullptr;
+ if (cache_ && id.compare(cache_->GetId()) == 0)
+ return cache_;
+
+ tizen_base::Bundle b;
+ b.Add("__LOAD__", id);
+
+ tizen_base::Bundle reply =
+ dbus::RequestBroker::GetInst().SendData(dbus::Command::GET, b);
+
+ std::shared_ptr<ThemeInfo> info = std::make_shared<ThemeInfo>(reply);
+
+ return info;
}
} // namespace loader
#include <string>
#include <utility>
#include <vector>
+#include <map>
#include "theme/dbus/request_handler.h"
#include "theme/loader/theme_event.h"
class ThemeInfoLoader : public dbus::IRequestHandler {
public:
- explicit ThemeInfoLoader(std::shared_ptr<ThemeInfo> cache)
- : IRequestHandler(), cache_(std::move(cache)) { }
tizen_base::Bundle OnRequest(dbus::Command cmd,
const tizen_base::Bundle& args) override;
std::vector<std::string> QueryThemeId();
void SetCurrent(const std::string& id);
- std::shared_ptr<ThemeInfo> LoadCurrent() const;
+ std::shared_ptr<ThemeInfo> LoadCurrent();
std::shared_ptr<ThemeInfo> Load(const std::string& id) const;
private:
std::shared_ptr<ThemeInfo> cache_;
- std::list<std::shared_ptr<IThemeEvent>> listeners_;
+ std::map<std::string, std::shared_ptr<IThemeEvent>> listeners_;
};
} // namespace loader