void ServiceContext::Shutdown() {
if (!handle_) return;
- auto* shutdown_func = reinterpret_cast<void (*)(void)>(dlsym(handle_, kUnitedServiceShutdown));
+ auto* shutdown_func =
+ reinterpret_cast<void (*)(void)>(dlsym(handle_, kUnitedServiceShutdown));
if (shutdown_func == nullptr) {
_E("dlsym() is failed. error=%s", dlerror());
} else {
std::shared_ptr<Service> ServiceContext::GetService() const { return service_; }
+std::shared_ptr<ServiceInfo> ServiceContext::GetServiceInfo() const {
+ return info_;
+}
+
const std::string& ServiceContext::GetName() const { return info_->GetName(); }
bool ServiceContext::Load() {
bool Init();
void Shutdown();
std::shared_ptr<Service> GetService() const;
+ std::shared_ptr<ServiceInfo> GetServiceInfo() const;
const std::string& GetName() const;
private:
namespace tizen_base {
-ServiceInfo::ServiceInfo(std::string conf_name, const Dictionary& dictionary)
+ServiceInfo::ServiceInfo(std::string conf_name,
+ std::shared_ptr<Dictionary> dictionary)
: conf_name_(std::move(conf_name)) {
- description_ = dictionary.Get(kDescription);
- name_ = dictionary.Get(kName);
- mode_ = dictionary.Get(kMode);
- type_ = dictionary.Get(kType);
- path_ = dictionary.Get(kPath);
+ description_ = dictionary->Get(kDescription);
+ name_ = dictionary->Get(kName);
+ mode_ = dictionary->Get(kMode);
+ type_ = dictionary->Get(kType);
+ path_ = dictionary->Get(kPath);
}
ServiceInfo::~ServiceInfo() {}
#ifndef SERVICE_INFO_HH_
#define SERVICE_INFO_HH_
+#include <memory>
#include <string>
#include "dictionary.hh"
class ServiceInfo {
public:
- ServiceInfo(std::string conf_name, const Dictionary& dictionary);
+ ServiceInfo(std::string conf_name, std::shared_ptr<Dictionary> dictionary);
~ServiceInfo();
const std::string& GetConfName() const;
#include <tizen_core.h>
#include <tizen_core_channel.h>
+#include <filesystem>
#include <utility>
+#include "exception.hh"
+#include "iniparser.hh"
#include "log_private.hh"
+namespace {
+
+constexpr const char kPathUnitedService[] = "/usr/share/united-service/";
+
+} // namespace
+
namespace tizen_base {
+namespace fs = std::filesystem;
ServiceLoader::ServiceLoader(int argc, char** argv, std::string name)
: argc_(argc), argv_(argv), name_(std::move(name)) {
_E("tizen_core_add_channel() is failed");
return false;
}
-
receiver_ = nullptr;
- return false;
+
+ 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;
+ }
+
+ return true;
}
void ServiceLoader::Shutdown() {
}
}
+void ServiceLoader::LoadServices() {
+ const fs::path directory(kPathUnitedService + name_);
+ for (auto const& entry : fs::directory_iterator(directory)) {
+ if (entry.is_regular_file()) {
+ auto file(entry.path());
+ if (file.extension() == ".service") {
+ auto dictionary = IniParser::Parse(file.string());
+ auto info =
+ std::make_shared<ServiceInfo>(file.string(), std::move(dictionary));
+ auto context = std::make_shared<ServiceContext>(std::move(info));
+ context->Init();
+ contexts_.push_back(std::move(context));
+ }
+ }
+ }
+}
+
int ServiceLoader::Run() {
OnCreate();
running_ = true;
* limitations under the License.
*/
-#include <tizen_core.h>
-
#include <bundle_cpp.h>
+#include <tizen_core.h>
+#include <memory>
#include <string>
+#include "service_context.hh"
+#include "service_info.hh"
+
namespace tizen_base {
class ServiceLoader {
private:
bool Init();
void Shutdown();
+ void LoadServices();
static void ChannelReceiveCb(tizen_core_channel_object_h object,
void* user_data);
- private : int argc_;
+ private:
+ int argc_;
char** argv_;
std::string name_;
tizen_core_task_h task_ = nullptr;
tizen_core_channel_receiver_h receiver_ = nullptr;
tizen_core_source_h source_ = nullptr;
bool running_ = false;
+ std::vector<std::shared_ptr<ServiceContext>> contexts_;
};
} // namespace tizen_base