#include "dictionary.hh"
+#include <utility>
+
+#include "log_private.hh"
+
namespace tizen_base {
Dictionary::Builder& Dictionary::Builder::SetNumber(dictionary* d) {
for (unsigned int i = 0; i < d->n; ++i) {
std::string key = d->key[i] ? d->key[i] : "";
std::string value = d->val[i] ? d->val[i] : "";
+ _D("key=%s, value=%s", key.c_str(), value.c_str());
map_[std::move(key)] = std::move(value);
}
void Service::Quit() {
if (!running_) return;
+ std::unique_lock<std::mutex> lock(mutex_);
tizen_core_source_h source = nullptr;
tizen_core_add_idle_job(
core_,
[](void* user_data) -> bool {
auto* service = static_cast<Service*>(user_data);
service->OnDestroy();
+ service->cond_var_.notify_one();
return false;
},
this, &source);
tizen_core_task_quit(task_);
+ cond_var_.wait(lock, [this]() { return state_ == State::Destroyed; });
running_ = false;
}
#include <tizen_core.h>
#include <tizen_core_channel.h>
+#include <condition_variable>
#include <memory>
+#include <mutex>
#include <string>
namespace tizen_base {
tizen_core_channel_receiver_h receiver_ = nullptr;
tizen_core_source_h source_ = nullptr;
bool running_ = false;
+ std::mutex mutex_;
+ std::condition_variable cond_var_;
};
} // namespace tizen_base
void ServiceContext::Shutdown() {
if (!handle_) return;
+ if (service_) service_->Quit();
+
auto* shutdown_func =
reinterpret_cast<void (*)(void)>(dlsym(handle_, kUnitedServiceShutdown));
if (shutdown_func == nullptr) {
namespace {
-static const std::string kTagUnitedService = "United-Service";
-static const std::string kDescription = kTagUnitedService + ":Description";
-static const std::string kName = kTagUnitedService + ":Name";
-static const std::string kMode = kTagUnitedService + ":Mode";
-static const std::string kType = kTagUnitedService + ":Type";
-static const std::string kPath = kTagUnitedService + ":Path";
+static const std::string kTagUnitedService = "united-service";
+static const std::string kDescription = kTagUnitedService + ":description";
+static const std::string kName = kTagUnitedService + ":name";
+static const std::string kMode = kTagUnitedService + ":mode";
+static const std::string kType = kTagUnitedService + ":type";
+static const std::string kPath = kTagUnitedService + ":path";
} // namespace
std::shared_ptr<Dictionary> dictionary)
: conf_name_(std::move(conf_name)) {
description_ = dictionary->Get(kDescription);
+ _D("Description=%s", description_.c_str());
name_ = dictionary->Get(kName);
+ _D("Name=%s", name_.c_str());
mode_ = dictionary->Get(kMode);
+ _D("Mode=%s", mode_.c_str());
type_ = dictionary->Get(kType);
+ _D("Type=%s", type_.c_str());
path_ = dictionary->Get(kPath);
+ _D("Path=%s", path_.c_str());
}
ServiceInfo::~ServiceInfo() {}
_E("tizen_core_add_channel() is failed");
return false;
}
- receiver_ = nullptr;
-
- try {
- LoadServices();
- } catch (const fs::filesystem_error& e) {
- _E("Exception occurs. error: %s(%d)", e.what(), e.code().value());
- return false;
- } catch (const Exception& e) {
- _E("Exception occurs. error: %s", e.what());
- return false;
- }
+ receiver_ = nullptr;
return true;
}
}
}
-void ServiceLoader::OnCreate() {}
+void ServiceLoader::OnCreate() {
+ try {
+ LoadServices();
+ } catch (const fs::filesystem_error& e) {
+ _E("Exception occurs. error: %s(%d)", e.what(), e.code().value());
+ } catch (const Exception& e) {
+ _E("Exception occurs. error: %s", e.what());
+ }
+}
-void ServiceLoader::OnDestroy() {}
+void ServiceLoader::OnDestroy() {
+ for (auto& context : contexts_) {
+ context->Shutdown();
+ }
+}
void ServiceLoader::OnMessageReceived(const std::string& sender,
const tizen_base::Bundle& envelope) {}
}
void OnCreate() override {
+ tizen_base::ServiceLoader::OnCreate();
if (callback_.create) callback_.create(user_data_);
}
void OnDestroy() override {
+ tizen_base::ServiceLoader::OnDestroy();
if (callback_.destroy) callback_.destroy(user_data_);
}