#include #include #include #include "probe/probe.h" #include "proto_comm.h" #include "proto_dbg.h" /*probe the broadcastted devices*/ int DiscoverDevice(void (*cb)(char *DeviceXAddr)) { int i; int result = 0; unsigned int count = 0; struct soap *soap = NULL; struct wsdd__ProbeType req; struct __wsdd__ProbeMatches rep; struct wsdd__ProbeMatchType *probeMatch; SOAP_ASSERT(NULL != (soap = proto_soap_new(SOAP_SOCK_TIMEOUT))); /*Set the packet header descriptor*/ proto_init_header(soap); /*Set the probe devices type*/ proto_init_ProbeType(soap, &req); /*deliver the broadcast probe message*/ result = soap_send___wsdd__Probe(soap, SOAP_MCAST_ADDR, NULL, &req); while (SOAP_OK == result) { memset(&rep, 0x00, sizeof(rep)); result = soap_recv___wsdd__ProbeMatches(soap, &rep); if (SOAP_OK == result) { if (soap->error) { soap_perror(soap, "ProbeMatches"); } else { /*Get the probing devices response*/ dump__wsdd__ProbeMatches(&rep); if (NULL != rep.wsdd__ProbeMatches) { count += rep.wsdd__ProbeMatches->__sizeProbeMatch; for(i = 0; i < rep.wsdd__ProbeMatches->__sizeProbeMatch; i++) { probeMatch = rep.wsdd__ProbeMatches->ProbeMatch + i; if (NULL != cb) { cb(probeMatch->XAddrs); } } } } } else if (soap->error) { break; } } SOAP_DBGERR("\ndetect end! It has detected %d devices!\n", count); if (NULL != soap) { proto_soap_delete(soap); } return count; }