예제 #1
0
int main(int argc, char **argv)
{
	GOptionContext *context;
	GError *err = NULL;
	guint signal;
	struct telephony_service *telservice;
	struct wan_service *wanservice;

	g_type_init();

	g_log_set_handler (NULL, G_LOG_LEVEL_MASK, log_handler, NULL);

	g_message("Telephony Interface Layer Daemon %s", VERSION);

	context = g_option_context_new(NULL);
	g_option_context_add_main_entries(context, options, NULL);

	if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
		if (err != NULL) {
			g_printerr("%s\n", err->message);
			g_error_free(err);
			exit(1);
		}

		g_printerr("An unknown error occurred\n");
		exit(1);
	}

	g_option_context_free(context);

	if (option_version == TRUE) {
		printf("%s\n", VERSION);
		exit(0);
	}

	if (option_detach == TRUE) {
		if (daemon(0, 0)) {
			perror("Can't start daemon");
			return 1;
		}
	}

	signal = setup_signalfd();

	event_loop = g_main_loop_new(NULL, FALSE);

	ofono_init();

	telservice = telephony_service_create();
	wanservice = wan_service_create();

	if(telservice && wanservice) {
		g_main_loop_run(event_loop);
	}

	g_message("Cleaning up");

	if(wanservice)
		wan_service_free(wanservice);
	if(telservice)
		telephony_service_free(telservice);

	ofono_exit();

	g_source_remove(signal);

	g_main_loop_unref(event_loop);

	return 0;
}
예제 #2
0
int main(int argc, char **argv)
{
	GOptionContext *context;
	LSError lserror;
	GError *err = NULL;
	guint signal;
	struct telephony_service *service;

	g_message("Telephony Interface Layer Daemon %s", VERSION);

	g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, debug_handler, NULL);

	context = g_option_context_new(NULL);
	g_option_context_add_main_entries(context, options, NULL);

	if (g_option_context_parse(context, &argc, &argv, &err) == FALSE) {
		if (err != NULL) {
			g_printerr("%s\n", err->message);
			g_error_free(err);
			exit(1);
		}

		g_printerr("An unknown error occurred\n");
		exit(1);
	}

	g_option_context_free(context);

	if (option_version == TRUE) {
		printf("%s\n", VERSION);
		exit(0);
	}

	if (option_detach == TRUE) {
		if (daemon(0, 0)) {
			perror("Can't start daemon");
			return 1;
		}
	}

	signal = setup_signalfd();

	event_loop = g_main_loop_new(NULL, FALSE);

	LSErrorInit(&lserror);

	if (!LSRegisterPalmService("com.palm.telephony", &palm_serivce_handle, &lserror)) {
		g_error("Failed to initialize the Luna Palm service: %s", lserror.message);
		LSErrorFree(&lserror);
		goto cleanup;
	}

	if (!LSGmainAttachPalmService(palm_serivce_handle, event_loop, &lserror)) {
		g_error("Failed to attach to glib mainloop for palm service: %s", lserror.message);
		LSErrorFree(&lserror);
		goto cleanup;
	}

	private_service_handle = LSPalmServiceGetPrivateConnection(palm_serivce_handle);

	service = telephony_service_create(palm_serivce_handle);
	/* FIXME this should be done as part of a plugin mechanism */
	ofono_init(service);

	g_main_loop_run(event_loop);

cleanup:
	/* FIXME this should be done as part of a plugin mechanism */
	ofono_exit(service);

	telephony_service_free(service);

	if (palm_serivce_handle != NULL && LSUnregisterPalmService(palm_serivce_handle, &lserror) < 0) {
		g_error("Could not unregister palm service: %s", lserror.message);
		LSErrorFree(&lserror);
	}

	g_source_remove(signal);

	g_main_loop_unref(event_loop);

	return 0;
}