Beispiel #1
0
		int setup_apple(unsigned int config, int argc, char *argv[])
		{
			CONFIG = config;
#if PLATFORM_IOS
			return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
#elif PLATFORM_OSX
			if (CONFIG & sys::CONFIG_CUSTOM_TIMER)
			{
				init(config);
			}
			else
				return NSApplicationMain(argc, (const char **)argv);
#endif
			return 0;
		}
Beispiel #2
0
/*
 * DarwinHandleGUI
 *  This function is called first from main(). The first time
 *  it is called we start the Mac OS X front end. The front end
 *  will call main() again from another thread to run the X
 *  server. On the second call this function loads the user
 *  preferences set by the Mac OS X front end.
 */
void DarwinHandleGUI(
    int         argc,
    char        *argv[],
    char        *envp[] )
{
    static Bool been_here = FALSE;
    int         main_exit, i;
    int         fd[2];

    if (been_here) {
        QuartzReadPreferences();
        return;
    }
    been_here = TRUE;

    // Make a pipe to pass events
    assert( pipe(fd) == 0 );
    darwinEventFD = fd[0];
    quartzEventWriteFD = fd[1];
    fcntl(darwinEventFD, F_SETFL, O_NONBLOCK);

    // Store command line arguments to pass back to main()
    argcGlobal = argc;
    argvGlobal = argv;
    envpGlobal = envp;

    // Determine if we need to start X clients
    // and what display mode to use
    quartzStartClients = 1;
    for (i = 1; i < argc; i++) {
        if (!strcmp(argv[i], "-nostartx")) {
            quartzStartClients = 0;    
        } else if (!strcmp( argv[i], "-fullscreen")) {
            quartzRootless = 0;
        } else if (!strcmp( argv[i], "-rootless")) {
            quartzRootless = 1;
        }
    }

    quartz = TRUE;
    main_exit = NSApplicationMain(argc, argv);
    exit(main_exit);
}
/*
 * DarwinHandleGUI
 *  This function is called first from main(). The first time
 *  it is called we start the Mac OS X front end. The front end
 *  will call main() again from another thread to run the X
 *  server. On the second call this function loads the user
 *  preferences set by the Mac OS X front end.
 */
