13 #include <common/extension.h>
15 static std::string prefix_ = "libwebapis";
16 static std::string postfix_ = ".so";
17 static std::vector<std::string> apinamespaces = {"tizen", "xwalk", "webapis"};
19 typedef common::Extension *(*CreateExtensionFunc)(void);
21 struct module_description {
24 std::vector<std::string> entries;
28 static XW_Extension ext = 0;
29 static std::map<XW_Extension, module_description> descriptions;
32 #define PRINT_TAB() std::cout << "\t"
38 std::cout << "[" << std::endl;
39 for (const auto& kv : descriptions) {
40 const module_description &desc = kv.second;
42 std::string::size_type n = desc.name.find('.');
44 n == std::string::npos ? desc.name : desc.name.substr(0, n);
46 if (std::find(apinamespaces.begin(), apinamespaces.end(), ns) ==
47 apinamespaces.end()) {
52 std::cout << "{" << std::endl;
55 std::cout << "\"name\":\"" << desc.name << "\"," << std::endl;
58 std::cout << "\"lib\":\"" << desc.lib << "\"," << std::endl;
61 std::cout << "\"entry_points\": [";
62 for (std::vector<std::string>::size_type i=0; i<desc.entries.size(); i++) {
66 std::cout << "\"" << desc.entries[i] << "\"";
68 std::cout << "]" << std::endl;
71 if (kv.first != ext) {
74 std::cout << std::endl;
76 std::cout << "]" << std::endl;
79 const void* get_interface(const char* name) {
80 if (!strcmp(name, XW_CORE_INTERFACE_1)) {
81 static const XW_CoreInterface coreInterface1 = {
82 [](XW_Extension extension, const char* name) {
83 module_description *desc = &descriptions[extension];
86 [](XW_Extension extension, const char* api) {},
87 [](XW_Extension extension, XW_CreatedInstanceCallback created,
88 XW_DestroyedInstanceCallback destroyed) {},
89 [](XW_Extension extension, XW_ShutdownCallback shutdown_callback) {},
90 [](XW_Instance instance, void* data) {},
91 [](XW_Instance instance) -> void* { return nullptr; }
93 return &coreInterface1;
96 if (!strcmp(name, XW_INTERNAL_ENTRY_POINTS_INTERFACE_1)) {
97 static const XW_Internal_EntryPointsInterface entryPointsInterface1 = {
98 [](XW_Extension extension, const char** entries) {
99 module_description *desc = &descriptions[extension];
100 for (int i=0; entries[i]; i++) {
101 desc->entries.push_back(std::string(entries[i]));
105 return &entryPointsInterface1;
108 if (!strcmp(name, XW_MESSAGING_INTERFACE_2)) {
109 static const XW_MessagingInterface_1 messagingInterface1 = {
110 [](XW_Extension extension, XW_HandleMessageCallback handle_message) {
112 [](XW_Instance instance, const char* message) {
115 return &messagingInterface1;
118 if (!strcmp(name, XW_INTERNAL_SYNC_MESSAGING_INTERFACE_1)) {
119 static const XW_Internal_SyncMessagingInterface syncMessagingInterface1 = {
120 [](XW_Extension extension,
121 XW_HandleSyncMessageCallback handle_sync_msg) {},
122 [](XW_Instance instance, const char* reply) {},
123 [](XW_Instance instance, const char* reply, int size) {}};
124 return &syncMessagingInterface1;
127 if (!strcmp(name, XW_INTERNAL_RUNTIME_INTERFACE_1)) {
128 static const XW_Internal_RuntimeInterface_1 runtimeInterface1 = {
129 [](XW_Extension extension, const char* key, char* value, size_t vlen) {
132 return &runtimeInterface1;
135 if (!strcmp(name, XW_INTERNAL_PERMISSIONS_INTERFACE_1)) {
136 static const XW_Internal_PermissionsInterface_1 permissionsInterface1 = {
137 [](XW_Extension extension, const char* api_name) -> int {
140 [](XW_Extension extension, const char* perm_table) -> int {
144 return &permissionsInterface1;
150 int main(int argc, char* argv[]) {
152 std::cerr << "Need tizen crosswalk path" << std::endl;
155 std::string lib_path = argv[1];
156 if (lib_path.empty()) {
157 std::cerr << "Invalid libpath for tec." << std::endl;
161 std::string tec_path = argv[2];
162 if (tec_path.empty()) {
163 std::cerr << "Invalid tizen crosswalk path" << std::endl;
167 struct dirent** namelist;
168 int num_entries = scandir(tec_path.c_str(), &namelist, NULL, alphasort);
169 if( num_entries >= 0 ) {
170 for( int i = 0; i < num_entries; ++i ) {
171 std::string fname = namelist[i]->d_name;
173 if (fname.size() >= prefix_.size() + postfix_.size() &&
174 !fname.compare(0, prefix_.size(), prefix_) &&
175 !fname.compare(fname.size() - postfix_.size(), postfix_.size(),
177 std::string so_path = tec_path + "/" + fname;
178 void *handle = dlopen(so_path.c_str(), RTLD_LAZY);
179 if (handle == NULL) {
180 std::cerr << "cannot open " << so_path << std::endl;
181 char* error = dlerror();
182 std::cerr << "Error >>" << ((error == NULL) ? "NULL" : error) << std::endl;
186 XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>(
187 dlsym(handle, "XW_Initialize"));
190 std::cerr << "Can not loading extension " << fname << std::endl;
193 descriptions[ext] = module_description();
194 descriptions[ext].lib = lib_path + "/" + fname;
195 int ret = initialize(ext, get_interface);
197 std::cerr << "Error loading extension " << fname << std::endl;
201 // some Shared libraries have static finalizer.
202 // __attribute__((destructor)) this gcc extension makes finalizer.
203 // if close it, it can makes segfault.
204 // True, It's shared object's problem. but we can't fix it.
205 // so don't close it in only this tool. just finish process.
215 if( errno == ENOENT )
216 std::cerr << "path not exist : " << tec_path << std::endl;
220 // it would be need for ignore loaded libraries destructor