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(); }
std::string DeviceInfoStorage::getInterfaceIp( const std::string & interface ) { struct ifaddrs * ifAddrStruct=NULL; struct ifaddrs * ifa=NULL; void * tmpAddrPtr=NULL; getifaddrs(&ifAddrStruct); std::string result(""); for (ifa = ifAddrStruct; ifa != NULL; ifa = ifa->ifa_next) { if (ifa ->ifa_addr->sa_family==AF_INET) { // check it is IP4 // is a valid IP4 Address tmpAddrPtr=&((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; char addressBuffer[INET_ADDRSTRLEN]; inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN); SIGRLOG( SIGRDEBUG3, "%s IP Address %s", ifa->ifa_name, addressBuffer); if(! strcmp(ifa->ifa_name, interface.c_str())) result = std::string(addressBuffer); } else if (ifa->ifa_addr->sa_family==AF_INET6) { // check it is IP6 // is a valid IP6 Address tmpAddrPtr=&((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; char addressBuffer[INET6_ADDRSTRLEN]; inet_ntop(AF_INET6, tmpAddrPtr, addressBuffer, INET6_ADDRSTRLEN); SIGRLOG( SIGRDEBUG3, "%s IP Address %s", ifa->ifa_name, addressBuffer); if( ( !strcmp(ifa->ifa_name, interface.c_str()) ) && result.empty() ) result = std::string(addressBuffer); } } if( ifAddrStruct != NULL ) freeifaddrs(ifAddrStruct); return result; }
int BaseClient::Init(const char* pchEndpoint) { if(!m_pSoap) { SIGRLOG (SIGRWARNING, "BaseClient::Init failed" ); return -1; } m_pDevClient = new DeviceClient (pchEndpoint, m_pSoap); m_pDevIOClient = new DeviceIOClient (pchEndpoint, m_pSoap); m_pDispClient = new DisplayClient (pchEndpoint, m_pSoap); m_pRecvClient = new ReceiverClient (pchEndpoint, m_pSoap); m_pRecordingClient = new RecordingClient (pchEndpoint, m_pSoap); m_pNotsConsumer = new NotificationConsumer(pchEndpoint, m_pSoap); if(m_pNotsConsumer && !m_pNotsConsumer->init()) { SIGRLOG (SIGRWARNING, "BaseClient::Init failed to init NotificationConsumer" ); return -1; } if( m_pDevClient && m_pDevIOClient && m_pDispClient && m_pRecvClient && m_pRecordingClient && m_pNotsConsumer ) return 0; SIGRLOG (SIGRWARNING, "BaseClient::Init failed to create proxies" ); return -1; }
void Discoverable::runDeviceService() { try { std::tr1::shared_ptr<Service_t> service(RemoteDiscovery::service()); std::string address = "urn:"; address += randUuid( service->getSoap() ); std::string xaddrs = baseServ_->m_endpoint; Scopes_t scopes = Scopes_t(); scopes.item = vector_join(baseServ_->m_scopes, " "); EndpointReference_t endpoint = EndpointReference_t(); endpoint.address = &address; probeMatches_.resize(1); probeMatches_.back().endpoint = &endpoint; probeMatches_.back().scopes = &scopes; probeMatches_.back().types = &baseServ_->m_type; probeMatches_.back().xaddrs = &xaddrs; probeMatches_.back().version = 1; proxy_.reset(RemoteDiscovery::proxy()); proxy_->hello(probeMatches_.back()); SIGRLOG( SIGRDEBUG2, "[runDeviceService] Starting the service loop" ); if( service->bind(this) == -1 ) throw UnixException( errno ); while (true) { pthread_mutex_lock(&mutex_); if(bExitRequest_) { service->destroy(); bExitRequest_ = false; break; } pthread_mutex_unlock(&mutex_); if (service->accept() == -1) { SIGRLOG( SIGRWARNING, "Accept failed" ); continue; } if( service->serve() != 0 ) continue; service->destroy(); } service.reset(); proxy_.reset(RemoteDiscovery::proxy()); proxy_->bye(probeMatches_.back()); } catch (std::exception & ex) { SIGRLOG( SIGRWARNING, "[runDeviceService] Caught an exception: %s", ex.what() ); } SIGRLOG( SIGRDEBUG0, "[runDeviceService] The service loop stopped" ); }
Discoverable::ProbeMatches_t Discoverable::probe(const Probe_t & arg) { SIGRLOG( SIGRDEBUG3, "probe ( %s, %s)", (arg.types != NULL ? arg.types->c_str() : ""), (arg.scopes != NULL ? arg.scopes->item.c_str() : "")); bool matched = true; if (arg.types != NULL && probeMatches_.back().types != NULL) { std::string types = *arg.types; while (true) { std::size_t pos1 = types.rfind(':'); if (pos1 == std::string::npos) break; std::size_t pos2 = types.rfind(' ', pos1); if (pos2 == std::string::npos) pos2 = 0; else ++pos2; types.erase(pos2, pos1 - pos2 + 1); } matched = isMatched(types, *probeMatches_.back().types); } if (matched && arg.scopes != NULL && !arg.scopes->item.empty() && probeMatches_.back().scopes != NULL) matched = isMatched(arg.scopes->item, probeMatches_.back().scopes->item); return matched ? probeMatches_ : Discoverable::ProbeMatches_t(); }
void Discoverable::bye(const Bye_t & arg) { SIGRLOG( SIGRDEBUG3, "bye ( %s, %s, %s)", (arg.xaddrs != NULL ? arg.xaddrs->c_str() : ""), (arg.types != NULL ? arg.types->c_str() : ""), (arg.scopes != NULL ? arg.scopes->item.c_str() : "")); }
int DeviceInfoStorage::SetDeviceInfo( OnvifDevice::Type type, const std::string & manufacturer, const std::string & model, const std::string & firmwareVersion, const std::string & serialNumber, const std::string & hardwareId, const std::string & scopes, const std::string & interface, int webservicePort ) { m_deviceType = type; m_type = DeviceInfoStorage::ResolveType(type); m_manufacturer = manufacturer; m_model = model; m_firmwareVersion = firmwareVersion; m_serialNumber = serialNumber; m_hardwareId = hardwareId; m_deviceServiceXAddr = DeviceInfoStorage::getInterfaceIp( interface ); m_scopes = split( scopes, ' ' ); m_webservicePort = webservicePort; std::stringstream ss; ss << "http://" << m_deviceServiceXAddr << ":" << m_webservicePort; m_endpoint = ss.str(); if( m_deviceServiceXAddr.empty() ) { SIGRLOG(SIGRCRITICAL, "DeviceInfoStorage::SetDeviceInfo " "hasnt found address for %s interface", interface.c_str() ); return -1; } return 0; }
bool NotificationConsumer::setCatcher( notificationCatcherFunc catcher ) { if(!catcher) { SIGRLOG (SIGRWARNING, "NotificationConsumer::setCatcher provided arg is NULL" ); return false; } catcher_ = catcher; return true; }
bool NotificationConsumer::init() { if( pthread_create(&thread_, NULL, &NotificationConsumer::notifyFunc, this ) != 0) { SIGRLOG (SIGRWARNING, "NotificationConsumer::init failed to run notifyFunc" ); return false; } return true; }
int DeviceServiceImpl::GetServices(_tds__GetServices *tds__GetServices, _tds__GetServicesResponse *tds__GetServicesResponse) { DevGetServices req(tds__GetServices); DevGetServicesResponse resp(tds__GetServicesResponse); if( req.d->IncludeCapability ) SIGRLOG(SIGRWARNING, "DeviceServiceImpl::GetServices 'Including Capabilities' still not implemented"); resp.AddService( "http://www.onvif.org/ver10/events/wsdl", m_pBaseServer->m_endpoint ); return 0; }
int ReceiverClient::SetReceiverMode(const std::string & recvToken, bool bMode) { RecvSetReceiverMode req(m_proxy.soap); RecvSetReceiverModeResponse resp(m_proxy.soap); req.setToken(recvToken); req.setMode(bMode); SIGRLOG(SIGRDEBUG2, "ReceiverClient::SetReceiverMode %s %d", req.getToken().c_str(), req.getMode()); int nRes = m_proxy.SetReceiverMode(req.d, resp.d); CHECKRETURN(nRes, "ReceiverClient::SetReceiverMode"); }
void Discoverable::hello(const Hello_t & arg) { SIGRLOG( SIGRDEBUG3, "hello ( %s, %s, %s)", (arg.xaddrs != NULL ? arg.xaddrs->c_str() : ""), (arg.types != NULL ? arg.types->c_str() : ""), (arg.scopes != NULL ? arg.scopes->item.c_str() : "")); // TODO: implement // currently not used, since wsdd client get devices only by probe request // if(arg.xaddrs != NULL && !arg.xaddrs->empty()) // { // if (std::find(members_.begin(), members_.end(), *arg.xaddrs) == members_.end()) // members_.push_back(arg.xaddrs->c_str()); // } }
int DeviceServiceImpl::SetSystemDateAndTime(_tds__SetSystemDateAndTime *tds__SetSystemDateAndTime, _tds__SetSystemDateAndTimeResponse *tds__SetSystemDateAndTimeResponse) { if(tds__SetSystemDateAndTime->DateTimeType != tt__SetDateTimeType__Manual) { SIGRLOG(SIGRWARNING, "DeviceServiceImpl::SetSystemDateAndTime Time is not Manual"); return SOAP_ERR; } DevSetSystemDateAndTime dt(tds__SetSystemDateAndTime); int nRes = m_pBaseServer->SetDateAndTime(dt); CHECKRETURN(nRes, "DeviceServiceImpl::SetSystemDateAndTime"); }
virtual ProbeMatches_t probe(const Probe_t & arg) { // Header wsa_.request(TO_TS_URL, SOAP_NAMESPACE_OF_wsd"/Probe"); // Body wsd__ProbeType req; req.soap_default(RemoteDiscoveryBindingProxy::soap); req.Types = arg.types; wsd__ScopesType req_scopes; req_scopes.soap_default(RemoteDiscoveryBindingProxy::soap); if (arg.scopes != NULL) { req_scopes.__item = arg.scopes->item; req_scopes.MatchBy = arg.scopes->matchBy; req.Scopes = &req_scopes; } wsd__ProbeMatchesType resp; if (Probe(&req, &resp ) != 0) throw SoapException(RemoteDiscoveryBindingProxy::soap); SIGRLOG( SIGRDEBUG3, "resp.ProbeMatch.size() %d", resp.ProbeMatch.size()); ProbeMatches_t matches; for( int i = 0; i < resp.ProbeMatch.size(); ++i ) if( !resp.ProbeMatch[i]->XAddrs->empty() ) { ProbeMatch_t match; match.xaddrs = new std::string( *resp.ProbeMatch[i]->XAddrs ); match.types = new std::string( *resp.ProbeMatch[i]->Types ); match.scopes = new Scopes_t(); match.scopes->item = resp.ProbeMatch[i]->Scopes->__item; matches.push_back(match); } return matches; }
Discoverable::~Discoverable() { SIGRLOG(SIGRDEBUG2, "Discoverable::~Discoverable"); stop(); pthread_mutex_destroy(&mutex_); }