OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include <dlfcn.h> | 8 #include <dlfcn.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... | |
21 return true; | 21 return true; |
22 } | 22 } |
23 return false; | 23 return false; |
24 } | 24 } |
25 | 25 |
26 int launch_app(int (*app_main)(int, const char**), int argc, | 26 int launch_app(int (*app_main)(int, const char**), int argc, |
27 const char** argv) { | 27 const char** argv) { |
28 return (*app_main)(argc, argv); | 28 return (*app_main)(argc, argv); |
29 } | 29 } |
30 | 30 |
31 void* load_library(const char** argv, const char* libraryName) | |
32 { | |
33 // attempt to lookup the location of the shared libraries | |
34 char libraryLocation[100]; | |
35 sprintf(libraryLocation, "%s/lib/lib%s.so", argv[0], libraryName); | |
36 if (!file_exists(libraryLocation)) { | |
37 printf("ERROR: Unable to find the appropriate library in the Skia App.\n "); | |
38 printf("ERROR: Did you provide the correct program_name?\n"); | |
39 usage(argv[0]); | |
40 return NULL; | |
41 } | |
42 | |
43 // load the appropriate library | |
44 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); | |
45 if (!appLibrary) { | |
46 printf("ERROR: Unable to open the shared library.\n"); | |
47 printf("ERROR: %s", dlerror()); | |
48 return NULL; | |
49 } | |
50 | |
51 return appLibrary; | |
52 } | |
53 | |
31 int main(int argc, const char** argv) { | 54 int main(int argc, const char** argv) { |
32 | 55 |
33 // check that the program name was specified | 56 // check that the program name was specified |
34 if (argc < 2) { | 57 if (argc < 2) { |
35 printf("ERROR: No program_name was specified\n"); | 58 printf("ERROR: No program_name was specified\n"); |
36 usage(argv[0]); | 59 usage(argv[0]); |
37 return -1; | 60 return -1; |
38 } | 61 } |
39 | 62 |
40 // attempt to lookup the location of the skia app | 63 // attempt to lookup the location of the skia app |
41 const char* appLocation = "/data/data/com.skia"; | 64 const char* appLocation = "/data/data/com.skia"; |
42 if (!file_exists(appLocation)) { | 65 if (!file_exists(appLocation)) { |
43 printf("ERROR: Unable to find the com.skia app on the device.\n"); | 66 printf("ERROR: Unable to find the com.skia app on the device.\n"); |
44 return -1; | 67 return -1; |
45 } | 68 } |
46 | 69 |
47 // attempt to lookup the location of the shared libraries | 70 // load the local skia shared library |
48 char libraryLocation[100]; | 71 load_library(argv, "libskia_local.so"); |
djsollen
2013/05/30 20:35:29
if this returns NULL we should abort and return -1
| |
49 sprintf(libraryLocation, "%s/lib/lib%s.so", appLocation, argv[1]); | |
50 if (!file_exists(libraryLocation)) { | |
51 printf("ERROR: Unable to find the appropriate library in the Skia App.\n "); | |
52 printf("ERROR: Did you provide the correct program_name?\n"); | |
53 usage(argv[0]); | |
54 return -1; | |
55 } | |
56 | 72 |
57 // load the appropriate library | 73 // load the appropriate library |
58 void* appLibrary = dlopen(libraryLocation, RTLD_LOCAL | RTLD_LAZY); | 74 void* appLibrary = load_library(argv, argv[1]); |
djsollen
2013/05/30 20:35:29
same here
| |
59 if (!appLibrary) { | |
60 printf("ERROR: Unable to open the shared library.\n"); | |
61 printf("ERROR: %s", dlerror()); | |
62 return -1; | |
63 } | |
64 | 75 |
65 // find the address of the main function | 76 // find the address of the main function |
66 int (*app_main)(int, const char**); | 77 int (*app_main)(int, const char**); |
67 *(void **) (&app_main) = dlsym(appLibrary, "main"); | 78 *(void **) (&app_main) = dlsym(appLibrary, "main"); |
68 | 79 |
69 if (!app_main) { | 80 if (!app_main) { |
70 printf("ERROR: Unable to load the main function of the selected program. \n"); | 81 printf("ERROR: Unable to load the main function of the selected program. \n"); |
71 printf("ERROR: %s\n", dlerror()); | 82 printf("ERROR: %s\n", dlerror()); |
72 return -1; | 83 return -1; |
73 } | 84 } |
74 | 85 |
75 // find the address of the SkPrintToConsole function | 86 // find the address of the SkPrintToConsole function |
76 void (*app_SkDebugToStdOut)(bool); | 87 void (*app_SkDebugToStdOut)(bool); |
77 *(void **) (&app_SkDebugToStdOut) = dlsym(appLibrary, "AndroidSkDebugToStdOu t"); | 88 *(void **) (&app_SkDebugToStdOut) = dlsym(appLibrary, "AndroidSkDebugToStdOu t"); |
78 | 89 |
79 if (app_SkDebugToStdOut) { | 90 if (app_SkDebugToStdOut) { |
80 (*app_SkDebugToStdOut)(true); | 91 (*app_SkDebugToStdOut)(true); |
81 } else { | 92 } else { |
82 printf("WARNING: Unable to redirect output to the console.\n"); | 93 printf("WARNING: Unable to redirect output to the console.\n"); |
83 printf("WARNING: %s\n", dlerror()); | 94 printf("WARNING: %s\n", dlerror()); |
84 } | 95 } |
85 | 96 |
86 // pass all additional arguments to the main function | 97 // pass all additional arguments to the main function |
87 return launch_app(app_main, argc - 1, ++argv); | 98 return launch_app(app_main, argc - 1, ++argv); |
88 } | 99 } |
OLD | NEW |