Skip to content

Commit 6180d1d

Browse files
hs0225daeyeon
authored andcommitted
feat(runtime): add start function
Signed-off-by: Hosung Kim [email protected]
1 parent 5a4b7da commit 6180d1d

File tree

5 files changed

+41
-48
lines changed

5 files changed

+41
-48
lines changed

deps/node/src/lwnode/lwnode-public.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ Runtime::~Runtime() {
6464
delete internal_;
6565
}
6666

67-
std::pair<bool, int> Runtime::Init(int argc,
68-
char** argv,
69-
std::promise<void>&& promise) {
67+
int Runtime::Start(int argc, char** argv, std::promise<void>&& promise) {
7068
internal_->runner_.SetInitPromise(std::move(promise));
71-
return internal_->Init(argc, argv);
72-
}
69+
std::pair<bool, int> init_result = internal_->Init(argc, argv);
7370

74-
void Runtime::Free() {
75-
return internal_->Free();
76-
}
71+
if (init_result.first) {
72+
internal_->Free();
73+
return init_result.second;
74+
}
7775

78-
int Runtime::Run() {
79-
return internal_->Run();
76+
int result = internal_->Run();
77+
internal_->Free();
78+
79+
return result;
8080
}
8181

8282
std::shared_ptr<Port> Runtime::GetPort() {

deps/node/src/node_main_lw.cc

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ int main(int argc, char* argv[]) {
7272
setvbuf(stderr, nullptr, _IONBF, 0);
7373

7474
lwnode::Runtime runtime;
75-
std::pair<bool, int> init_result; // early_return, exit_code
75+
std::pair<bool, int> init_result; // early_return, exit_code
76+
7677
// FIXME: Fix Runtime::Init() call to ensure environment initialization
7778
// before running the loop, Runtime::Run(). This workaround passes a
7879
// promise directly to know when that is.
@@ -82,20 +83,12 @@ int main(int argc, char* argv[]) {
8283
if (!lwnode::InitScriptRootPath()) {
8384
exit(-errno);
8485
}
85-
char* args[] = {"", "index.js", nullptr};
86-
init_result = runtime.Init(2, args, std::move(promise));
87-
} else {
88-
// started by command line
89-
init_result = runtime.Init(argc, argv, std::move(promise));
90-
}
9186

92-
if (init_result.first) {
93-
runtime.Free();
94-
return init_result.second;
87+
char* args[] = {
88+
const_cast<char*>(""), const_cast<char*>("index.js"), nullptr};
89+
return runtime.Start(2, args, std::move(promise));
9590
}
9691

97-
int result = runtime.Run();
98-
runtime.Free();
99-
100-
return result;
92+
// started by command line
93+
return runtime.Start(argc, argv, std::move(promise));
10194
}

include/lwnode/lwnode-public.h

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,35 +31,39 @@ namespace lwnode {
3131

3232
LWNODE_EXPORT bool ParseAULEvent(int argc, char** argv);
3333

34-
// Sets the path of the root directory of the JavaScript. If you do
35-
// not put the path argument, the root path is the app's resource path by
36-
// default on Tizen AUL mode. Be sure to call this function before lwnode::Start
37-
// function.
34+
/**
35+
* Sets the path of the root directory of the JavaScript. If you do
36+
* not put the path argument, the root path is the app's resource path by
37+
* default on Tizen AUL mode. Be sure to call this function before lwnode::Start
38+
* function.
39+
**/
3840
LWNODE_EXPORT bool InitScriptRootPath(const std::string path = "");
3941

4042
LWNODE_EXPORT int Start(int argc, char** argv);
4143

42-
// Sets the dlog tag id for debugging. This is only used on Tizen when not in
43-
// AUL mode.
44+
/**
45+
* Sets the dlog tag id for debugging. This is only used on Tizen when not in
46+
* AUL mode.
47+
**/
4448
LWNODE_EXPORT void SetDlogID(const std::string& appId);
4549

4650
class LWNODE_EXPORT Runtime {
4751
public:
4852
Runtime();
4953
~Runtime();
5054

51-
// Initializes the runtime and returns true if it early termination and sets
52-
// the exit code to the second return value. Otherwise, it returns false
53-
// and you need call Run() to run the runtime.
54-
std::pair<bool, int> Init(int argc,
55-
char** argv,
56-
std::promise<void>&& promise);
57-
58-
// Runs the runtime and returns the exit code. The runtime must be
59-
// initialized.
60-
int Run();
61-
62-
void Free();
55+
/**
56+
* Start the runtime and returns the exit code. It initializes the runtime
57+
* and runs it. When the runtime is initialized, the promise object is set.
58+
*
59+
* @param argc - Argument count.
60+
* @param argv - Argument vector. The element should be the starting file
61+
* name of the application.
62+
* @param promise - Promise object. It will be set when the runtime
63+
* initialization is complete.
64+
* @return Returns the exit code of the runtime.
65+
**/
66+
int Start(int argc, char** argv, std::promise<void>&& promise);
6367

6468
std::shared_ptr<Port> GetPort();
6569

test/embedding/embedtest.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ TEST0(Embedtest, MessagePort2_Post_Many_JS_First) {
4242

4343
std::thread worker = std::thread(
4444
[&](std::promise<void>&& promise) mutable {
45-
runtime->Init(COUNT_OF(args), args, std::move(promise));
46-
runtime->Run();
47-
runtime->Free();
45+
runtime->Start(COUNT_OF(args), args, std::move(promise));
4846
},
4947
std::move(promise));
5048

test/embedding/example.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ int main(int argc, char* argv[]) {
2222
// FIXME: Fix Runtime::Init() call to ensure environment initialization
2323
// before running the loop, Runtime::Run(). This workaround passes a
2424
// promise directly to know when that is.
25-
runtime->Init(COUNT_OF(args), args, std::move(promise));
26-
runtime->Run();
27-
runtime->Free();
25+
runtime->Start(COUNT_OF(args), args, std::move(promise));
2826
},
2927
std::move(promise));
3028

0 commit comments

Comments
 (0)