PageRenderTime 582ms CodeModel.GetById 347ms app.highlight 4ms RepoModel.GetById 197ms app.codeStats 0ms

/apps/launcher/main.c

http://ftk.googlecode.com/
C | 54 lines | 46 code | 8 blank | 0 comment | 8 complexity | 0766df794a21e8593a858ec37c260668 MD5 | raw file
 1#include "ftk.h"
 2#include <dlfcn.h>
 3
 4typedef Ret (*FtkMain)(int argc, char* argv[]);
 5
 6static Ret launch_app(const char* sharelib, const char* function, int argc, char* argv[])
 7{
 8	void* handle = dlopen(sharelib, RTLD_NOW);
 9	if(handle != NULL)
10	{
11		FtkMain entry = (FtkMain)dlsym(handle, function);
12		if(entry != NULL)
13		{
14			return entry(argc, argv);
15		}
16		else
17		{
18			ftk_logd("dlsym %s failed.\n", function);
19		}
20	}
21	else
22	{
23		ftk_logd("dlopen %s failed.\n", sharelib);
24	}
25
26	return RET_FAIL;
27}
28
29int main(int argc, char* argv[])
30{
31	const char* sharelib = NULL;
32	const char* function = NULL;
33	if(argc < 2)
34	{
35		ftk_logd("Usage: %s sharelib [function (deault use ftk_main)]\n", argv[0]);
36
37		return 0;
38	}
39
40	sharelib = argv[1];
41	function = argv[2] != NULL ? argv[2] : "ftk_main";
42	ftk_init(argc, argv);
43
44	if(launch_app(sharelib, function, argc, argv) == RET_OK)
45	{
46		ftk_run();
47	}
48	else
49	{
50		ftk_loge("launch %s %s failed.\n", sharelib, function);
51	}
52
53	return 0;
54}