int AmazonS3SoapBindingService::serve() { #ifndef WITH_FASTCGI unsigned int k = this->soap->max_keep_alive; #endif do { #ifndef WITH_FASTCGI if (this->soap->max_keep_alive > 0 && !--k) this->soap->keep_alive = 0; #endif if (soap_begin_serve(this->soap)) { if (this->soap->error >= SOAP_STOP) continue; return this->soap->error; } if (dispatch() || (this->soap->fserveloop && this->soap->fserveloop(this->soap))) { #ifdef WITH_FASTCGI soap_send_fault(this->soap); #else return soap_send_fault(this->soap); #endif } #ifdef WITH_FASTCGI soap_destroy(this->soap); soap_end(this->soap); } while (1); #else } while (this->soap->keep_alive);
void* NotificationConsumer::notifyFunc(void* ptr) { NotificationConsumer* consumer = static_cast<NotificationConsumer*>(ptr); int iRet; EventingServiceImpl* serv = new EventingServiceImpl(consumer, NULL, soap_new()); if ( (iRet = soap_bind(serv->soap, NULL, 8080, 100) == SOAP_INVALID_SOCKET ) ) { SIGRLOG(SIGRCRITICAL, "NotificationConsumer::notifyFunc Binding on %d port failed", 8080); return NULL; } while(1) { bool bBreak = false; pthread_mutex_lock( &consumer->mutex_ ); if(consumer->shutdownFlag_) bBreak = true; pthread_mutex_unlock( &consumer->mutex_ ); if(bBreak) break; if( (iRet = soap_accept(serv->soap)) == SOAP_INVALID_SOCKET) { SIGRLOG(SIGRCRITICAL, "NotificationConsumer::notifyFunc accepting failed"); return NULL; } if ( (soap_begin_serve(serv->soap)) != SOAP_OK) { SIGRLOG(SIGRWARNING, "NotificationConsumer::notifyFunc serve %d failed", iRet); continue; } if( serv ) iRet = serv->dispatch(); continue; } serv->destroy(); }
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) { #ifndef WITH_FASTCGI unsigned int k = soap->max_keep_alive; #endif do { #ifndef WITH_FASTCGI if (soap->max_keep_alive > 0 && !--k) soap->keep_alive = 0; #endif if (soap_begin_serve(soap)) { if (soap->error >= SOAP_STOP) continue; return soap->error; } if (soap_serve_request(soap) || (soap->fserveloop && soap->fserveloop(soap))) { #ifdef WITH_FASTCGI soap_send_fault(soap); #else return soap_send_fault(soap); #endif } #ifdef WITH_FASTCGI soap_destroy(soap); soap_end(soap); } while (1); #else } while (soap->keep_alive);
int Service::start(int port) { if (!soap_valid_socket(bind(NULL, port, 100))) { soap_stream_fault(std::cerr); exit(1); } std::cerr << "Server Running" << std::endl; /* optional: set accept timeout to pulse acks every 500 ms, see below */ soap->accept_timeout = -500000; for (;;) { if (soap_valid_socket(accept())) { /* with iterative servers asynchronous messaging deadlock scenarios exist! */ /* chain the WSRM service operations after the main service operations */ if (soap_begin_serve(soap) == SOAP_OK) if (dispatch() == SOAP_NO_METHOD) soap_serve_request(soap); if (soap->error) soap_send_fault(soap); if (soap->error && soap->error != SOAP_STOP) soap_stream_fault(std::cerr); destroy(); callback.destroy(); soap_wsrm_dump(soap, stdout); } else { /* error or timeout? */ if (soap->errnum) { soap_stream_fault(std::cerr); exit(1); } /* timeout occurs after 1 sec */ /* send acks to peers (optional), 10 ms per message timeout */ soap_wsrm_pulse(soap, -10000); /* 10 ms */ } } return SOAP_OK; }
void *callback_thread(void *ctx) { WSDualHttpBinding_USCOREICalculatorDuplexService *callback = (WSDualHttpBinding_USCOREICalculatorDuplexService*)ctx; THREAD_DETACH(THREAD_ID); /* chain the WSRM operations after callback operations */ if (soap_begin_serve(callback->soap) == SOAP_OK) if (callback->dispatch() == SOAP_NO_METHOD) soap_serve_request(callback->soap); if (callback->soap->error) soap_send_fault(callback->soap); if (callback->soap->error != SOAP_STOP && callback->soap->error != SOAP_EOF) callback->soap_stream_fault(std::cerr); else if (callback->soap->error != SOAP_EOF || callback->soap->errnum) soap_wsrm_dump(callback->soap, stdout); callback->destroy(); delete callback; return NULL; }
int Client::poll(int timeout) { #ifdef CB_THREAD // We leave the acceptance of messages to the callback server thread if (timeout < 0) timeout = 1; sleep(timeout); // but we want to wait some until these messages arrive #else callback.soap->accept_timeout = timeout; printf("\n**** Callback Polling\n"); while (soap_valid_socket(callback.accept())) { /* chain the WSRM operations after callback operations */ if (soap_begin_serve(callback.soap) == SOAP_OK) if (callback.dispatch() == SOAP_NO_METHOD) soap_serve_request(callback.soap); if (callback.soap->error) soap_send_fault(callback.soap); soap->error = callback.soap->error; callback.destroy(); if (soap->error && soap->error != SOAP_STOP) { soap_stream_fault(std::cerr); return soap->error; } soap_wsrm_dump(callback.soap, stdout); } #endif return SOAP_OK; }
int main(int argc, char* argv[]) { std::string indevice = "/dev/video0"; std::string inpath = "unicast"; std::string outdevice = "/dev/video10"; std::string outpath = "rtsp://127.0.0.1:8554/unicast"; std::string username; std::string password; int port = 8080; int c = 0; while ((c = getopt (argc, argv, "h" "u:p:" "P:" "i:I:o:O:")) != -1) { switch (c) { case 'P': port = atoi(optarg); break; case 'u': username = optarg; break; case 'p': password = optarg; break; case 'i': indevice = optarg; break; case 'I': inpath = optarg; break; case 'o': outdevice = optarg; break; case 'O': outpath = optarg; break; case 'h': std::cout << argv[0] << " [-u username] [-p password] [-i v4l2 input device] [-I rtsp server] [-o v4l2 output device] [-O rtsp client]" << std::endl; exit(0); break; } } std::cout << "Listening to " << port << std::endl; ServiceContext deviceCtx; deviceCtx.m_devices.insert(std::pair<std::string,std::string>(indevice, inpath)); deviceCtx.m_port = port; deviceCtx.m_user = username; deviceCtx.m_password = password; deviceCtx.m_outdevice = outdevice; deviceCtx.Manufacturer = "Manufacturer"; deviceCtx.Model = "Model"; deviceCtx.FirmwareVersion = "FirmwareVersion"; deviceCtx.SerialNumber = "SerialNumber"; deviceCtx.HardwareId = "HardwareId"; deviceCtx.m_scope.push_back("onvif://www.onvif.org/name/Name"); deviceCtx.m_scope.push_back("onvif://www.onvif.org/location/Here"); deviceCtx.m_scope.push_back("onvif://www.onvif.org/Profile/Streaming"); deviceCtx.m_scope.push_back("onvif://www.onvif.org/Profile/G"); struct soap *soap = soap_new(); soap->user = (void*)&deviceCtx; soap->fget = http_get; { FOREACH_SERVICE(DECLARE_SERVICE,soap) if (!soap_valid_socket(soap_bind(soap, NULL, deviceCtx.m_port, 100))) { soap_stream_fault(soap, std::cerr); } else { while (soap_accept(soap) != SOAP_OK) { if (soap_begin_serve(soap)) { soap_stream_fault(soap, std::cerr); } FOREACH_SERVICE(DISPATCH_SERVICE,soap) else { std::cout << "Unknown service" << std::endl; } } } } soap_destroy(soap); soap_end(soap); soap_free(soap); return 0; }
int _tmain(int argc, _TCHAR* argv[]) { int ret; /* 192.168.1.1 is the NVT, 192.168.1.234 is the NVC */ string url = "http://192.168.1.1/onvif/device_service"; /* Below is where to receive the event */ string eventNotify = "http://192.168.1.234:9090/subscription-2"; string user = "******"; string pass = "******"; OnvifClientDevice onvifDevice(url, user, pass); _tds__GetCapabilitiesResponse capabilitiesResponse; onvifDevice.GetCapabilities(); OnvifClientMedia media(onvifDevice); _trt__GetProfilesResponse profiles; media.GetProfiles(profiles); /* Recording */ OnvifClientRecording onvifRecording(onvifDevice); _trc__GetRecordingsResponse recordings; onvifRecording.GetRecordings(recordings); /* Onvif Receiver */ OnvifClientReceiver onvifReceiver(onvifDevice); _trv__GetReceiversResponse receivers; onvifReceiver.GetReceivers(receivers); string replayUrl; OnvifClientReplay onvifRelay(onvifDevice); onvifRelay.GetReplayUri("RecordingToken001", replayUrl); printf("Relay Url %s\n", replayUrl.c_str()); OnvifClientEvent onvifEvent(onvifDevice); onvifEvent.Subscribe(eventNotify); OnvifClientEventNotify notify(soap_new()); if ((ret = soap_bind(¬ify, NULL, 9090, 100) == SOAP_INVALID_SOCKET ) ) { printf("OnvifClientEventNotify::soap_bind Binding on %d port failed", 9090); return 0; } int timeStart = time(NULL); int currentTime = 0; //Loop to recevie the event while(1) { currentTime = time(NULL); if (currentTime - timeStart > 58) { onvifEvent.Renew(); } printf("soap_accept accepting\n"); if( (ret = soap_accept(¬ify)) == SOAP_INVALID_SOCKET) { printf("soap_accept accepting timeout\n"); continue; } if ( (soap_begin_serve(¬ify)) != SOAP_OK) { printf("soap_begin_serve serve %d failed", ret); continue; } ret = notify.dispatch(); continue; } return 0; }