thermferm/server.c

changeset 240
6bdda35b4a13
parent 237
51a294d683cd
child 245
b01b6238eb67
equal deleted inserted replaced
239:793c09ece542 240:6bdda35b4a13
95 { 95 {
96 devices_list *device; 96 devices_list *device;
97 97
98 for (device = Config.devices; device; device = device->next) { 98 for (device = Config.devices; device; device = device->next) {
99 if (strcmp(device->uuid, uuid) == 0) { 99 if (strcmp(device->uuid, uuid) == 0) {
100 #ifdef HAVE_WIRINGPI_H
101 piLock(LOCK_DEVICES);
102 #endif
100 if (plus == TRUE) { 103 if (plus == TRUE) {
101 device->inuse++; 104 device->inuse++;
102 } else { 105 } else {
103 if (device->inuse) 106 if (device->inuse)
104 device->inuse--; 107 device->inuse--;
105 } 108 }
109 #ifdef HAVE_WIRINGPI_H
110 piUnlock(LOCK_DEVICES);
111 #endif
106 } 112 }
107 } 113 }
108 } 114 }
109 115
110 116
213 int cmd_device(char *buf) 219 int cmd_device(char *buf)
214 { 220 {
215 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE]; 221 char *opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
216 devices_list *device, *tmpd; 222 devices_list *device, *tmpd;
217 socklen_t fromlen; 223 socklen_t fromlen;
218 int i, rlen, ival; 224 int i, rc, rlen, ival;
219 uuid_t uu; 225 uuid_t uu;
220 226
221 opt = strtok(buf, " \0"); 227 opt = strtok(buf, " \0");
222 opt = strtok(NULL, " \0"); 228 opt = strtok(NULL, " \0");
223 229
263 device->address = xstrcpy((char *)"Enter address here"); 269 device->address = xstrcpy((char *)"Enter address here");
264 device->gpiopin = -1; 270 device->gpiopin = -1;
265 device->description = xstrcpy((char *)"Describe me here"); 271 device->description = xstrcpy((char *)"Describe me here");
266 device->comment = xstrcpy((char *)"Comment here"); 272 device->comment = xstrcpy((char *)"Comment here");
267 273
274 #ifdef HAVE_WIRINGPI_H
275 piLock(LOCK_DEVICES);
276 #endif
268 if (Config.devices == NULL) { 277 if (Config.devices == NULL) {
269 Config.devices = device; 278 Config.devices = device;
270 } else { 279 } else {
271 for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) { 280 for (tmpd = Config.devices; tmpd; tmpd = tmpd->next) {
272 if (tmpd->next == NULL) { 281 if (tmpd->next == NULL) {
273 tmpd->next = device; 282 tmpd->next = device;
274 break; 283 break;
275 } 284 }
276 } 285 }
277 } 286 }
287 #ifdef HAVE_WIRINGPI_H
288 piUnlock(LOCK_DEVICES);
289 #endif
278 syslog(LOG_NOTICE, "Device %s added", device->uuid); 290 syslog(LOG_NOTICE, "Device %s added", device->uuid);
279 srv_send((char *)"211 Device %s added", device->uuid); 291 srv_send((char *)"211 Device %s added", device->uuid);
280 return 0; 292 return 0;
281 293
282 } else { 294 } else {
285 } 297 }
286 } 298 }
287 299
288 if (strcmp(opt, (char *)"DEL") == 0) { 300 if (strcmp(opt, (char *)"DEL") == 0) {
289 301
290 if (delete_Device(param)) { 302 #ifdef HAVE_WIRINGPI_H
303 piLock(LOCK_DEVICES);
304 #endif
305 rc = delete_Device(param);
306 #ifdef HAVE_WIRINGPI_H
307 piUnlock(LOCK_DEVICES);
308 #endif
309 if (rc) {
291 syslog(LOG_NOTICE, "Device %s deleted", param); 310 syslog(LOG_NOTICE, "Device %s deleted", param);
292 srv_send((char *)"211 Device %s deleted", param); 311 srv_send((char *)"211 Device %s deleted", param);
293 return 0; 312 return 0;
294 } else { 313 } else {
295 srv_send((char *)"440 No such device"); 314 srv_send((char *)"440 No such device");

mercurial