Split Native Parts to SharedObject and Executable
[platform/core/dotnet/launcher.git] / NativeLauncher / src / waiter.h
1 #include <string>
2 #include <functional>
3
4 #include <iostream>
5
6 extern "C" {
7   typedef int (*prepared_callback)(void *data);
8   typedef int (*requested_callback)(void *data);
9   typedef int (*executed_callback)(const char* path, const char* app_root, int argc, char *argv[], void *data);
10
11   void register_launching_callback(prepared_callback prepared,
12       requested_callback requested, executed_callback executed, void *data);
13   void wait_for_launching(int argc, char *argv[]);
14 }
15
16 namespace dotnet {
17 namespace runtime {
18
19 using std::string;
20 using Receiver = std::function<void(int)>;
21
22 enum Status
23 {
24   Started,
25   Prepared,
26   Requested,
27   Executed
28 };
29
30 class WaiterContext
31 {
32   public:
33     prepared_callback Prepared;
34     requested_callback Requested;
35     executed_callback Executed;
36
37     void *Data;
38
39     WaiterContext();
40     bool Prepare();
41     bool Request();
42     bool Execute(const char *path, const char *app_root, int argc, char *argv[]);
43
44   private:
45     Status Step;
46 };
47
48 class Waiter
49 {
50   public:
51     struct AppInfo
52     {
53       string AppPath;
54       string AppId;
55       string PkgId;
56       string PkgType;
57     };
58
59     int WaitToLaunching(int argc, char *argv[]);
60     void Stop();
61
62     void RegisterFd(int fd, Receiver receiver);
63     void DeregisterFd(int fd);
64     void SetContext(WaiterContext ctx);
65
66   protected:
67     void OnPrepared();
68     void OnRequested(const AppInfo&);
69     void OnWaiting();
70     void OnExecuted(const char *path, const char *app_root, int argc, char *argv[]);
71
72   private:
73     WaiterContext context;
74 };
75
76 }  // namespace runtime
77 }  // namespace dotnet