main.c

The main application for a simple window manager.

/*
 * $QNXLicenseC:
 * Copyright 2012, QNX Software Systems Limited. All Rights Reserved.
 *
 * This software is QNX Confidential Information subject to
 * confidentiality restrictions. DISCLOSURE OF THIS SOFTWARE
 * IS PROHIBITED UNLESS AUTHORIZED BY QNX SOFTWARE SYSTEMS IN
 * WRITING.
 *
 * You must obtain a written license from and pay applicable license
 * fees to QNX Software Systems Limited before you may reproduce, modify
 * or distribute this software, or any work that includes all or part
 * of this software. For more information visit
 * http://licensing.qnx.com or email licensing@qnx.com.
 *
 * This file may contain contributions from others.  Please review
 * this entire file for other proprietary rights or license notices,
 * as well as the QNX Development Suite License Guide at
 * http://licensing.qnx.com/license-guide/ for other information.
 * $
 */

#include "struct.h"

static void main_setup_default(window_manager_t *winmgr){
	winmgr->background = 1;
	winmgr->pps_fd = -1;
	winmgr->state = WINMGR_UPDATE;
	winmgr->verbose = 1;

	winmgr->car_app.id = strdup("100");
	winmgr->car_app.data = strdup("carcontrol.testDev_carcontrol_21522f09,\
	                               WIDTH=800,HEIGHT=395");

	winmgr->weather_app.id = strdup("101");
	winmgr->weather_app.data = strdup("sys.browser.gYABgJYFHAzbeFMPCCpYWBtHAm0,\
	                                   WIDTH=800,HEIGHT=395");

	winmgr->screen_tid = -1;

}

int main(int argc, char **argv)
{
	int rc;

	window_manager_t window_manager;
	memset(&window_manager, 0, sizeof(window_manager_t));
	window_manager_t *winmgr = &window_manager;
	main_setup_default(winmgr);

	rc = screen_init(winmgr, argc, argv);
	if (rc != EOK){
		exit(EXIT_FAILURE);
	}

	// create a pps thread and here
	if (pthread_create(NULL, NULL, pps_thread, (void*)winmgr) < 0) {
		SLOG_ERROR("Failed to create a pps thread (%d:%s)", errno, strerror(errno));
	}

	if (pthread_create(NULL, NULL, screen_thread, (void*)winmgr) < 0) {
		SLOG_ERROR("Failed to create a screen thread (%d:%s)", errno, strerror(errno));
	}

	// launcher apps
	while(winmgr->pps_fd == -1){
		sleep(1);
	}
	launcher_send(winmgr, CMD_START, winmgr->car_app.data, winmgr->car_app.id);
	launcher_send(winmgr, CMD_START, winmgr->weather_app.data, winmgr->weather_app.id);

	sleep(30);
	launcher_send(winmgr, CMD_STOP, "", "");

	sleep(5);

	// create a self_detached thread
	pthread_cancel(winmgr->pps_tid);
	pthread_cancel(winmgr->screen_tid);

	return EXIT_SUCCESS;
}