void DarwinHandleGUI(
    int         argc,
    char        *argv[],
    char        *envp[] )
{
    static Bool been_here = FALSE;
    int         main_exit, i;
    int         fd[2];

    if (been_here) {
#ifdef INXDARWINAPP
        QuartzReadPreferences();
#endif
        return;
    }
    been_here = TRUE;

    // Make a pipe to pass events
    assert( pipe(fd) == 0 );
    darwinEventReadFD = fd[0];
    darwinEventWriteFD = fd[1];
    fcntl(darwinEventReadFD, F_SETFL, O_NONBLOCK);

    // Store command line arguments to pass back to main()
    argcGlobal = argc;
    argvGlobal = argv;
    envpGlobal = envp;

    quartzStartClients = 1;
    for (i = 1; i < argc; i++) {
        // Display version info without starting Mac OS X UI if requested
        if (!strcmp( argv[i], "-showconfig" ) || !strcmp( argv[i], "-version" )) {
            DarwinPrintBanner();
            exit(0);
        }

        // Determine if we need to start X clients
        // and what display mode to use
        if (!strcmp(argv[i], "-nostartx")) {
            quartzStartClients = 0;    
        } else if (!strcmp( argv[i], "-fullscreen")) {
            quartzRootless = 0;
        } else if (!strcmp( argv[i], "-rootless")) {
            quartzRootless = 1;
        }
    }

#ifdef INXQUARTZ
    /* Initially I ran the X server on the main thread, and received
       events on the second thread. But now we may be using Carbon,
       that needs to run on the main thread. (Otherwise, when it's
       prebound, it will initialize itself on the wrong thread)
       
       grr.. but doing that means that if the X thread gets scheduled
       before the main thread when we're _not_ prebound, things fail,
       so initialize by hand. */
    extern void _InitHLTB(void);
    
    _InitHLTB();
    
    X11ControllerMain(argc, argv, server_thread, NULL);
#else
    main_exit = NSApplicationMain(argc, argv);
#endif
    exit(main_exit);
}
Beispiel #4
0
/*! Normal entry point for all platforms, including Windows console applications */
int
main(int argc, char** argv)
#endif
{
	int ret;

#if !FOUNDATION_PLATFORM_ANDROID && !FOUNDATION_PLATFORM_PNACL
	_environment_main_args(argc, (const char* const*)argv);
#elif FOUNDATION_PLATFORM_PNACL
	FOUNDATION_UNUSED(instance);
#endif

	ret = main_initialize();
	if (ret < 0)
		return ret;

#if FOUNDATION_PLATFORM_POSIX

	//Set signal handlers
	{
		struct sigaction action;
		memset(&action, 0, sizeof(action));

#if FOUNDATION_COMPILER_CLANG
#  pragma clang diagnostic push
#  pragma clang diagnostic ignored "-Wdisabled-macro-expansion"
#endif

		//Signals we process globally
		action.sa_handler = sighandler;
		sigaction(SIGKILL, &action, 0);
		sigaction(SIGTERM, &action, 0);
		sigaction(SIGQUIT, &action, 0);
		sigaction(SIGINT,  &action, 0);
		sigaction(SIGABRT, &action, 0);

		//Ignore sigpipe
		action.sa_handler = SIG_IGN;
		sigaction(SIGPIPE, &action, 0);

#if FOUNDATION_COMPILER_CLANG
#  pragma clang diagnostic pop
#endif
	}

#endif

#if FOUNDATION_PLATFORM_ANDROID
	if ((ret = android_initialize()) < 0)
		return ret;
#endif

#if FOUNDATION_PLATFORM_TIZEN
	if ((ret = tizen_initialize()) < 0)
		return ret;
#endif

#if FOUNDATION_PLATFORM_WINDOWS

	SetConsoleCtrlHandler(_main_console_handler, TRUE);

#endif

	thread_set_main();

	foundation_startup();

#if FOUNDATION_PLATFORM_WINDOWS || FOUNDATION_PLATFORM_LINUX || FOUNDATION_PLATFORM_PNACL
	system_post_event(FOUNDATIONEVENT_START);
#endif

#if FOUNDATION_PLATFORM_APPLE
#  if FOUNDATION_PLATFORM_MACOSX
	if (!(environment_application()->flags & APPLICATION_UTILITY)) {
		delegate_start_main_ns_thread();

		extern int NSApplicationMain(int argc, char* argv[]);
		ret = NSApplicationMain(argc, argv);

#  elif FOUNDATION_PLATFORM_IOS
	{
		delegate_start_main_ns_thread();

		extern int UIApplicationMain(int argc, char* argv[], void* principalClassName,
		                             void* delegateClassName);
		ret = UIApplicationMain(argc, (char**)argv, 0, 0);

#  endif
		//NSApplicationMain and UIApplicationMain never returns though
		return ret;
	}
#endif

#if !FOUNDATION_PLATFORM_IOS

#  if FOUNDATION_PLATFORM_TIZEN
	tizen_start_main_thread();
	ret = tizen_app_main(argc, argv);
#  else
	{
		string_t name;
		const application_t* app = environment_application();
		{
			string_const_t vstr = string_from_version_static(app->version);
			string_const_t aname = app->short_name;
			if (!aname.length)
				aname = string_const(STRING_CONST("unknown"));
			name = string_allocate_format(STRING_CONST("%.*s-%.*s"), (int)aname.length, aname.str,
			                              (int)vstr.length, vstr.str);
		}

		if (app->dump_callback)
			crash_guard_set(app->dump_callback, name.str, name.length);

		if (system_debugger_attached())
			ret = main_run(0);
		else
			ret = crash_guard(main_run, 0, app->dump_callback, name.str, name.length);

		string_deallocate(name.str);
	}
#  endif

	main_finalize();

#if FOUNDATION_PLATFORM_ANDROID
	android_finalize();
#endif

#if FOUNDATION_PLATFORM_TIZEN
	tizen_finalize();
#endif

	return ret;
#endif
}

#if FOUNDATION_PLATFORM_ANDROID

/*! Android native glue entry point */
void
android_main(struct android_app * app) {
	if (!app)
		return;
	android_entry(app);
	real_main();
}

#endif

#if FOUNDATION_PLATFORM_PNACL

/*! PNaCl glue entry points */
PP_EXPORT int32_t
PPP_InitializeModule(PP_Module module_id, PPB_GetInterface get_browser) {
	return pnacl_module_initialize(module_id, get_browser);
}

PP_EXPORT const void*
PPP_GetInterface(const char* interface_name) {
	return pnacl_module_interface(interface_name, string_length(interface_name));
}

PP_EXPORT void
PPP_ShutdownModule() {
	pnacl_module_finalize();
}
Beispiel #5
0
int macOSMain(int argc, char** argv, IApp* app)
{
	pApp = app;
	return NSApplicationMain(argc, argv);
}