int CDECL main(int aArgc, char* aArgv[]) { InitialisationParams* initParams = InitialisationParams::Create(); OptionParser parser; OptionUint optionDuration("-d", "--duration", 30, "Number of seconds to run the test"); parser.AddOption(&optionDuration); if (!parser.Parse(aArgc, aArgv)) { return (1); } UpnpLibrary::Initialise(initParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); UpnpLibrary::DestroySubnetList(subnetList); UpnpLibrary::StartCp(subnet); // Debug::SetLevel(Debug::kTopology); ReceiverManager2Logger* logger = new ReceiverManager2Logger(); Blocker* blocker = new Blocker; blocker->Wait(optionDuration.Value()); delete blocker; delete (logger); UpnpLibrary::Close(); }
// parse a STATA command DwUseOptions* DwUseOptionParser::Parse(vector<string> words) { // there are 10 keywords we expect to see string keys[] = {"variables", "if", "using", "limit", "nulldata", "lowercase", "uppercase", "label_variable", "label_values", "username", "password", "database"}; size_t nkeys(sizeof(keys) / sizeof(string)); // create parser that accepts these keywords OptionParser* parser = new OptionParser( set<string>(keys, keys + nkeys) ); // prepare another vector where we can search // see if we have a using anywhere, if we do, the first part is the varlist, if not it is the tablename bool hasUsing = hasKeyword(words, "using"); // if it contains using somewhere we can start with variables (if missing it will be an empty string, if the list is there it will be expected) if( !hasUsing ) words.insert(words.begin(), "using"); else if( lowerCase(words[0]) != "if" && lowerCase(words[0]) != "using" ) words.insert(words.begin(), "variables"); // parse the options map<string,string> options = parser->Parse( words ); delete parser; // create a meaningful options object DwUseOptions* useOptions = new DwUseOptions( options ); return useOptions; }
int __cdecl main(int aArgc, char* aArgv[]) { InitialisationParams* initParams = InitialisationParams::Create(); OptionParser parser; OptionUint optionDuration("-d", "--duration", 30, "Number of seconds to run the test"); parser.AddOption(&optionDuration); if (!parser.Parse(aArgc, aArgv)) { return (1); } UpnpLibrary::Initialise(initParams); UpnpLibrary::StartCp(); //Debug::SetLevel(Debug::kTopology); ReceiverManager2Logger* logger = new ReceiverManager2Logger(); Blocker* blocker = new Blocker; blocker->Wait(optionDuration.Value()); delete blocker; delete (logger); UpnpLibrary::Close(); }
int CDECL main(int aArgc, char* aArgv[]) { InitialisationParams* initParams = InitialisationParams::Create(); OptionParser parser; OptionUint optionDuration("-d", "--duration", 30, "Number of seconds to run the test"); parser.AddOption(&optionDuration); if (!parser.Parse(aArgc, aArgv)) { return (1); } Library* lib = new Library(initParams); std::vector<NetworkAdapter*>* subnetList = lib->CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); Library::DestroySubnetList(subnetList); CpStack* cpStack = lib->StartCp(subnet); // Debug::SetLevel(Debug::kTopology); ReceiverManager1Logger* logger = new ReceiverManager1Logger(*cpStack); Blocker* blocker = new Blocker(lib->Env()); blocker->Wait(optionDuration.Value()); delete blocker; delete (logger); Print("Closing ... "); delete lib; Print("closed\n"); }
void TestNetwork(const std::vector<Brn>& aArgs) { OptionParser parser; OptionUint adapter("-i", "--interface", 0, "index of network adapter to use"); parser.AddOption(&adapter); if (!parser.Parse(aArgs) || parser.HelpDisplayed()) { return; } std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(Net::InitialisationParams::ELoopbackUse, "TestNetwork"); ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size()); TIpAddress addr = (*ifs)[adapter.Value()]->Address(); for (TUint i=0; i<ifs->size(); i++) { (*ifs)[i]->RemoveRef("TestNetwork"); } delete ifs; Endpoint endpt(0, addr); Endpoint::AddressBuf buf; endpt.AppendAddress(buf); Print("Using network interface %s\n\n", buf.Ptr()); Thread* th = new MainNetworkTestThread(addr); th->Start(); th->Wait(); delete th; }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; OptionBool loopback("-l", "--loopback", "Use the loopback adapter only"); parser.AddOption(&loopback); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (loopback.Value()) { aInitParams->SetUseLoopbackNetworkInterface(); } UpnpLibrary::Initialise(aInitParams); UpnpLibrary::StartCombined(); //Debug::SetLevel(Debug::kDevice/*Debug::kXmlFetch | Debug::kHttp*/); Print("TestDviDeviceList - starting\n"); DvDevices* devices = new DvDevices; CpDevices* deviceList = new CpDevices; FunctorCpDevice added = MakeFunctorCpDevice(*deviceList, &CpDevices::Added); FunctorCpDevice removed = MakeFunctorCpDevice(*deviceList, &CpDevices::Removed); Print("Count devices implementing service1\n"); Brn domainName("a.b.c"); Brn serviceType("service1"); TUint ver = 1; CpDeviceListUpnpServiceType* list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); Blocker* blocker = new Blocker; blocker->Wait(aInitParams->MsearchTimeSecs()); std::vector<const char*> udns; udns.push_back((const char*)gNameDevice1.Ptr()); udns.push_back((const char*)gNameDevice2.Ptr()); deviceList->Validate(udns); udns.clear(); delete list; deviceList->Clear(); Print("Count devices implementing service2\n"); serviceType.Set("service2"); list = new CpDeviceListUpnpServiceType(domainName, serviceType, ver, added, removed); blocker->Wait(aInitParams->MsearchTimeSecs()); udns.push_back((const char*)gNameDevice1_1.Ptr()); udns.push_back((const char*)gNameDevice2.Ptr()); deviceList->Validate(udns); udns.clear(); delete list; delete blocker; delete deviceList; delete devices; Print("TestDviDeviceList - completed\n"); UpnpLibrary::Close(); }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; OptionBool loopback("-l", "--loopback", "Use the loopback adapter only"); parser.AddOption(&loopback); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (loopback.Value()) { aInitParams->SetUseLoopbackNetworkAdapter(); } aInitParams->SetMsearchTime(1); aInitParams->SetDvUpnpServerPort(0); UpnpLibrary::Initialise(aInitParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); UpnpLibrary::DestroySubnetList(subnetList); UpnpLibrary::StartCombined(subnet); //Debug::SetLevel(Debug::kEvent | Debug::kDvEvent); Print("TestDvDeviceStd - starting\n"); Semaphore* sem = new Semaphore("SEM1", 0); DeviceBasic* device = new DeviceBasic(DeviceBasic::eProtocolUpnp); CpDevices* deviceList = new CpDevices(device->Device().Udn(), *sem); FunctorCpDeviceCpp added = MakeFunctorCpDeviceCpp(*deviceList, &CpDevices::Added); FunctorCpDeviceCpp removed = MakeFunctorCpDeviceCpp(*deviceList, &CpDevices::Removed); std::string domainName("openhome.org"); std::string serviceType("TestBasic"); TUint ver = 1; CpDeviceListCppUpnpServiceType* list = new CpDeviceListCppUpnpServiceType(domainName, serviceType, ver, added, removed); sem->Wait(30*1000); // allow up to 30s to find our one device try { deviceList->TestActions(); Functor cb = MakeFunctor(sem, &DeviceDisabled); device->Device().SetDisabled(cb); sem->Wait(); deviceList->TestThrows(); device->Device().SetEnabled(); deviceList->TestSubscriptions(); } catch (Exception& e) { Print("Exception %s from %s:%u\n", e.Message(), e.File(), e.Line()); ASSERTS(); } delete sem; delete list; delete deviceList; delete device; Print("TestDvDeviceStd - completed\n"); UpnpLibrary::Close(); }
void TestSsdpMListen(const std::vector<Brn>& aArgs) { OptionParser parser; OptionUint duration("-d", "--duration", 30, "Number of seconds to listen for. Defaults to 30"); parser.AddOption(&duration); OptionUint adapter("-i", "--interface", 0, "index of network adapter to use"); parser.AddOption(&adapter); if (!parser.Parse(aArgs) || parser.HelpDisplayed()) { return; } Runner runner("SSDP multicast listener\n"); runner.Add(new SuiteListen(duration.Value(), adapter.Value())); runner.Run(); }
void TestTopology2(Environment& aEnv, const std::vector<Brn>& aArgs) { if( find(aArgs.begin(), aArgs.end(), Brn("--path")) == aArgs.end() ) { Log::Print("No path supplied!\n"); ASSERTS(); } OptionParser parser; OptionString optionServer("-s", "--server", Brn("eng"), "address of server to connect to"); parser.AddOption(&optionServer); OptionUint optionPort("-p", "--port", 80, "server port to connect on"); parser.AddOption(&optionPort); OptionString optionPath("", "--path", Brn(""), "path to use on server"); parser.AddOption(&optionPath); if (!parser.Parse(aArgs) || parser.HelpDisplayed()) { return; } TUint port = optionPort.Value(); ASSERT(port <= 65535); Bwh uriBuf(100); Endpoint endptServer = Endpoint(port, optionServer.Value()); uriBuf.Replace(Brn("http://")); endptServer.AppendEndpoint(uriBuf); uriBuf.Append(Brn("/")); uriBuf.Append(optionPath.Value()); Uri uri(uriBuf); auto reader = new HttpReader(aEnv); TUint code = reader->Connect(uri); if ((code < HttpStatus::kSuccessCodes) || (code >= HttpStatus::kRedirectionCodes)) { Log::Print("Failed to connect \n"); ASSERTS(); } ReaderUntilS<1024>* readerUntil = new ReaderUntilS<1024>(*reader); Runner runner("Topology2 tests\n"); runner.Add(new SuiteTopology2(*readerUntil)); runner.Run(); delete readerUntil; delete reader; }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; OptionUint duration("-d", "--duration", 30, "Number of seconds to run the test"); OptionUint adapter("-i", "--interface", 0, "index of network adapter to use"); parser.AddOption(&duration); parser.AddOption(&adapter); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } UpnpLibrary::Initialise(aInitParams); std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(false, "TestTopology3"); ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size()); TIpAddress subnet = (*ifs)[adapter.Value()]->Subnet(); for (TUint i=0; i<ifs->size(); i++) { (*ifs)[i]->RemoveRef("TestTopology3"); } delete ifs; UpnpLibrary::StartCp(subnet); Endpoint endpt(0, subnet); Endpoint::AddressBuf buf; endpt.AppendAddress(buf); Print("Using network interface %s\n\n", buf.Ptr()); // Debug::SetLevel(Debug::kTopology); // Debug::SetLevel(Debug::kAll); TopologyLogger logger; CpTopology3* topology = new CpTopology3(logger); if (topology != NULL) { Blocker* blocker = new Blocker; blocker->Wait(duration.Value()); delete blocker; } delete topology; UpnpLibrary::Close(); }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over"); parser.AddOption(&mx); OptionBool refresh("-f", "--refresh", "Wait mx secs then refresh list"); parser.AddOption(&refresh); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (mx.Value() != 0) { aInitParams->SetMsearchTime(mx.Value()); } UpnpLibrary::Initialise(aInitParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); UpnpLibrary::DestroySubnetList(subnetList); UpnpLibrary::StartCp(subnet); // Debug::SetLevel(Debug::kTopology); // Debug::SetLevel(Debug::kAll); TopologyLogger logger; CpTopology1* topology = new CpTopology1(logger); if (topology != NULL) { Blocker* blocker = new Blocker; blocker->Wait(aInitParams->MsearchTimeSecs()); delete blocker; } if (refresh.Value()) { Blocker* blocker = new Blocker; blocker->Wait(mx.Value()); Print("\nRefreshing...\n\n"); topology->Refresh(); blocker->Wait(mx.Value()); delete blocker; } delete topology; UpnpLibrary::Close(); }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams) { std::vector<Brn> args = OptionParser::ConvertArgs(aArgc, aArgv); OptionParser parser; OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over"); parser.AddOption(&mx); if (!parser.Parse(args, true) || parser.HelpDisplayed()) { return; } if (mx.Value() != 0) { aInitParams->SetMsearchTime(mx.Value()); } Library* lib = new Net::Library(aInitParams); TestSsdpUListen(lib->Env(), args); delete lib; }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams) { std::vector<Brn> args = OptionParser::ConvertArgs(aArgc, aArgv); OptionParser parser; OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over"); parser.AddOption(&mx); if (!parser.Parse(args, true) || parser.HelpDisplayed()) { return; } if (mx.Value() != 0) { aInitParams->SetMsearchTime(mx.Value()); } UpnpLibrary::Initialise(aInitParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); UpnpLibrary::DestroySubnetList(subnetList); UpnpLibrary::StartCp(subnet); TestSsdpUListen(args); UpnpLibrary::Close(); }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams) { OptionParser parser; OptionBool loopback("-l", "--loopback", "Use the loopback adapter only"); parser.AddOption(&loopback); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (loopback.Value()) { aInitParams->SetUseLoopbackNetworkAdapter(); } aInitParams->SetDvUpnpServerPort(0); Library* lib = new Library(aInitParams); std::vector<NetworkAdapter*>* subnetList = lib->CreateSubnetList(); TIpAddress subnet = (*subnetList)[0]->Subnet(); Library::DestroySubnetList(subnetList); CpStack* cpStack = NULL; DvStack* dvStack = NULL; lib->StartCombined(subnet, cpStack, dvStack); TestDvSubscription(*cpStack, *dvStack); delete lib; }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], InitialisationParams* aInitParams) { OptionParser parser; Brn emptyString(""); OptionString config("-c", "--config", emptyString, "[full dir path] to folder containing web UI"); parser.AddOption(&config); OptionBool loopback("-l", "--loopback", "Use the loopback adapter only"); parser.AddOption(&loopback); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } if (config.Value().Bytes() == 0) { parser.DisplayHelp(); return; } if (loopback.Value()) { aInitParams->SetUseLoopbackNetworkAdapter(); } aInitParams->SetDvNumWebSocketThreads(5); aInitParams->SetDvWebSocketPort(54320); aInitParams->SetDvUpnpServerPort(0); UpnpLibrary::Initialise(aInitParams); Debug::SetLevel(Debug::kDvWebSocket | Debug::kError | Debug::kDvInvocation | Debug::kDvEvent | Debug::kDvDevice); UpnpLibrary::StartDv(); Print("TestDvTestBasic - starting ('q' to quit)\n"); DeviceBasic* device = new DeviceBasic(config.Value()); while (getchar() != 'q') { ; } delete device; Print("TestDvTestBasic - exiting\n"); UpnpLibrary::Close(); }
void TestDeviceList(const std::vector<Brn>& aArgs) { OptionParser parser; OptionUint mx("-mx", "--mx", 1, "[1..5] number of second to spread response over"); parser.AddOption(&mx); OptionBool all("-a", "--all", "Search for all devices and services"); parser.AddOption(&all); OptionBool root("-r", "--root", "Search for root devices only"); parser.AddOption(&root); Brn emptyString(""); OptionString uuid("-u", "--uuid", emptyString, "[uuid string] search for a particular device"); parser.AddOption(&uuid); OptionString urn("-t", "--urn", emptyString, "Search for a device or service of the form [domain:[device|service]:type:ver]"); parser.AddOption(&urn); OptionBool refresh("-f", "--refresh", "Wait mx secs then refresh list"); parser.AddOption(&refresh); if (!parser.Parse(aArgs) || parser.HelpDisplayed()) { return; } // Debug::SetLevel(Debug::kDevice); DeviceListLogger logger; CpDeviceList* deviceList = NULL; FunctorCpDevice added = MakeFunctorCpDevice(logger, &DeviceListLogger::Added); FunctorCpDevice removed = MakeFunctorCpDevice(logger, &DeviceListLogger::Removed); if (all.Value()) { deviceList = new CpDeviceListUpnpAll(added, removed); } else if (root.Value()) { Print("Search root...\n"); deviceList = new CpDeviceListUpnpRoot(added, removed); } else if (uuid.Value().Bytes() > 0) { Print("Search uuid...\n"); deviceList = new CpDeviceListUpnpUuid(uuid.Value(), added, removed); } else if (urn.Value().Bytes() > 0) { Print("Search device/service...\n"); Brn domainName; Brn type; TUint ver; if (OpenHome::Net::Ssdp::ParseUrnDevice(urn.Value(), domainName, type, ver)) { deviceList = new CpDeviceListUpnpDeviceType(domainName, type, ver, added, removed); } else if (OpenHome::Net::Ssdp::ParseUrnService(urn.Value(), domainName, type, ver)) { deviceList = new CpDeviceListUpnpServiceType(domainName, type, ver, added, removed); } else { parser.DisplayHelp(); } } else { parser.DisplayHelp(); } Blocker* blocker = new Blocker; if (deviceList != NULL) { blocker->Wait(Stack::InitParams().MsearchTimeSecs()); } if (refresh.Value()) { Print("\nRefreshing...\n\n"); deviceList->Refresh(); blocker->Wait(Stack::InitParams().MsearchTimeSecs()); } delete blocker; delete deviceList; }
void OpenHome::TestFramework::Runner::Main(TInt aArgc, TChar* aArgv[], Net::InitialisationParams* aInitParams) { OptionParser parser; OptionUint adapter("-i", "--interface", 0, "index of network adapter to use"); parser.AddOption(&adapter); OptionBool send("-s", "--send", "Send"); parser.AddOption(&send); OptionString endpoint("-a", "--address", Brn("239.255.255.250"), "Multicast address"); parser.AddOption(&endpoint); OptionUint port("-p", "--port", 1968, "Multicast port"); parser.AddOption(&port); if (!parser.Parse(aArgc, aArgv) || parser.HelpDisplayed()) { return; } Net::UpnpLibrary::InitialiseMinimal(aInitParams); std::vector<NetworkAdapter*>* ifs = Os::NetworkListAdapters(*Net::gStack, Net::InitialisationParams::ELoopbackExclude, "TestMulticast"); ASSERT(ifs->size() > 0 && adapter.Value() < ifs->size()); TIpAddress addr = (*ifs)[adapter.Value()]->Address(); for (TUint i=0; i<ifs->size(); i++) { (*ifs)[i]->RemoveRef("TestMulticast"); } delete ifs; Endpoint endpt(0, addr); Endpoint::AddressBuf buf; endpt.AppendAddress(buf); Print("Using network interface %s\n\n", buf.Ptr()); Endpoint multicast(port.Value(), endpoint.Value()); if (send.Value() == false) { SocketUdpMulticast socket(addr, multicast); Endpoint actual(socket.Port(), multicast.Address()); Bws<100> buf2; actual.AppendEndpoint(buf2); Print("Receiving from multicast endpoint %s\n", buf2.Ptr()); Bwh message(10000); Endpoint sender = socket.Receive(message); Bws<100> buf3; sender.AppendEndpoint(buf3); if (message == Brn("Test message")) { Print("Received test messsge from %s\n", buf3.Ptr()); } else { Print("Received unrecognised messsge from %s\n", buf3.Ptr()); } } else { if (multicast.Port() == 0) { Print("Cannot send to port 0\n"); } else { Bws<100> buf2; multicast.AppendEndpoint(buf2); Print("Sending test message to %s\n", buf2.Ptr()); //SocketUdpMulticast socket(addr, multicast); SocketUdp socket(0, addr); socket.Send(Brn("Test message"), multicast); } } Net::UpnpLibrary::Close(); }
int CDECL main(int aArgc, char* aArgv[]) { OptionParser parser; OptionUint optionAdapter("-a", "--adapter", 0, "[adapter] index of network adapter to use"); parser.AddOption(&optionAdapter); OptionString optionRoom("-r", "--room", Brx::Empty(), "Room containing the receiver to play/stop"); parser.AddOption(&optionRoom); if (!parser.Parse(aArgc, aArgv)) { return 1; } gRoom.Replace(optionRoom.Value()); InitialisationParams* initParams = InitialisationParams::Create(); UpnpLibrary::Initialise(initParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[optionAdapter.Value()]->Subnet(); UpnpLibrary::DestroySubnetList(subnetList); UpnpLibrary::Close(); TUint channel = 0; TUint ttl = 4; TUint latency = 100; TBool multicast = false; TBool disabled = false; TUint preset = 99; THandle Songcast = SongcastCreate("av.openhome.org", subnet, channel, ttl, latency, multicast, !disabled, preset, loggerReceiver, 0, loggerSubnet, 0, loggerConfigurationChanged, 0, NULL, 0, "OpenHome", "http://www.openhome.org", "http://www.openhome.org", icon_png, icon_png_len, "image/png"); if (Songcast == 0) { printf("Songcast error\n"); return(1); } printf("preset = %d\n", preset); if (multicast) { printf("multicast\n"); } else { printf("unicast\n"); } if (disabled) { printf("disabled\n"); } else { printf("enabled\n"); } printf("q = quit, m = toggle multicast, e = toggle enabled\n"); for (;;) { int key = mygetch(); if (key == 'q') { break; } if (key == 'm') { if (multicast) { multicast = false; SongcastSetMulticast(Songcast, false); } else { multicast = true; SongcastSetMulticast(Songcast, true); } } if (key == 'e') { if (disabled) { disabled = false; SongcastSetEnabled(Songcast, true); } else { disabled = true; SongcastSetEnabled(Songcast, false); } } if (key == 'a') { SongcastSetSubnet(Songcast, 43200); // 192.168.0.0 } if (gRecv != 0) { if (key == 'p') { SongcastSetEnabled(Songcast, true); ReceiverPlay(gRecv); } if (key == 's') { ReceiverStop(gRecv); ReceiverStandby(gRecv); SongcastSetEnabled(Songcast, false); } } } if (gRecv != 0) { ReceiverRemoveRef(gRecv); } SongcastDestroy(Songcast); printf("\n"); return (0); }
void TestSsdpUListen(Environment& aEnv, const std::vector<Brn>& aArgs) { OptionParser parser; OptionUint mx("-mx", "--mx", 0, "[1..5] number of second to spread response over"); parser.AddOption(&mx); OptionUint adapter("-i", "--interface", 0, "index of network adapter to use"); parser.AddOption(&adapter); OptionBool all("-a", "--all", "Search for all devices and services"); parser.AddOption(&all); OptionBool root("-r", "--root", "Search for root devices only"); parser.AddOption(&root); Brn emptyString(""); OptionString uuid("-u", "--uuid", emptyString, "[uuid string] search for a particular device"); parser.AddOption(&uuid); OptionString urn("-t", "--urn", emptyString, "Search for a device or service of the form [domain:[device|service]:type:ver]"); parser.AddOption(&urn); if (!parser.Parse(aArgs) || parser.HelpDisplayed()) { return; } //Debug::SetLevel(Debug::kSsdpMulticast); TBool block = true; SsdpNotifyLoggerU logger; SsdpListenerUnicast* uListener = new SsdpListenerUnicast(aEnv, logger, NetworkIf(aEnv, adapter.Value())); uListener->Start(); if (all.Value()) { Print("Search all...\n"); uListener->MsearchAll(); } else if (root.Value()) { Print("Search root...\n"); uListener->MsearchRoot(); } else if (uuid.Value().Bytes() > 0) { Print("Search uuid...\n"); uListener->MsearchUuid(uuid.Value()); } else if (urn.Value().Bytes() > 0) { Print("Search device/service...\n"); Brn domainName; Brn deviceType; TUint ver; if (OpenHome::Net::Ssdp::ParseUrnDevice(urn.Value(), domainName, deviceType, ver)) { uListener->MsearchDeviceType(domainName, deviceType, ver); } else if (OpenHome::Net::Ssdp::ParseUrnService(urn.Value(), domainName, deviceType, ver)) { uListener->MsearchServiceType(domainName, deviceType, ver); } else { parser.DisplayHelp(); block = false; } } else { parser.DisplayHelp(); block = false; } if (block) { Blocker* blocker = new Blocker(aEnv); blocker->Wait(aEnv.InitParams()->MsearchTimeSecs()); delete blocker; } delete uListener; }
int main(int aArgc, char* aArgv[]) { OptionParser parser; OptionString optionRenderer("-r", "--renderer", Brn("dummy"), "Renderer module name."); parser.AddOption(&optionRenderer); if (!parser.Parse(aArgc, aArgv)) { return (1); } Net::InitialisationParams* initParams = Net::InitialisationParams::Create(); Net::Library* lib = new Net::Library(initParams); Net::DvStack* dvStack = lib->StartDv(); Brhz udn("device1"); Net::DvDeviceStandard* device = new Net::DvDeviceStandard(*dvStack, udn); SourceIndexHandler* sourceIndexHandler = new SourceIndexHandler(); StandbyHandler* standbyHandler = new StandbyHandler(); IRenderer* renderer = NULL; if (0 == strcmp((const char*)optionRenderer.Value().Ptr(), "dummy")) { renderer = new Dummy(lib->Env()); } #ifdef HAVE_VLC_VLC_H else { renderer = new Vlc(lib->Env()); } #endif std::vector<OpenHome::NetworkAdapter*>* subnetList = lib->CreateSubnetList(); TIpAddress adapter = (*subnetList)[0]->Address(); OpenHome::Net::Library::DestroySubnetList(subnetList); char url[1024]; char attributes[1024]; sprintf(url, "%d.%d.%d.%d", adapter&0xff, (adapter>>8)&0xff, (adapter>>16)&0xff, (adapter>>24)&0xff); Config::GetInstance().GetAbout().SetUrl(url); sprintf(url, "http://%s:%s/", url, kHttpPort); sprintf(attributes, "Info Time App:Config=%s Volume", url); Config::GetInstance().GetAbout().SetVersion(VERSION); unsigned long long size; const char* res = getResource("/renderer.js", &size); Config::GetInstance().RegisterController(res, size); Config::GetInstance().GetDataMapper().Append("/data/renderer.json", "renderer"); Player* player = new Player( renderer, *device, *standbyHandler, *sourceIndexHandler, true, attributes, "OpenHome", "OpenHome Consortium", "http://openhome.org", "", "OpenHome Media Player", "", "", "", Config::GetInstance().GetString("device", "room").c_str(), Config::GetInstance().GetString("device", "name").c_str(), "", url, ""); SourcePlaylist* sourcePlaylist = new SourcePlaylist(*device, kTracksMax, kProtocolInfo, *player); player->AddSource(sourcePlaylist); device->SetEnabled(); char c = '\0'; while (c != 'q') { if(scanf("%c", &c)) ; } Log::Print("Quiting...\n"); delete sourcePlaylist; delete device; delete sourceIndexHandler; delete standbyHandler; delete player; Log::Print("Exit complete\n"); return (0); }
int CDECL main(int aArgc, char* aArgv[]) { OptionParser parser; OptionUint optionAdapter("-a", "--adapter", 0, "[adapter] index of network adapter to use"); parser.AddOption(&optionAdapter); OptionUint optionTtl("-t", "--ttl", 1, "[ttl] ttl"); parser.AddOption(&optionTtl); OptionString optionUri("-u", "--uri", Brn("mpus://0.0.0.0:0"), "[uri] uri of the sender"); parser.AddOption(&optionUri); if (!parser.Parse(aArgc, aArgv)) { return (1); } InitialisationParams* initParams = InitialisationParams::Create(); UpnpLibrary::Initialise(initParams); std::vector<NetworkAdapter*>* subnetList = UpnpLibrary::CreateSubnetList(); TIpAddress subnet = (*subnetList)[optionAdapter.Value()]->Subnet(); TIpAddress adapter = (*subnetList)[optionAdapter.Value()]->Address(); UpnpLibrary::DestroySubnetList(subnetList); printf("Using subnet %d.%d.%d.%d\n", subnet&0xff, (subnet>>8)&0xff, (subnet>>16)&0xff, (subnet>>24)&0xff); TUint ttl = optionTtl.Value(); Brhz uri(optionUri.Value()); OhmReceiverDriver* driver = new OhmReceiverDriver(); OhmReceiver* receiver = new OhmReceiver(adapter, ttl, *driver); UpnpLibrary::StartCp(subnet); printf("q = quit\n"); Debug::SetLevel(Debug::kMedia); for (;;) { int key = mygetch(); if (key == 'q') { printf("QUIT\n"); break; } else if (key == 'p') { printf("PLAY %s\n", uri.CString()); receiver->Play(uri); } else if (key == 's') { printf("STOP\n"); receiver->Stop(); } } delete(receiver); UpnpLibrary::Close(); printf("\n"); return (0); }