2 // Created by DXL on 2017/9/1.
10 // native thread attach label
11 static bool g_IsAttach
;
13 // get current env for jvm
15 JNIEnv
*currentThreadEnv
;
17 if ((*g_JavaVM
)->GetEnv(g_JavaVM
, (void **) ¤tThreadEnv
, JNI_VERSION_1_4
) != JNI_OK
) {
18 LOGE("Get Env Fail!");
19 if ((*g_JavaVM
)->AttachCurrentThread(g_JavaVM
, ¤tThreadEnv
, NULL
) != JNI_OK
) {
20 LOGE("Attach the current thread Fail!");
25 LOGE("Attach the current thread Success!");
26 return currentThreadEnv
;
30 //LOGE("Get Env Success!");
31 return currentThreadEnv
;
35 // detach native thread from jvm
38 (*g_JavaVM
)->DetachCurrentThread(g_JavaVM
);
43 CMD
*parse_command_line(const char *commandStr
) {
44 CMD
*cmd
= (CMD
*) malloc(sizeof(CMD
));
48 // copy the source to the heap
49 char *pTmp
= strdup(commandStr
);
50 // new memory size is default 20 for char **
52 cmd
->cmd
= (char **) malloc(size
* sizeof(char **));
58 char *pStr
= strtok(pTmp
, " ");
61 for (; pStr
!= NULL
; ++count
) {
63 if (count
== (size
- 1)) {
65 cmd
->cmd
= (char **) realloc(cmd
->cmd
, size
* sizeof(char **));
67 pStr
= strtok(NULL
, " ");
69 cmd
->cmd
[count
] = pStr
;
72 cmd
->len
= (count
- 1);
76 // cmd arg struct free
77 void free_command_line(CMD
*cmd
) {