bcap_server.c
Go to the documentation of this file.
1 
25 #include "stdint.h"
26 #include <stdlib.h>
27 #include <string.h>
28 
29 #if defined(_USE_WIN_API)
30 #include <process.h>
31 #include <winsock2.h>
32 #pragma comment(lib, "wsock32.lib")
33 #elif defined(_USE_LINUX_API)
34 #include <arpa/inet.h>
35 #include <errno.h>
36 #include <pthread.h>
37 #include <termios.h>
38 #else
39 #include "dn_additional.h"
40 #endif
41 
42 #include "dn_common.h"
43 #include "dn_device.h"
44 #include "dn_tcp.h"
45 #include "dn_udp.h"
46 #include "dn_com.h"
47 #include "dn_thread.h"
48 #include "bcap_common.h"
49 #include "bcap_mapid.h"
50 #include "bcap_server.h"
51 
56 #define _BCAP_SERVER_MAX (BCAP_TCP_MAX + BCAP_UDP_MAX + BCAP_COM_MAX)
57 
62 #define _FUNCTION_ID_MAX (137 + 1)
63 
69 {
73 };
74 
79 struct VEC_OBJECT
80 {
83  struct VEC_OBJECT *prev;
84  struct VEC_OBJECT *next;
85 };
86 
92 {
93  struct CONN_PARAM_COMMON device;
94  struct BCAP_PACKET last_send;
95  struct BCAP_PACKET last_recv;
106  struct VEC_OBJECT *stack;
107  int num_child;
112 };
113 
116 
117 static THRET THTYPE
118 recv_thread(void *arg);
119 
126 static int
128 {
129  int i, start, end, index = -1;
130 
131  switch(type) {
132  case CONN_TCP:
133  start = 0;
134  end = BCAP_TCP_MAX;
135  break;
136  case CONN_UDP:
137  start = BCAP_TCP_MAX;
138  end = start + BCAP_UDP_MAX;
139  break;
140  case CONN_COM:
141  start = BCAP_TCP_MAX + BCAP_UDP_MAX;
142  end = start + BCAP_COM_MAX;
143  break;
144  default:
145  return 0;
146  }
147 
148  for(i = start; i < end; i++) {
149  if(m_conn_param[i].device.sock == 0) {
150  index = i;
151  break;
152  }
153  }
154 
155  return (index + 1);
156 }
157 
164 static struct CONN_BCAP_SERVER*
165 check_address(int index)
166 {
167  index--;
168 
169  if(index < 0 || _BCAP_SERVER_MAX <= index) {
170  return NULL;
171  }
172  else if(m_conn_param[index].device.sock == 0) {
173  return NULL;
174  }
175 
176  return &m_conn_param[index];
177 }
178 
185 static HRESULT
186 push_vector(struct CONN_BCAP_SERVER *bcap_param, struct VEC_OBJECT *pObj)
187 {
188  struct VEC_OBJECT *pPrev;
189 
190  if(bcap_param->num_object >= BCAP_OBJECT_MAX) {
191  return E_MAX_OBJECT;
192  }
193 
194  /* Replaces the created object to top of vector */
195  pPrev = bcap_param->stack;
196  bcap_param->stack = pObj;
197 
198  /* Sets relation */
199  pObj->prev = pPrev;
200  if(pPrev != NULL) {
201  pPrev->next = pObj;
202  }
203 
204  bcap_param->num_object++;
205 
206  return S_OK;
207 }
208 
216 static HRESULT
217 pop_vector(struct CONN_BCAP_SERVER *bcap_param, struct VEC_OBJECT **pObj,
218  int index)
219 {
220  int i;
221  struct VEC_OBJECT *pPrev, *pNext, *pCur = bcap_param->stack;
222  HRESULT hr = E_HANDLE;
223 
224  for(i = 0; (i < bcap_param->num_object) && (pCur); i++) {
225  if(i == index) {
226  *pObj = pCur;
227 
228  /* Gets the object which is later than the poped one */
229  pNext = pCur->next;
230  pCur->next = NULL;
231 
232  /* Gets the object which is earlier than the poped one */
233  pPrev = pCur->prev;
234  pCur->prev = NULL;
235 
236  if(pNext == NULL) { // If the target object is the latest one
237  bcap_param->stack = pPrev;
238  } else {
239  pNext->prev = pPrev;
240  }
241 
242  if(pPrev != NULL) { // If the target object is not the earliest one
243  pPrev->next = pNext;
244  }
245 
246  bcap_param->num_object--;
247  hr = S_OK;
248  break;
249  }
250 
251  pCur = pCur->prev;
252  }
253 
254  return hr;
255 }
256 
265 static int
267 {
268  int i, index = -1;
269  struct VEC_OBJECT *pCur = bcap_param->stack;
270 
271  for(i = 0; (i < bcap_param->num_object) && (pCur); i++) {
272  if((pCur->id == id) && (pCur->hObj == hObj)) {
273  index = i;
274  break;
275  }
276 
277  pCur = pCur->prev;
278  }
279 
280  return index;
281 }
282 
290 static struct CONN_BCAP_SERVER *
291 search_node(struct CONN_BCAP_SERVER *parent, const void *arg, int size)
292 {
293  struct CONN_BCAP_SERVER *node = NULL, *tmp;
294 
295  tmp = parent->node1;
296  while(tmp != NULL) {
297  if(memcmp(tmp->device.arg, arg, size) == 0) {
298  node = tmp;
299  break;
300  }
301  tmp = tmp->node2;
302  }
303 
304  return node;
305 }
306 
314 static HRESULT
315 change_relation(struct CONN_BCAP_SERVER *own, int mode, int *sock)
316 {
317  HRESULT hr = S_OK;
318  struct CONN_BCAP_SERVER *node, *tmp;
319  int flag_mutex;
320  MUTEX *mutex;
321 
322  /* Checks mutex object */
323  mutex = own->relation_mutex;
324  flag_mutex = ((mutex != NULL) ? 1 : 0);
325 
326  /* Locks mutex and must not returns this function without end of one. */
327  if(flag_mutex) {
328  hr = lock_mutex(mutex, INFINITE);
329  if(FAILED(hr)) return hr;
330  }
331 
332  switch(mode) {
333  case ADD_CHILD:
334  /* Root node only */
335  if(own->parent == NULL) {
336  /* Creates new node */
337  node = (struct CONN_BCAP_SERVER *) malloc(
338  sizeof(struct CONN_BCAP_SERVER));
339  if(node == NULL) {
340  hr = E_OUTOFMEMORY;
341  goto exit_proc;
342  }
343 
344  /* Initializes node memory */
345  memset(node, 0, sizeof(struct CONN_BCAP_SERVER));
346 
347  /* Copies device parameters from parent node */
348  node->device = own->device;
349 
350  /* Sets child socket */
351  node->device.sock = *sock;
352 
353  /* Copies parameters */
354  node->exec_timeout = own->exec_timeout;
355  node->wdt_interval = own->wdt_interval;
356 
357  /* Sets last modified */
359 
360  /* Copies mutex */
361  node->relation_mutex = own->relation_mutex;
362 
363  /* Sets parent node */
364  node->parent = own;
365  own->num_child++;
366 
367  /* Replaces the head of children */
368  tmp = own->node1;
369  own->node1 = node;
370  node->node2 = tmp;
371  if(tmp != NULL) tmp->node1 = node;
372 
373  if(flag_mutex) {
374  hr = node->device.dn_set_timeout(*sock, node->device.timeout);
375  if(FAILED(hr)) {
376  node->device.dn_close(sock);
377  free(node);
378  goto exit_proc;
379  }
380 
381  /* Creates terminal event for main thread */
382  hr = create_event(&node->term_main_evt, 1, 0);
383  if(FAILED(hr)) {
384  node->device.dn_close(sock);
385  free(node);
386  goto exit_proc;
387  }
388 
389  /* Begins child thread */
390  begin_thread(&node->main_thread, &recv_thread, node);
391  } else {
392  switch(node->device.type) {
393  case CONN_UDP:
394  node->device.arg = malloc(sizeof(struct sockaddr_in));
395  memcpy(node->device.arg, own->device.arg, sizeof(struct sockaddr_in));
396  break;
397  default:
398  break;
399  }
400 
401  node->last_send.args =
402  (VARIANT*) malloc(sizeof(VARIANT));
403  VariantInit(node->last_send.args);
404  }
405  }
406  break;
407 
408  case DELETE_CHILD:
409  /* Root node only */
410  if(own->parent == NULL) {
411  node = own->node2;
412  while (node != NULL) {
413  tmp = node->node2;
414 
415  if(flag_mutex) {
416  /* Ends child thread */
417  set_event(&node->term_main_evt);
418  exit_thread(node->main_thread);
419 
420  /* Destroys event */
422 
423  /* Closes connection */
424  node->device.dn_close(&node->device.sock);
425  } else {
426  VariantClear(node->last_send.args);
427  free(node->last_send.args);
428 
429  if(node->device.arg != NULL) {
430  free(node->device.arg);
431  }
432  }
433 
434  free(node);
435  node = tmp;
436 
437  own->num_child--;
438  }
439  own->node2 = NULL;
440  }
441  break;
442 
443  case DESTROY_SELF:
444  if(own->parent != NULL) {
445  /* Removes own node from the children list */
446  tmp = own->node1;
447 
448  if(tmp == NULL) { // If own node is the youngest children
449  own->parent->node1 = own->node2;
450  } else {
451  tmp->node2 = own->node2;
452  }
453 
454  if(own->node2 != NULL) { // If own node is not the oldest children
455  own->node2->node1 = tmp;
456  }
457 
458  /* Adds own node to the parent's delete */
459  tmp = own->parent->node2;
460  own->parent->node2 = own;
461  own->node2 = tmp;
462  if(tmp != NULL) tmp->node1 = own;
463  } else {
464  if(!flag_mutex) {
465  node = own->node1;
466  while(node != NULL) {
467  tmp = node->node2;
468  change_relation(node, DESTROY_SELF, NULL);
469  node = tmp;
470  }
471  change_relation(own, DELETE_CHILD, NULL);
472  }
473  }
474  break;
475 
476  default:
477  hr = E_INVALIDARG;
478  break;
479  }
480 
481 exit_proc:
482  if(flag_mutex) {
483  unlock_mutex(mutex);
484  }
485 
486  return hr;
487 }
488 
494 static int
496 {
497  uint32_t cur, diff;
498  struct CONN_BCAP_SERVER *child, *tmp;
499 
500  child = parent->node1;
501  while(child != NULL) {
502  tmp = child->node2;
503 
504  cur = gettimeofday_msec();
505  diff = calc_time_diff(child->last_modified, cur);
506  if(diff > UDP_LIFELIMIT) {
507  change_relation(child, DESTROY_SELF, NULL);
508  }
509 
510  child = tmp;
511  }
512 
513  change_relation(parent, DELETE_CHILD, NULL);
514 
515  return parent->num_child;
516 }
517 
524 static HRESULT
525 bcap_callfunc(struct BCAP_PACKET *recv_packet, struct BCAP_PACKET *send_packet)
526 {
527  int32_t id;
528  CALL_FUNC_BCAP func;
529 
530  /* Initializes send packet */
531  send_packet->serial = recv_packet->serial;
532  send_packet->reserv = 0;
533  send_packet->id = E_INVALIDARG;
534  send_packet->argc = 0;
535 
536  id = recv_packet->id;
537  if((0 < id) && (id < _FUNCTION_ID_MAX)) {
538  func = m_list_func[id];
539  if(func == NULL) {
540  /* The function is not implemented */
541  send_packet->id = E_NOTIMPL;
542  } else {
543  /* callback function */
544  VariantClear(send_packet->args);
545  send_packet->id = func(recv_packet->args, recv_packet->argc,
546  send_packet->args);
547  send_packet->argc = m_map_id[id].return_flag ? 1 : 0;
548  }
549  }
550 
551  return S_OK;
552 }
553 
559 static HRESULT
561 {
562  int index;
563  int32_t relation_id;
564  uint16_t i, clear_flag = 1;
565  uint32_t cur, start, diff;
566  HRESULT hr;
567  struct CONN_BCAP_SERVER *tmp_param = bcap_param;
568  struct CONN_PARAM_COMMON *device = &bcap_param->device;
569  struct BCAP_PACKET tmp_send_packet, tmp_recv_packet, *send_packet =
570  &bcap_param->last_send, *recv_packet = &bcap_param->last_recv;
571  struct VEC_OBJECT *pObj = NULL;
572  BSTR bstrOpt = NULL;
573  VARIANT vntTmp, vntOpt;
574 
575  VariantInit(&vntTmp);
576  VariantInit(&vntOpt);
577 
578  /* Initializes temporary packet */
579  tmp_recv_packet.argc = (uint16_t) -1;
580  tmp_recv_packet.args = NULL;
581 
582  /* Receives b-CAP packet */
583  hr = bcap_recv(device, &tmp_recv_packet, 0);
584 
585  if(SUCCEEDED(hr)) {
586  /* Sets S_EXECUTING packet */
587  memset(&tmp_send_packet, 0, sizeof(struct BCAP_PACKET));
588  tmp_send_packet.serial = tmp_recv_packet.serial;
589  tmp_send_packet.id = S_EXECUTING;
590 
591  /* Checks retry packet */
592  switch(device->type) {
593  case CONN_UDP:
594  tmp_param = search_node(bcap_param, device->arg,
595  sizeof(struct sockaddr_in));
596  if(tmp_param == NULL) {
597  /* Checks life limit */
598  if((bcap_param->num_child >= BCAP_CLIENT_MAX)
599  && (check_lifelimit(bcap_param) >= BCAP_CLIENT_MAX))
600  {
601  tmp_send_packet.id = E_MAX_CONNECT;
602  bcap_send(device, &tmp_send_packet);
603  hr = S_FALSE;
604  goto exit_proc;
605  }
606 
607  /* Adds child */
608  change_relation(bcap_param, ADD_CHILD, &device->sock);
609  tmp_param = bcap_param->node1;
610  }
611 
612  send_packet = &tmp_param->last_send;
613 
614  //break;
615 
616  case CONN_COM:
617  /* Sets retry count */
618  tmp_recv_packet.reserv =
619  (tmp_recv_packet.reserv == 0) ?
620  tmp_recv_packet.serial : tmp_recv_packet.reserv;
621 
622  /* If already responded, then does not execute */
623  if(send_packet->serial == tmp_recv_packet.reserv) {
624  /* Copies last send packet */
625  tmp_send_packet = *send_packet;
626 
627  /* Sets new serial number */
628  tmp_send_packet.serial = tmp_recv_packet.serial;
629 
630  /* Sends temporary send packet */
631  bcap_send(device, &tmp_send_packet);
632  hr = S_FALSE;
633  goto exit_proc;
634  }
635 
636  break;
637 
638  default:
639  break;
640  }
641 
642  /* Checks execute thread */
643  hr = wait_event(&bcap_param->comp_evt, 0);
644  if(hr == E_TIMEOUT) {
645  /* Sends result busy process */
646  tmp_send_packet.id = E_BUSY_PROC;
647  bcap_send(device, &tmp_send_packet);
648  goto exit_proc;
649  }
650 
651  switch(tmp_recv_packet.id) {
652  case ID_SERVICE_START:
656  case ID_FILE_GETFILE:
661  case ID_FILE_GETVARIABLE:
663  case ID_TASK_GETVARIABLE:
666  if(bcap_param->num_object >= BCAP_OBJECT_MAX) {
667  tmp_send_packet.id = E_MAX_OBJECT;
668  bcap_send(device, &tmp_send_packet);
669  hr = S_FALSE;
670  goto exit_proc;
671  }
672 
673  if(tmp_recv_packet.id == ID_SERVICE_START) {
674  if((tmp_recv_packet.argc >= 1) && (tmp_recv_packet.args != NULL)) {
675  VariantCopy(&vntTmp, &tmp_recv_packet.args[0]);
676  hr = VariantChangeType(&vntTmp, &vntTmp, 0, VT_BSTR);
677  if(FAILED(hr)) {
678  tmp_send_packet.id = hr;
679  bcap_send(device, &tmp_send_packet);
680  hr = S_FALSE;
681  goto exit_proc;
682  }
683  } else {
684  vntTmp.vt = VT_BSTR;
685  vntTmp.bstrVal = SysAllocString(L"");
686  }
687 
688  bstrOpt = SysAllocString(L"WDT");
689  hr = GetOptionValue(vntTmp.bstrVal, bstrOpt, VT_UI4, &vntOpt);
690  vntOpt.ulVal =
691  (vntOpt.vt == VT_UI4) ? vntOpt.ulVal : INIT_WDT_INTERVAL;
692  if(vntOpt.ulVal < MIN_WDT_INTERVAL) {
693  tmp_send_packet.id = E_INVALIDARG;
694  bcap_send(device, &tmp_send_packet);
695  hr = S_FALSE;
696  goto exit_proc;
697  } else {
698  tmp_param->wdt_interval = vntOpt.ulVal;
699  }
700  SysFreeString(bstrOpt);
701  VariantClear(&vntOpt);
702 
703  bstrOpt = SysAllocString(L"InvokeTimeout");
704  hr = GetOptionValue(vntTmp.bstrVal, bstrOpt, VT_UI4, &vntOpt);
705  vntOpt.ulVal =
706  (vntOpt.vt == VT_UI4) ? vntOpt.ulVal : INIT_EXEC_TIMEOUT;
707  if(vntOpt.ulVal < MIN_WDT_INTERVAL) {
708  tmp_send_packet.id = E_INVALIDARG;
709  bcap_send(device, &tmp_send_packet);
710  hr = S_FALSE;
711  goto exit_proc;
712  } else {
713  tmp_param->exec_timeout = vntOpt.ulVal;
714  }
715  SysFreeString(bstrOpt);
716  VariantClear(&vntOpt);
717 
718  VariantClear(&vntTmp);
719  bstrOpt = NULL;
720  }
721 
722  break;
723 
724  default:
725  break;
726  }
727 
728  /* Resets last received packet */
729  if(recv_packet->args != NULL) {
730  for(i = 0; i < recv_packet->argc; i++) {
731  VariantClear(&recv_packet->args[i]);
732  }
733  free(recv_packet->args);
734  }
735 
736  /* Copies to last receive packet */
737  clear_flag = 0;
738  *recv_packet = tmp_recv_packet;
739 
740  /* Runs execute thread */
741  reset_event(&bcap_param->comp_evt);
742  set_event(&bcap_param->exec_evt);
743 
744  if(SUCCEEDED(hr)) {
745  start = gettimeofday_msec();
746  while(1) {
747  hr = wait_event(&bcap_param->comp_evt, tmp_param->wdt_interval);
748  if(SUCCEEDED(hr)) {
749  break;
750  } else {
751  /* Sends S_EXECUTING packet */
752  hr = bcap_send(device, &tmp_send_packet);
753  if(FAILED(hr)) {
754  break;
755  }
756  }
757 
758  /* Checks executing timeout */
759  cur = gettimeofday_msec();
760  diff = calc_time_diff(start, cur);
761  if(diff > tmp_param->exec_timeout) {
762  hr = E_TIMEOUT;
763  break;
764  }
765  }
766  }
767  }
768 
769 exit_proc:
770  if(hr == S_OK) {
771  if(bcap_param->last_send.id == S_OK) {
772  /* Changes the vector of created objects */
773  relation_id = m_map_id[recv_packet->id].relation_id;
774  if(relation_id > 0) { // Push
775  pObj = (struct VEC_OBJECT *) malloc(sizeof(struct VEC_OBJECT));
776  if(pObj != NULL) {
777  memset(pObj, 0, sizeof(struct VEC_OBJECT));
778  pObj->id = relation_id;
779  pObj->hObj =
780  (recv_packet->id == ID_SERVICE_START) ?
781  0 : bcap_param->last_send.args[0].lVal;
782  push_vector(bcap_param, pObj);
783  }
784  }
785  else if(relation_id < 0) { // Pop
786  index = search_vector(bcap_param, recv_packet->id,
787  (recv_packet->id == ID_SERVICE_STOP) ?
788  0 : recv_packet->args[0].lVal);
789  if(index >= 0) {
790  pop_vector(bcap_param, &pObj, index);
791  free(pObj);
792  }
793  if((device->type == CONN_UDP)
794  && (recv_packet->id == ID_SERVICE_STOP))
795  {
796  change_relation(tmp_param, DESTROY_SELF, NULL);
797  change_relation(bcap_param, DELETE_CHILD, NULL);
798  tmp_param = NULL;
799  }
800  }
801  }
802 
803  /* Responds the result message */
804  hr = bcap_send(device, &bcap_param->last_send);
805  if(SUCCEEDED(hr) && (tmp_param != NULL)) {
806  tmp_param->last_send.serial = bcap_param->last_send.serial;
807  tmp_param->last_send.reserv = bcap_param->last_send.reserv;
808  tmp_param->last_send.id = bcap_param->last_send.id;
809  tmp_param->last_send.argc = bcap_param->last_send.argc;
810  VariantCopy(tmp_param->last_send.args, bcap_param->last_send.args);
811 
812  tmp_param->last_modified = gettimeofday_msec();
813  }
814  }
815 
816  /* Clears temporary packet */
817  if(clear_flag) {
818  if(tmp_recv_packet.args != NULL) {
819  for(i = 0; i < tmp_recv_packet.argc; i++) {
820  VariantClear(&tmp_recv_packet.args[i]);
821  }
822  free(tmp_recv_packet.args);
823  }
824  }
825 
826  VariantClear(&vntTmp);
827  VariantClear(&vntOpt);
828  if(bstrOpt) {
829  SysFreeString(bstrOpt);
830  }
831 
832  return hr;
833 }
834 
840 static THRET THTYPE
841 exec_thread(void *arg)
842 {
843 #if !defined(THRET)
844  THRET ret = (THRET)NULL;
845 #endif
846 
847  HRESULT hr;
848  struct CONN_BCAP_SERVER *bcap_param = (struct CONN_BCAP_SERVER *) arg;
849  EVENT *evt[2] =
850  { &bcap_param->exec_evt, &bcap_param->term_sub_evt };
851 
852  while(1) {
853  hr = wait_event_multi(evt, 2, INFINITE, 0);
854  if(hr == WAIT_OBJECT_0 + 1) {
855  break;
856  }
857  else if(hr == WAIT_OBJECT_0) {
858  bcap_callfunc(&bcap_param->last_recv, &bcap_param->last_send);
859  }
860  else {
861  bcap_param->last_send.serial = bcap_param->last_recv.serial;
862  bcap_param->last_send.reserv = 0;
863  bcap_param->last_send.id = hr;
864  bcap_param->last_send.argc = 0;
865  }
866  set_event(&bcap_param->comp_evt);
867  }
868 
869 #if !defined(THRET)
870  return ret;
871 #endif
872 }
873 
879 static THRET THTYPE
880 recv_thread(void *arg)
881 {
882 #if !defined(THRET)
883  THRET ret = (THRET)NULL;
884 #endif
885 
886  uint16_t i;
887  HRESULT hr;
888  struct CONN_BCAP_SERVER *bcap_param = (struct CONN_BCAP_SERVER *) arg;
889  struct BCAP_PACKET *send_packet = &bcap_param->last_send, *recv_packet =
890  &bcap_param->last_recv;
891  struct VEC_OBJECT *pObj = NULL;
892  VARIANT vnt_send, vntTmp;
893  CALL_FUNC_BCAP func;
894 
895  /* Sets last send packet */
896  send_packet->args = &vnt_send;
897  VariantInit(&vnt_send);
898 
899  /* Creates terminal event for sub thread */
900  hr = create_event(&bcap_param->term_sub_evt, 1, 0);
901  if(FAILED(hr)) goto exit_proc;
902 
903  /* Creates events for synchronizing threads */
904  hr = create_event(&bcap_param->exec_evt, 0, 0);
905  if(FAILED(hr)) goto exit_proc;
906 
907  hr = create_event(&bcap_param->comp_evt, 1, 1);
908  if(FAILED(hr)) goto exit_proc;
909 
910  /* Begins sub thread */
911  begin_thread(&bcap_param->sub_thread, &exec_thread, arg);
912 
913  while(1) {
914  hr = wait_event(&bcap_param->term_main_evt, 0);
915  if(SUCCEEDED(hr)) {
916  break;
917  }
918 
919  hr = receive_execute(bcap_param);
920  if(FAILED(hr) && hr != E_TIMEOUT) {
921  break;
922  }
923  }
924 
925 exit_proc:
926  /* Ends sub thread */
927  set_event(&bcap_param->term_sub_evt);
928  exit_thread(bcap_param->sub_thread);
929 
930  /* Destroys events */
931  destroy_event(&bcap_param->term_sub_evt);
932  destroy_event(&bcap_param->exec_evt);
933  destroy_event(&bcap_param->comp_evt);
934 
935  /* Clears last send packet */
936  VariantClear(&vnt_send);
937 
938  /* Clears last received packet */
939  if(recv_packet->args != NULL) {
940  for(i = 0; i < recv_packet->argc; i++) {
941  VariantClear(&recv_packet->args[i]);
942  }
943  free(recv_packet->args);
944  }
945 
946  /* Release all of vector elements */
947  VariantInit(&vntTmp);
948  vntTmp.vt = VT_I4;
949 
950  while(1) {
951  hr = pop_vector(bcap_param, &pObj, 0);
952  if(FAILED(hr)) break;
953 
954  func = m_list_func[pObj->id];
955  if(func != NULL) {
956  vntTmp.lVal = pObj->hObj;
957  func(&vntTmp, ((pObj->id == ID_SERVICE_STOP) ? 0 : 1), &vnt_send);
958  VariantClear(&vnt_send);
959  }
960 
961  free(pObj);
962  }
963 
964  VariantClear(&vntTmp);
965 
966  /* Destroys self */
967  change_relation(bcap_param, DESTROY_SELF, NULL);
968 
969 #if !defined(THRET)
970  return ret;
971 #endif
972 }
973 
979 static THRET THTYPE
980 accept_thread(void *arg)
981 {
982 #if !defined(THRET)
983  THRET ret = (THRET)NULL;
984 #endif
985 
986  int client;
987  HRESULT hr;
988  volatile struct CONN_BCAP_SERVER *child;
989  struct CONN_BCAP_SERVER *bcap_param = (struct CONN_BCAP_SERVER *) arg;
990  MUTEX mutex;
991 
992  /* Initializes mutex */
993  bcap_param->relation_mutex = &mutex;
994  hr = initialize_mutex(&mutex);
995  if(FAILED(hr)) goto exit_proc;
996 
997  while(1) {
998  hr = wait_event(&bcap_param->term_main_evt, 300);
999  if(SUCCEEDED(hr)) {
1000  break;
1001  }
1002 
1003  if(bcap_param->num_child < BCAP_CLIENT_MAX) {
1004  hr = tcp_accept(bcap_param->device.sock, &client);
1005  if(SUCCEEDED(hr)) {
1006  /* Sets no delay option */
1007  tcp_set_nodelay(client, 1);
1008 
1009  /* Sets keep alive option */
1012 
1013  /* Adds child */
1014  change_relation(bcap_param, ADD_CHILD, &client);
1015  }
1016  }
1017 
1018  /* Deletes child */
1019  change_relation(bcap_param, DELETE_CHILD, NULL);
1020  }
1021 
1022 exit_proc:
1023  /* Ends all children thread */
1024  child = bcap_param->node1;
1025  while(child != NULL) {
1026  set_event((EVENT *) &child->term_main_evt);
1027  exit_thread(child->main_thread);
1028 
1029  child = bcap_param->node1;
1030  }
1031 
1032  /* Deletes child */
1033  change_relation(bcap_param, DELETE_CHILD, NULL);
1034 
1035  /* Releases mutex */
1036  release_mutex(&mutex);
1037 
1038 #if !defined(THRET)
1039  return ret;
1040 #endif
1041 }
1042 
1043 HRESULT
1045 {
1046  if((id <= 0) || (_FUNCTION_ID_MAX <= id)) {
1047  return E_INVALIDARG;
1048  }
1049 
1050  m_list_func[id] = func;
1051 
1052  return S_OK;
1053 }
1054 
1055 HRESULT
1056 bCap_Open_Server(const char *connect, uint32_t timeout, int *pfd)
1057 {
1058  int type, index, *sock;
1059  HRESULT hr;
1060  void *conn_param;
1061  struct CONN_PARAM_ETH eth_param =
1062  { 0, 0, htonl(INADDR_ANY), htons(5007) };
1063  struct CONN_PARAM_COM com_param =
1064  { 1, 38400, NOPARITY, 8, ONESTOPBIT, 0 };
1065  struct CONN_BCAP_SERVER *bcap_param;
1066  struct CONN_PARAM_COMMON *device;
1067  struct sockaddr_in *paddr;
1068 
1069  if(connect == NULL || pfd == NULL)
1070  return E_INVALIDARG;
1071 
1072  type = parse_conn_type(connect);
1073 
1074  index = find_open_address(type);
1075  if(index == 0)
1076  return E_MAX_OBJECT;
1077 
1078  bcap_param = &m_conn_param[index - 1];
1079  device = &bcap_param->device;
1080 
1081  /* Initializes connection parameters */
1082  device->type = type;
1083  switch(device->type) {
1084  case CONN_TCP:
1085  hr = parse_conn_param_ether(connect, &eth_param);
1086  conn_param = &eth_param;
1087  device->arg = NULL;
1088  device->dn_open = &tcp_open_server;
1089  device->dn_close = &tcp_close;
1090  device->dn_send = &tcp_send;
1091  device->dn_recv = &tcp_recv;
1092  device->dn_set_timeout = &tcp_set_timeout;
1093  break;
1094  case CONN_UDP:
1095  hr = parse_conn_param_ether(connect, &eth_param);
1096  conn_param = &eth_param;
1097  paddr = (struct sockaddr_in *) malloc(sizeof(struct sockaddr_in));
1098  if(paddr == NULL) {
1099  hr = E_OUTOFMEMORY;
1100  break;
1101  }
1102  paddr->sin_addr.s_addr = eth_param.dst_addr;
1103  paddr->sin_port = eth_param.dst_port;
1104  paddr->sin_family = AF_INET;
1105  device->arg = (void *) paddr;
1106  device->dn_open = &udp_open;
1107  device->dn_close = &udp_close;
1108  device->dn_send = &udp_send;
1109  device->dn_recv = &udp_recv;
1110  device->dn_set_timeout = &udp_set_timeout;
1111  break;
1112  case CONN_COM:
1113  hr = parse_conn_param_serial(connect, &com_param);
1114  conn_param = &com_param;
1115  device->arg = NULL;
1116  device->dn_open = &com_open;
1117  device->dn_close = &com_close;
1118  device->dn_send = &com_send;
1119  device->dn_recv = &com_recv;
1120  device->dn_set_timeout = &com_set_timeout;
1121  break;
1122  default:
1123  hr = E_INVALIDARG;
1124  break;
1125  }
1126 
1127  if(FAILED(hr)) {
1128  if(device->arg != NULL) {
1129  free(device->arg);
1130  device->arg = NULL;
1131  }
1132  memset(bcap_param, 0, sizeof(struct CONN_BCAP_SERVER));
1133  return hr;
1134  }
1135 
1136  /* Create terminal event for main thread */
1137  hr = create_event(&bcap_param->term_main_evt, 1, 0);
1138  if(FAILED(hr)) {
1139  if(device->arg != NULL) {
1140  free(device->arg);
1141  device->arg = NULL;
1142  }
1143  memset(bcap_param, 0, sizeof(struct CONN_BCAP_SERVER));
1144  return hr;
1145  }
1146 
1147  /* Opens connection */
1148  sock = &device->sock;
1149  hr = device->dn_open(conn_param, sock);
1150  if(FAILED(hr)) {
1151  destroy_event(&bcap_param->term_main_evt);
1152  if(device->arg != NULL) {
1153  free(device->arg);
1154  device->arg = NULL;
1155  }
1156  memset(bcap_param, 0, sizeof(struct CONN_BCAP_SERVER));
1157  return hr;
1158  }
1159 
1160  hr = device->dn_set_timeout(*sock, timeout);
1161  if(FAILED(hr)) {
1162  bCap_Close_Server(&index);
1163  return hr;
1164  }
1165 
1166  /* Sets parameters */
1167  device->timeout = timeout;
1168  bcap_param->exec_timeout = INIT_EXEC_TIMEOUT;
1169  bcap_param->wdt_interval = INIT_WDT_INTERVAL;
1170 
1171  /* Begins main thread */
1172  if(device->type == CONN_TCP) {
1173  begin_thread(&bcap_param->main_thread, &accept_thread, bcap_param);
1174  } else {
1175  begin_thread(&bcap_param->main_thread, &recv_thread, bcap_param);
1176  }
1177 
1178  *pfd = index;
1179 
1180  return S_OK;
1181 }
1182 
1183 HRESULT
1185 {
1186  int index, *sock;
1187  struct CONN_BCAP_SERVER *bcap_param;
1188  struct CONN_PARAM_COMMON *device;
1189 
1190  if(pfd == NULL)
1191  return E_HANDLE;
1192 
1193  index = *pfd;
1194 
1195  bcap_param = check_address(index);
1196  if(bcap_param == NULL)
1197  return E_HANDLE;
1198 
1199  device = &bcap_param->device;
1200  sock = &device->sock;
1201 
1202  /* Ends main thread */
1203  set_event(&bcap_param->term_main_evt);
1204  exit_thread(bcap_param->main_thread);
1205 
1206  /* Destroys event */
1207  destroy_event(&bcap_param->term_main_evt);
1208 
1209  /* Closes connection */
1210  device->dn_close(sock);
1211 
1212  /* Releases argument */
1213  if(device->arg != NULL) {
1214  free(device->arg);
1215  device->arg = NULL;
1216  }
1217 
1218  /* Resets connection parameters */
1219  memset(bcap_param, 0, sizeof(struct CONN_BCAP_SERVER));
1220 
1221  *pfd = 0;
1222 
1223  return S_OK;
1224 }
#define S_FALSE
Succeeded but some processes may remain.
Definition: dn_common.h:95
#define BCAP_UDP_MAX
A definition for the maximum count of UDP servers.
Definition: bcap_server.h:69
_DN_EXP_THREAD HRESULT wait_event(EVENT *pevt, uint32_t timeout)
Waits a event.
Definition: dn_thread.c:361
_DN_EXP_THREAD HRESULT unlock_mutex(MUTEX *pmutex)
Unlocks mutex handle.
Definition: dn_thread.c:188
#define ID_TASK_GETVARIABLE
Definition: bcap_funcid.h:125
b-CAP server communication object.
Definition: bcap_server.c:91
static struct CONN_BCAP_SERVER m_conn_param[_BCAP_SERVER_MAX]
Definition: bcap_server.c:115
TCP API file.
unsigned uint32_t
Definition: stdint.h:43
static struct CONN_BCAP_SERVER * check_address(int index)
Checks whether the index has been used or not.
Definition: bcap_server.c:165
_BCAP_EXP_COMMON HRESULT bcap_recv(struct CONN_PARAM_COMMON *device, struct BCAP_PACKET *packet_recv, int client)
Receives b-CAP packet.
Definition: bcap_common.c:984
struct CONN_BCAP_SERVER * node1
Definition: bcap_server.c:110
#define S_EXECUTING
Succeeded but the server has been executing yet.
Definition: bcap_common.h:63
_DN_EXP_TCP HRESULT tcp_open_server(void *param, int *sock)
Opens TCP server.
Definition: dn_tcp.c:254
static THRET THTYPE recv_thread(void *arg)
The receiving thread.
Definition: bcap_server.c:880
uint16_t argc
Definition: bcap_common.h:232
HRESULT(* dn_set_timeout)(int sock, uint32_t timeout)
Definition: dn_device.h:181
struct VEC_OBJECT * stack
Definition: bcap_server.c:106
UDP API file.
#define UDP_LIFELIMIT
A definition for the life limit of a UDP connection.
Definition: bcap_server.h:144
uint32_t timeout
Definition: dn_device.h:174
#define MIN_WDT_INTERVAL
A definition for the minimum watch dog timer interval.
Definition: bcap_server.h:104
int32_t relation_id
Definition: bcap_mapid.h:44
HRESULT(* dn_recv)(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Definition: dn_device.h:179
#define ID_CONTROLLER_CONNECT
Definition: bcap_funcid.h:39
_DN_EXP_TCP HRESULT tcp_set_keepalive(int sock, int enable, uint32_t idle, uint32_t interval, uint32_t count)
Sets keep alive option.
Definition: dn_tcp.c:485
#define KEEPALIVE_COUNT
A definition for the keep alive count option.
Definition: bcap_server.h:137
#define S_OK
Succeeded.
Definition: dn_common.h:89
_DN_EXP_TCP HRESULT tcp_set_nodelay(int sock, int enable)
Sets no delay option.
Definition: dn_tcp.c:500
_DN_EXP_THREAD HRESULT lock_mutex(MUTEX *pmutex, uint32_t timeout)
Locks mutex handle.
Definition: dn_thread.c:145
#define INIT_WDT_INTERVAL
A definition for the initial watch dog timer interval.
Definition: bcap_server.h:111
_DN_EXP_THREAD HRESULT create_event(EVENT *pevt, int reset_mode, int init_signal)
Creates a event object.
Definition: dn_thread.c:220
wchar_t * BSTR
Definition: dn_common.h:239
uint32_t wdt_interval
Definition: bcap_server.c:97
unsigned short uint16_t
Definition: stdint.h:41
_DN_EXP_UDP HRESULT udp_send(int sock, const char *buf, uint32_t len_buf, void *arg)
Sends UDP packet.
Definition: dn_udp.c:94
#define _FUNCTION_ID_MAX
A definition for the maximum count of b-CAP function IDs.
Definition: bcap_server.c:62
int32_t lVal
Definition: dn_common.h:312
VARIANT * args
Definition: bcap_common.h:233
static CALL_FUNC_BCAP m_list_func[_FUNCTION_ID_MAX]
Definition: bcap_server.c:114
_DN_EXP_THREAD HRESULT wait_event_multi(EVENT **pevt, uint32_t count, uint32_t timeout, int wait_all)
Waits multiple events.
Definition: dn_thread.c:478
struct CONN_PARAM_COMMON device
Definition: bcap_server.c:93
BSTR bstrVal
Definition: dn_common.h:318
static int search_vector(struct CONN_BCAP_SERVER *bcap_param, int32_t id, uint32_t hObj)
Searches the target object with function ID and object handle.
Definition: bcap_server.c:266
Thread and mutex API file.
struct CONN_BCAP_SERVER * parent
Definition: bcap_server.c:109
struct VEC_OBJECT * prev
Definition: bcap_server.c:83
#define FAILED(hr)
A macro that returns TRUE/FALSE. If hr is less than zero, then returns TRUE.
Definition: dn_common.h:77
#define ID_CONTROLLER_GETMESSAGE
Definition: bcap_funcid.h:54
_DN_EXP_COM HRESULT com_open(void *param, int *sock)
Opens serial port.
Definition: dn_com.c:360
static HRESULT pop_vector(struct CONN_BCAP_SERVER *bcap_param, struct VEC_OBJECT **pObj, int index)
Pops the object where is in the indicated index from the vector.
Definition: bcap_server.c:217
static uint32_t htonl(uint32_t hostlong)
#define E_HANDLE
Failed because the handle is invalid.
Definition: dn_common.h:119
#define calc_time_diff(start, end)
A macro that calculates the time difference between start and end.
Definition: dn_thread.h:199
#define KEEPALIVE_ENABLE
A definition for the keep alive enable option.
Definition: bcap_server.h:117
_DN_EXP_UDP HRESULT udp_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the UDP socket.
Definition: dn_udp.c:173
int THREAD
int32_t id
Definition: bcap_server.c:81
#define E_INVALIDARG
Failed because some arguments are invalid.
Definition: dn_common.h:131
HRESULT(* dn_close)(int *sock)
Definition: dn_device.h:177
int MUTEX
#define ID_EXTENSION_GETVARIABLE
Definition: bcap_funcid.h:63
_DN_EXP_COM HRESULT com_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the serial socket.
Definition: dn_com.c:489
_DN_EXP_DEVICE HRESULT parse_conn_param_serial(const char *opt, struct CONN_PARAM_COM *param)
Parses serial connection parameters.
Definition: dn_device.c:235
_DN_EXP_COMMON void SysFreeString(BSTR bstr)
Releases the memory of BSTR.
Definition: dn_common.c:104
_DN_EXP_COM HRESULT com_recv(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Receives serial packet.
Definition: dn_com.c:453
uint32_t hObj
Definition: bcap_server.c:82
_DN_EXP_UDP HRESULT udp_open(void *param, int *sock)
Opens UDP socket.
Definition: dn_udp.c:52
int32_t HRESULT
Definition: dn_common.h:61
_DN_EXP_THREAD HRESULT destroy_event(EVENT *pevt)
Destroys a event object.
Definition: dn_thread.c:251
#define ID_CONTROLLER_GETCOMMAND
Definition: bcap_funcid.h:46
uint32_t last_modified
Definition: bcap_server.c:98
static HRESULT bcap_callfunc(struct BCAP_PACKET *recv_packet, struct BCAP_PACKET *send_packet)
Execute a callback function with the received b-CAP command.
Definition: bcap_server.c:525
static THRET THTYPE exec_thread(void *arg)
The executing thread.
Definition: bcap_server.c:841
#define ID_FILE_GETFILE
Definition: bcap_funcid.h:75
HRESULT bCap_Open_Server(const char *connect, uint32_t timeout, int *pfd)
Starts b-CAP server.
Definition: bcap_server.c:1056
int32_t id
Definition: bcap_common.h:231
#define THTYPE
static THRET THTYPE accept_thread(void *arg)
The accepting thread for TCP connection.
Definition: bcap_server.c:980
_DN_EXP_COMMON HRESULT VariantCopy(VARIANT *pvargDest, const VARIANT *pvargSrc)
Copies the source variant to destination variant.
#define E_MAX_CONNECT
Failed because the number of connection is too much.
Definition: dn_common.h:199
_DN_EXP_COM HRESULT com_close(int *sock)
Closes the socket.
Definition: dn_com.c:385
#define E_OUTOFMEMORY
Failed because there is no enough memory space.
Definition: dn_common.h:125
uint16_t sin_port
uint16_t reserv
Definition: bcap_common.h:230
#define THRET
struct VEC_OBJECT * next
Definition: bcap_server.c:84
#define BCAP_COM_MAX
A definition for the maximum count of COM servers.
Definition: bcap_server.h:76
#define NOPARITY
A definition for serial communication setting.
Definition: dn_device.h:69
#define AF_INET
Definition: dn_additional.h:66
HRESULT bCap_Close_Server(int *pfd)
Ends b-CAP server.
Definition: bcap_server.c:1184
_DN_EXP_UDP HRESULT udp_recv(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Receives UDP packet.
Definition: dn_udp.c:135
#define SUCCEEDED(hr)
A macro that returns TRUE/FALSE. If hr is zero or more, then returns TRUE.
Definition: dn_common.h:71
struct CONN_BCAP_SERVER * node2
Definition: bcap_server.c:111
_DN_EXP_THREAD HRESULT set_event(EVENT *pevt)
Sets a event.
Definition: dn_thread.c:295
#define INIT_EXEC_TIMEOUT
A definition for the initial executing timeout.
Definition: bcap_server.h:97
A type definition for Ethernet connection parameters.
Definition: dn_device.h:144
Common device API file.
uint16_t vt
Definition: dn_common.h:308
#define ONESTOPBIT
A definition for serial communication setting.
Definition: dn_device.h:87
b-CAP MAP ID file.
Common API file.
int EVENT
#define ID_ROBOT_GETVARIABLE
Definition: bcap_funcid.h:101
#define INFINITE
A definition for infinite wait.
Definition: dn_thread.h:95
_DN_EXP_COMMON void VariantInit(VARIANT *pvarg)
Initializes the VARIANT.
Definition: dn_common.c:368
_DN_EXP_COMMON HRESULT VariantChangeType(VARIANT *pvargDest, VARIANT *pvarSrc, uint16_t wFlags, uint16_t vt)
Changes the source variant to destination variant with the indicated type.
#define BCAP_OBJECT_MAX
A definition for the maximum count of creatable objects in a thread.
Definition: bcap_server.h:90
static const struct MAP_ID m_map_id[]
Definition: bcap_mapid.h:48
_DN_EXP_TCP HRESULT tcp_recv(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Receives TCP packet.
Definition: dn_tcp.c:364
#define BCAP_TCP_MAX
A definition for the maximum count of TCP servers.
Definition: bcap_server.h:62
A type definition for common communication parameters.
Definition: dn_device.h:170
User own API file.
static uint16_t htons(uint16_t hostshort)
static int check_lifelimit(struct CONN_BCAP_SERVER *parent)
Checks the life limit all of child nodes, and if expired then deletes.
Definition: bcap_server.c:495
_DN_EXP_THREAD uint32_t gettimeofday_msec()
Gets the current time value [ms].
Definition: dn_thread.c:589
HRESULT(* dn_open)(void *param, int *sock)
Definition: dn_device.h:176
_DN_EXP_COM HRESULT com_send(int sock, const char *buf, uint32_t len_buf, void *arg)
Sends serial packet.
Definition: dn_com.c:412
CHANGE_RELATION
change relation information.
Definition: bcap_server.c:68
HRESULT bCap_SetCallFunc(int32_t id, CALL_FUNC_BCAP func)
Sets a callback function.
Definition: bcap_server.c:1044
struct in_addr sin_addr
uint32_t exec_timeout
Definition: bcap_server.c:96
#define _BCAP_SERVER_MAX
A definition for the maximum count of servers.
Definition: bcap_server.c:56
#define E_NOTIMPL
Failed because the function is not implemented.
Definition: dn_common.h:101
A type definition for the multi type variable.
Definition: dn_common.h:306
THREAD main_thread
Definition: bcap_server.c:99
_DN_EXP_COMMON BSTR SysAllocString(const wchar_t *sz)
Allocates and returns BSTR.
Definition: dn_common.c:61
struct BCAP_PACKET last_send
Definition: bcap_server.c:94
_DN_EXP_THREAD HRESULT release_mutex(MUTEX *pmutex)
Releases mutex handle.
Definition: dn_thread.c:108
_DN_EXP_COMMON void VariantClear(VARIANT *pvarg)
Clears the VARIANT.
Definition: dn_common.c:382
#define E_MAX_OBJECT
Failed because the packet is too much.
Definition: dn_common.h:181
#define begin_thread(p_thread, function, arg)
A macro that begins thread.
#define WAIT_OBJECT_0
uint16_t dst_port
Definition: dn_device.h:147
int int32_t
Definition: stdint.h:42
_DN_EXP_DEVICE int parse_conn_type(const char *opt)
Parses and returns the connection type.
Definition: dn_device.c:93
A type definition for the b-CAP packet.
Definition: bcap_common.h:227
_DN_EXP_COMMON HRESULT GetOptionValue(BSTR bstrSrc, BSTR bstrKey, uint16_t vt, VARIANT *pvarDest)
Searchs the key string from source string and sets the value to the destination variant with the indi...
static int find_open_address(int type)
Returns the open address of m_conn_param.
Definition: bcap_server.c:127
uint32_t ulVal
Definition: dn_common.h:323
A type definition for serial connection parameters.
Definition: dn_device.h:156
static HRESULT receive_execute(struct CONN_BCAP_SERVER *bcap_param)
Receives the b-CAP packet and executes callback functions.
Definition: bcap_server.c:560
#define ID_CONTROLLER_GETEXTENSION
Definition: bcap_funcid.h:41
A vector for stacking created objects.
Definition: bcap_server.c:79
_DN_EXP_TCP HRESULT tcp_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the TCP socket.
Definition: dn_tcp.c:405
#define BCAP_CLIENT_MAX
A definition for the maximum count of TCP clients.
Definition: bcap_server.h:83
#define ID_CONTROLLER_GETTASK
Definition: bcap_funcid.h:44
HRESULT(* CALL_FUNC_BCAP)(VARIANT *vntArgs, int16_t Argc, VARIANT *vntRet)
Definition: bcap_server.h:147
struct BCAP_PACKET last_recv
Definition: bcap_server.c:95
#define ID_CONTROLLER_GETROBOT
Definition: bcap_funcid.h:43
_DN_EXP_TCP HRESULT tcp_send(int sock, const char *buf, uint32_t len_buf, void *arg)
Sends TCP packet.
Definition: dn_tcp.c:319
#define exit_thread(thread)
A macro that ends thread.
#define ID_SERVICE_STOP
Definition: bcap_funcid.h:37
Serial API file.
#define ID_CONTROLLER_GETFILE
Definition: bcap_funcid.h:42
#define KEEPALIVE_IDLE
A definition for the keep alive idle option.
Definition: bcap_server.h:124
int return_flag
Definition: bcap_mapid.h:45
_DN_EXP_UDP HRESULT udp_close(int *sock)
Closes the socket.
Definition: dn_udp.c:80
_DN_EXP_TCP HRESULT tcp_accept(int sock, int *client)
TCP server accepts a TCP client.
Definition: dn_tcp.c:448
#define E_BUSY_PROC
Failed because executing process is busy.
Definition: bcap_server.h:55
_DN_EXP_TCP HRESULT tcp_close(int *sock)
Closes the socket.
Definition: dn_tcp.c:305
b-CAP Common API file.
#define E_TIMEOUT
Failed because the communication timed out.
Definition: dn_common.h:169
#define ID_FILE_GETVARIABLE
Definition: bcap_funcid.h:76
uint32_t dst_addr
Definition: dn_device.h:146
#define INADDR_ANY
Definition: dn_additional.h:36
MUTEX * relation_mutex
Definition: bcap_server.c:108
static int connect(SOCKET s, const struct sockaddr *name, int namelen)
HRESULT(* dn_send)(int sock, const char *buf, uint32_t len_buf, void *arg)
Definition: dn_device.h:178
#define ID_SERVICE_START
Definition: bcap_funcid.h:36
_BCAP_EXP_COMMON HRESULT bcap_send(struct CONN_PARAM_COMMON *device, struct BCAP_PACKET *packet_send)
Sends b-CAP packet.
Definition: bcap_common.c:899
_DN_EXP_DEVICE HRESULT parse_conn_param_ether(const char *opt, struct CONN_PARAM_ETH *param)
Parses Ethernet connection parameters.
Definition: dn_device.c:121
#define KEEPALIVE_INTERVAL
A definition for the keep alive interval option.
Definition: bcap_server.h:131
_DN_EXP_THREAD HRESULT initialize_mutex(MUTEX *pmutex)
Initializes mutex handle.
Definition: dn_thread.c:80
static HRESULT push_vector(struct CONN_BCAP_SERVER *bcap_param, struct VEC_OBJECT *pObj)
Pushes the created object to the vector.
Definition: bcap_server.c:186
short sin_family
uint16_t serial
Definition: bcap_common.h:229
static HRESULT change_relation(struct CONN_BCAP_SERVER *own, int mode, int *sock)
Changes thread&#39;s relationships for TCP connection.
Definition: bcap_server.c:315
_DN_EXP_THREAD HRESULT reset_event(EVENT *pevt)
Resets a event.
Definition: dn_thread.c:328
#define ID_CONTROLLER_GETVARIABLE
Definition: bcap_funcid.h:45
static struct CONN_BCAP_SERVER * search_node(struct CONN_BCAP_SERVER *parent, const void *arg, int size)
Searches the target node which has a specified argument.
Definition: bcap_server.c:291
b-CAP Server API file.


bcap_core
Author(s): DENSO WAVE INCORPORATED
autogenerated on Mon Jun 10 2019 13:12:20