File: test-processrunner.cc

package info (click to toggle)
guessnet 0.35-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,564 kB
  • ctags: 1,447
  • sloc: cpp: 6,188; sh: 1,009; perl: 118; makefile: 105
file content (59 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
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
#include "Environment.h"
#include "ProcessRunner.h"

#include <stdio.h>

#define DEBUG(args...) fprintf(stderr, ##args)
//#define DEBUG(args...) do {} while(0)


class ProcessPrinter : public ProcessListener
{
public:
	virtual void handleTermination(const std::string& tag, int status) throw ()
	{
		printf("%.*s: terminated with status %d\n", PFSTR(tag), status);
	}
};


int main(int argc, char* argv[])
{
	try {
		InstallUnexpected installUnexpected;

		Environment::get().debug(true);

		{
			fprintf(stderr, "\t\tInitializing process runner...\n");
			ProcessRunner pr;
			fprintf(stderr, "\t\tInitialized process runner...\n");
		}

		fprintf(stderr, "\t\tReinitializing process runner...\n");
		ProcessPrinter pp;
		ProcessRunner pr;

		fprintf(stderr, "\t\tAdding processes...\n");
		pr.addProcess("test1", "sleep 1", &pp);
		pr.addProcess("test2", "sleep 2", &pp);
		pr.addProcess("test2a", "sleep 2", &pp);
		pr.addProcess("test0", "true", &pp);
		pr.addProcess("test3", "false", &pp);
		pr.addProcess("test2b", "sleep 2", &pp);
		pr.addProcess("test1a", "sleep 1", &pp);

		fprintf(stderr, "\t\tSleeping...\n");
		sleep(2);
		fprintf(stderr, "\t\tShutting down...\n");
		pr.shutdown();

		fprintf(stderr, "\t\tDone.\n");
	}
	catch (Exception& e)
	{
		error("%s: %.*s\n", e.type(), PFSTR(e.desc()));
		return 1;
	}
	return 0;
}