File: main.cpp

package info (click to toggle)
qbble 1.2-10
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 108 kB
  • ctags: 143
  • sloc: cpp: 735; ansic: 138; makefile: 50
file content (93 lines) | stat: -rw-r--r-- 1,828 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "mainWindow.h"

#include <qapplication.h>
#include <xmms/plugin.h>
#include <cstdio>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>      
#include <signal.h>
#include <error.h>
#include <errno.h>
#include <signal.h>
#include <iostream>
using namespace std;

extern int errno;
extern const char * const sys_siglist[]; 
static int child_pid;

void signal_handler(int signo)
{
	cout << "Child caught " << sys_siglist[signo] << endl;
	cout << "Exiting child ... " << endl;
	exit(1);
}

extern "C" void init()
{
	// fork, otherwise we block in a.exec()
	child_pid = fork();
	if (!child_pid)
	{
		// child
		signal(SIGSEGV, signal_handler);
		signal(SIGPIPE, signal_handler);
		
		int argc = 0;
		char *argv[] = { "qbble" };
		QApplication a(argc, argv);
		mainWindow * mw = new mainWindow();
		mw->setCaption( "Qbble" );
		mw->show();
		a.connect( &a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()) );
		a.exec();
		
		cout << "Child exiting of its own accord" << endl;
		exit(1);
		// TODO: notify XMMS here that the plugin is gone.
	}
	else
	{
		// parent
		cout << "Started qbble plugin" << endl;
	}
}

extern "C" void cleanup()
{
	cout << "Cleaning up" << endl;
	int status;
	if (!child_pid)
	{
		cout << "We got asked to cleanup something nonexistent" << endl;
	}
	else if (kill(child_pid, SIGINT) < 0)
	{
		cout << "While attempting to kill Qbble, " << strerror(errno) << endl;
	}
	else if (wait(&status) < 0)
	{
		cout << "While reaping Qbble child process, " << strerror(errno) << endl;
	}
	child_pid = 0;
}

GeneralPlugin qbble_gp =
{
    NULL,           /* handle */
    NULL,           /* filename */
    -1,         	/* xmms_session */
    "Qbble 1.1",    /* Description */
    init,
    NULL,
    NULL,
    cleanup,
};

extern "C" GeneralPlugin *get_gplugin_info(void)
{
	return &qbble_gp;
}