Mercurial > remote-gamepad-server
comparison service.c @ 2:f362b20de51e
Remove trailing whitespaces.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 22 Feb 2015 18:03:26 +0100 |
parents | e70ea46d6073 |
children | eafcd170dc6d |
comparison
equal
deleted
inserted
replaced
1:05c8e0aef77d | 2:f362b20de51e |
---|---|
65 Returns size read or -1 | 65 Returns size read or -1 |
66 */ | 66 */ |
67 ssize_t receive_ds_info(int socket, ds_t* ds){ | 67 ssize_t receive_ds_info(int socket, ds_t* ds){ |
68 struct sockaddr_in add; | 68 struct sockaddr_in add; |
69 socklen_t l = sizeof(struct sockaddr_in); | 69 socklen_t l = sizeof(struct sockaddr_in); |
70 | 70 |
71 ssize_t result; | 71 ssize_t result; |
72 | 72 |
73 result = recvfrom_rs(socket, ds, sizeof(ds_t), 0, (struct sockaddr*)&add, &l); | 73 result = recvfrom_rs(socket, ds, sizeof(ds_t), 0, (struct sockaddr*)&add, &l); |
74 if(result == -1) perror("recvfrom_rs"); | 74 if(result == -1) perror("recvfrom_rs"); |
75 return result; | 75 return result; |
76 } | 76 } |
77 | 77 |
82 void start_service(void){ | 82 void start_service(void){ |
83 | 83 |
84 int uinput_fd; | 84 int uinput_fd; |
85 int sock_fd; | 85 int sock_fd; |
86 uint16_t udp_port = base_port + curdev; | 86 uint16_t udp_port = base_port + curdev; |
87 | 87 |
88 ds_t ds; | 88 ds_t ds; |
89 ssize_t result; | 89 ssize_t result; |
90 | 90 |
91 | 91 |
92 fprintf(stdout, " [%d] Creation of service:\n", curdev); | 92 fprintf(stdout, " [%d] Creation of service:\n", curdev); |
96 if(uinput_fd == -1){ | 96 if(uinput_fd == -1){ |
97 fprintf(stderr, " [%d] Joystick device failed\n", curdev); | 97 fprintf(stderr, " [%d] Joystick device failed\n", curdev); |
98 exit(EXIT_FAILURE); | 98 exit(EXIT_FAILURE); |
99 } | 99 } |
100 fprintf(stdout, " [%d] Joystick device OK\n", curdev); | 100 fprintf(stdout, " [%d] Joystick device OK\n", curdev); |
101 | 101 |
102 | 102 |
103 // Create udp socket | 103 // Create udp socket |
104 sock_fd = create_socket(&udp_port, SOCK_DGRAM); | 104 sock_fd = create_socket(&udp_port, SOCK_DGRAM); |
105 if(sock_fd == -1){ | 105 if(sock_fd == -1){ |
106 fprintf(stderr, " [%d] Socket failed\n", curdev); | 106 fprintf(stderr, " [%d] Socket failed\n", curdev); |
107 exit(EXIT_FAILURE); | 107 exit(EXIT_FAILURE); |
108 } | 108 } |
109 fprintf(stdout, " [%d] Socket on port %d OK\n", curdev, udp_port); | 109 fprintf(stdout, " [%d] Socket on port %d OK\n", curdev, udp_port); |
110 | 110 |
111 | 111 |
112 // Device and Socket are ok :-D | 112 // Device and Socket are ok :-D |
113 fprintf(stdout, " [%d] Creation of service: OK\n", curdev); | 113 fprintf(stdout, " [%d] Creation of service: OK\n", curdev); |
114 | 114 |
115 | 115 |
116 /* Center device axis when created */ | 116 /* Center device axis when created */ |
118 do_uinput(uinput_fd, ABS_X, DS_MAX_X/2, EV_ABS); | 118 do_uinput(uinput_fd, ABS_X, DS_MAX_X/2, EV_ABS); |
119 | 119 |
120 while(1){ | 120 while(1){ |
121 result = receive_ds_info(sock_fd, &ds); | 121 result = receive_ds_info(sock_fd, &ds); |
122 if(result == -1){ | 122 if(result == -1){ |
123 fprintf(stderr, " [%d] DS Info receive failed\n", curdev); | 123 fprintf(stderr, " [%d] DS Info receive failed\n", curdev); |
124 } | 124 } |
125 if(result > 0){ | 125 if(result > 0){ |
126 ds_process_evt(&ds, uinput_fd); | 126 ds_process_evt(&ds, uinput_fd); |
127 } | 127 } |
128 } | 128 } |