summaryrefslogtreecommitdiff
path: root/NativeLauncher/src/waiter.cc
diff options
context:
space:
mode:
Diffstat (limited to 'NativeLauncher/src/waiter.cc')
-rw-r--r--NativeLauncher/src/waiter.cc133
1 files changed, 103 insertions, 30 deletions
diff --git a/NativeLauncher/src/waiter.cc b/NativeLauncher/src/waiter.cc
index 6f83482..c7cb794 100644
--- a/NativeLauncher/src/waiter.cc
+++ b/NativeLauncher/src/waiter.cc
@@ -30,16 +30,30 @@ static std::vector<pollfd> Fdlist_;
static std::map<int, FdHandler> Handlers_;
static Waiter::AppInfo AppInfo_;
-void Waiter::OnPrepare()
+void Waiter::OnPrepared()
{
- // preload the libraries.
- if (prepare_ != nullptr)
- prepare_();
+ if (!context.Prepare())
+ {
+ _DBG("Fail to Prepare...");
+ }
}
-void Waiter::OnLaunchRequested(const AppInfo& info)
+void Waiter::OnRequested(const AppInfo& info)
{
// do some job on user id is still system
+
+ if (!context.Request())
+ {
+ _DBG("Fail to Request...");
+ }
+}
+
+void Waiter::OnExecuted(const char *path, const char *app_root, int argc, char *argv[])
+{
+ if (!context.Execute(path, app_root, argc, argv))
+ {
+ _DBG("Fail to Execute...");
+ }
}
void Waiter::OnWaiting()
@@ -98,18 +112,6 @@ void Waiter::DeregisterFd(int fd)
Handlers_.erase(fd);
}
-
-Waiter::Waiter(Action prepare, Action requested, Executor executor)
-{
- prepare_ = prepare;
- requested_ = requested;
- executor_ = executor;
-}
-
-Waiter::~Waiter()
-{
-}
-
int Waiter::WaitToLaunching(int argc, char *argv[])
{
#ifndef NO_TIZEN
@@ -117,7 +119,7 @@ int Waiter::WaitToLaunching(int argc, char *argv[])
{
_DBG("on_create..."); // XXX
Waiter* waiter = static_cast<Waiter*>(user_data);
- waiter->OnPrepare();
+ waiter->OnPrepared();
};
auto on_launch = [](int argc, char **argv, const char *app_path,
@@ -139,7 +141,7 @@ int Waiter::WaitToLaunching(int argc, char *argv[])
PkgType : pkg_type
};
- waiter->OnLaunchRequested(info);
+ waiter->OnRequested(info);
return 0;
};
@@ -149,7 +151,7 @@ int Waiter::WaitToLaunching(int argc, char *argv[])
string app_root(aul_get_app_root_path());
Waiter* waiter = static_cast<Waiter*>(user_data);
- waiter->executor_(argv[0], app_root, argc, argv);
+ waiter->OnExecuted(argv[0], app_root.c_str(), argc, argv);
return 0;
};
@@ -197,7 +199,12 @@ int Waiter::WaitToLaunching(int argc, char *argv[])
return launchpad_loader_main(argc, argv, &callbacks, &adapter, this);
#else
- if (argc < 2) return -1;
+ if (argc < 2)
+ {
+ _DBG("not enough args : %d", argc);
+ return -1;
+ }
+ _DBG("argv[1] = %s", argv[1]);
std::string app_path(argv[1]);
std::string app_root;
auto pos = app_path.find_last_of('/');
@@ -206,17 +213,83 @@ int Waiter::WaitToLaunching(int argc, char *argv[])
else
app_root = ".";
- this->OnPrepare();
- AppInfo info = {
- AppPath : argv[1],
- AppId : "",
- PkgId : "",
- PkgType : ""
- };
- this->OnLaunchRequested(info);
- this->executor_(app_path, app_root, argc, argv);
+ this->OnPrepared();
+ AppInfo info = {
+ AppPath : argv[1],
+ AppId : "",
+ PkgId : "",
+ PkgType : ""
+ };
+ this->OnRequested(info);
+ this->OnExecuted(app_path.c_str(), app_root.c_str(), argc, argv);
#endif
}
+void Waiter::SetContext(WaiterContext ctx)
+{
+ context = ctx;
+}
+
+WaiterContext::WaiterContext()
+{
+ Step = Status::Started;
+}
+
+bool WaiterContext::Prepare()
+{
+ if (Step == Status::Started && Prepared != nullptr && Prepared(Data) == 0)
+ {
+ Step = Status::Prepared;
+ return true;
+ }
+ return false;
+}
+
+bool WaiterContext::Request()
+{
+ if (Step == Status::Prepared && Requested != nullptr && Requested(Data) == 0)
+ {
+ Step = Status::Requested;
+ return true;
+ }
+ return false;
+}
+
+bool WaiterContext::Execute(const char *path, const char *app_root, int argc, char *argv[])
+{
+ if (Step == Status::Requested && Executed != nullptr &&
+ Executed(path, app_root, argc, argv, Data))
+ {
+ Step = Status::Executed;
+ return true;
+ }
+ return false;
+}
+
} // namespace runtime
} // namespace dotnet
+
+using dotnet::runtime::Waiter;
+using dotnet::runtime::WaiterContext;
+
+static Waiter waiter;
+
+void register_launching_callback(prepared_callback prepared,
+ requested_callback requested, executed_callback executed, void *data)
+{
+ WaiterContext context;
+ context.Prepared = prepared;
+ context.Requested = requested;
+ context.Executed = executed;
+ context.Data = data;
+
+ waiter.SetContext(context);
+}
+
+void wait_for_launching(int argc, char *argv[])
+{
+ _DBG("wait_for_launching...");
+
+ waiter.WaitToLaunching(argc, argv);
+}
+