Mercurial > remote-gamepad-server
comparison dspad.c @ 0:e70ea46d6073
Initial import from http://wouhanegaine.free.fr/dev/DSPad02b_neo07.zip
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 22 Feb 2015 01:38:06 +0100 |
parents | |
children | f362b20de51e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e70ea46d6073 |
---|---|
1 /* | |
2 DSPad | |
3 Convert Nintendo DS keypress into joystick events | |
4 */ | |
5 | |
6 #define __MAIN_FILE__ | |
7 | |
8 #include "ds.h" | |
9 #include "uinput.h" | |
10 #include "service.h" | |
11 #include "restartOp.h" | |
12 #include "XML.h" | |
13 | |
14 #include <stdio.h> | |
15 #include <stdint.h> | |
16 #include <sys/types.h> | |
17 #include <unistd.h> | |
18 #include <stdlib.h> | |
19 #include <sys/wait.h> | |
20 | |
21 | |
22 #define DEFAULT_PATH "~/DSPad_server.xml" | |
23 | |
24 | |
25 /* | |
26 Process xml atoms | |
27 */ | |
28 int dspad_process_xml(void* elem, char* tag, char* content){ | |
29 | |
30 (void)elem; | |
31 | |
32 if(tag != NULL && content != NULL){ | |
33 if(strcmp(content, "")){ | |
34 | |
35 /* process atom: */ | |
36 if(!strcmp(tag, "base_port")){ | |
37 base_port = atoi(content); | |
38 return 1; | |
39 } | |
40 | |
41 else if(!strcmp(tag, "uinput_dev")){ | |
42 if(uinput_dev != NULL) free(uinput_dev); | |
43 uinput_dev = (char*)malloc(strlen(content)+1); | |
44 strcpy(uinput_dev, content); | |
45 return 1; | |
46 } | |
47 | |
48 else if(!strcmp(tag, "nb_pad")){ | |
49 nbdev = atoi(content); | |
50 return 1; | |
51 } | |
52 | |
53 return ReadXML(elem, dspad_process_xml, content); | |
54 } | |
55 } | |
56 | |
57 /* Should not happend... (compiler warning) */ | |
58 return 0; | |
59 } | |
60 | |
61 | |
62 | |
63 /* | |
64 Read config file | |
65 returns 1 OK | |
66 0 error | |
67 */ | |
68 int config_read(char* path){ | |
69 int ok = 0; | |
70 char* text = NULL; | |
71 | |
72 text = LoadFile(path); | |
73 if(text){ | |
74 ok = ReadXML(NULL, dspad_process_xml, text); | |
75 free(text); | |
76 if(ok){ | |
77 fprintf(stderr, "Reading \"%s\" OK\n", path); | |
78 } | |
79 else{ | |
80 fprintf(stderr, "Reading \"%s\" FAILED\n", path); | |
81 } | |
82 } | |
83 return ok; | |
84 } | |
85 | |
86 | |
87 | |
88 | |
89 int main(int argc, char** argv){ | |
90 /* -- gcc -Werror satisfaction... -- */ | |
91 (void)argc; | |
92 (void)argv; | |
93 /* --------------------------------- */ | |
94 | |
95 curdev = 0; | |
96 | |
97 fprintf(stdout, "\n--- Starting DSPad Server v0.2 ---\n"); | |
98 | |
99 pid_t pid = 0; | |
100 | |
101 if(argc == 3 && !strcmp("-f", argv[1])){ | |
102 fprintf(stderr, "Loading \"%s\"\n", argv[2]); | |
103 config_read(argv[2]); | |
104 } | |
105 else{ | |
106 fprintf(stderr, "Loading \"%s\"\n", DEFAULT_PATH); | |
107 config_read(DEFAULT_PATH); | |
108 } | |
109 | |
110 | |
111 | |
112 /* fork servers */ | |
113 while(curdev < nbdev){ | |
114 pid = fork_rs(); | |
115 switch(pid){ | |
116 case 0: | |
117 curdev++; | |
118 // Wait 2 seconds before next because | |
119 // of kernel dev creation latency | |
120 sleep_rs(2); | |
121 break; | |
122 case -1: | |
123 fprintf(stderr, " [%d] Creation of service: failed\n", curdev); | |
124 exit(EXIT_FAILURE); | |
125 break; | |
126 default: | |
127 start_service(); | |
128 sleep(5); | |
129 fprintf(stdout, " [%d] Service finished\n", curdev); | |
130 waitpid(-1, NULL, 0); | |
131 exit(EXIT_SUCCESS); | |
132 break; | |
133 } /* switch */ | |
134 } | |
135 | |
136 return 0; | |
137 } | |
138 |