示例#1
0
THandle STDCALL SongcastCreate(const char* aDomain, uint32_t aSubnet, uint32_t aChannel, uint32_t aTtl, uint32_t aLatency, uint32_t aMulticast, uint32_t aEnabled, uint32_t aPreset, ReceiverCallback aReceiverCallback, void* aReceiverPtr, SubnetCallback aSubnetCallback, void* aSubnetPtr, ConfigurationChangedCallback aConfigurationChangedCallback, void* aConfigurationChangedPtr, MessageCallback aFatalErrorCallback, void* aFatalErrorPtr, MessageCallback aLogOutputCallback, void* aLogOutputPtr, const char* aManufacturer, const char* aManufacturerUrl, const char* aModelUrl, void* aImagePtr, uint32_t aImageBytes, const char* aMimeType)
{
	try {
        printf("%s\n", aDomain);
        
        // get the computer name
        Bws<Songcast::kMaxUdnBytes> computer;
        TUint bytes = computer.MaxBytes();

        if (!GetComputerName((LPSTR)computer.Ptr(), (LPDWORD)&bytes)) {
            THROW(SongcastError);
        }
        
        computer.SetBytes(bytes);
        
		TBool enabled = (aEnabled == 0) ? false : true;
		TBool multicast = (aMulticast == 0) ? false : true;

        // create the sender driver
        OhmSenderDriverWindows* driver = new OhmSenderDriverWindows(aDomain, aManufacturer, enabled);

        // create the soundcard
		Songcast* songcast = new Songcast(aSubnet, aChannel, aTtl, aLatency, multicast, enabled, aPreset, aReceiverCallback, aReceiverPtr, aSubnetCallback, aSubnetPtr, aConfigurationChangedCallback, aConfigurationChangedPtr, aFatalErrorCallback, aFatalErrorPtr, aLogOutputCallback, aLogOutputPtr, computer, driver, aManufacturer, aManufacturerUrl, aModelUrl, Brn((TByte*) aImagePtr, aImageBytes), Brn(aMimeType));

		driver->SetSongcast(*songcast);

		return (songcast);
	}
	catch (SongcastError)
    {
	}

	return (0);
}
示例#2
0
void OpenHome::Net::Invocation::Output(IAsyncOutput& aConsole)
{
    AutoMutex a(iLock); /* using iLock doesn't prevent logging for multiple invocations overlapping
                           Using iCpStack.Env().Mutex() causes problems though as the call to
                           ServiceType().FullName() below also uses the Environment's mutex and we
                           can't easily use a different mutex there.
                           If we later want to prevent overlapped output, it'd be best to add a
                           shared logging mutex to Environment */
    Bws<Ascii::kMaxUintStringBytes+1> buf;
    (void)Ascii::AppendDec(buf, iSequenceNumber);
    buf.PtrZ();
    aConsole.Output("SequenceNumber", (const TChar*)buf.Ptr());
    aConsole.Output("Service", (const TChar*)ServiceType().FullName().Ptr());
    aConsole.Output("Action", (const TChar*)iAction->Name().Ptr());
    TUint count = (TUint)iInput.size();
    for (TUint i=0; i<count; i++) {
        OutputArgument(aConsole, "InputArg", *(iInput[i]));
    }
    if (Error()) {
        iError.Output(aConsole);
    }
    else if (iCompleted) {
        count = (TUint)iOutput.size();
        for (TUint i=0; i<count; i++) {
            OutputArgument(aConsole, "OutputArg", *(iOutput[i]));
        }
    }
}
void NetworkAdapterList::TraceAdapter(const TChar* aPrefix, NetworkAdapter& aAdapter)
{ // static
    Endpoint ep(0, aAdapter.Address());
    Bws<Endpoint::kMaxAddressBytes> addr;
    ep.AppendAddress(addr);
    LOG(kTrace, "%s: %s(%s)\n", aPrefix, aAdapter.Name(), (const TChar*)addr.Ptr());
}
示例#4
0
InvocationManager::InvocationManager(CpStack& aCpStack)
    : Thread("InvocationManager")
    , iCpStack(aCpStack)
    , iLock("INVM")
    , iFreeInvocations(aCpStack.Env().InitParams()->NumInvocations())
    , iWaitingInvocations(aCpStack.Env().InitParams()->NumInvocations())
    , iFreeInvokers(aCpStack.Env().InitParams()->NumActionInvokerThreads())
{
    TUint i;
    iInvokers = (Invoker**)malloc(sizeof(*iInvokers) * iCpStack.Env().InitParams()->NumActionInvokerThreads());
    for (i=0; i<iCpStack.Env().InitParams()->NumActionInvokerThreads(); i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("ActionInvoker %d", i);
        thName.PtrZ();
        iInvokers[i] = new Invoker((const TChar*)thName.Ptr(), iFreeInvokers);
        iFreeInvokers.Write(iInvokers[i]);
        iInvokers[i]->Start();
    }

    for (i=0; i<iCpStack.Env().InitParams()->NumInvocations(); i++) {
        iFreeInvocations.Write(new OpenHome::Net::Invocation(iCpStack, iFreeInvocations));
    }
    iActive = true;
    Start();
}
示例#5
0
文件: Error.cpp 项目: ACDN/ohNet
void Error::Output(IAsyncOutput& aConsole)
{
    aConsole.Output("ErrorLevel", LevelName());
    Bws<Ascii::kMaxUintStringBytes+1> buf;
    (void)Ascii::AppendDec(buf, iCode);
    buf.PtrZ();
    aConsole.Output("ErrorCode", (const TChar*)buf.Ptr());
    aConsole.Output("ErrorDescription", Description());
}    
示例#6
0
EventServerUpnp::EventServerUpnp(CpStack& aCpStack, TIpAddress aInterface)
    : iTcpServer(aCpStack.Env(), "EventServer", aCpStack.Env().InitParams()->CpUpnpEventServerPort(), aInterface)
{
    const TUint numThread = aCpStack.Env().InitParams()->NumEventSessionThreads();
    for (TUint i=0; i<numThread; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("EventSession %d", i);
        thName.PtrZ();
        iTcpServer.Add((const TChar*)thName.Ptr(), new EventSessionUpnp(aCpStack));
    }
}
示例#7
0
EventServerUpnp::EventServerUpnp(CpStack& aCpStack, TIpAddress aInterface)
    : iTcpServer(aCpStack.Env(), "EventServer", aCpStack.Env().InitParams()->CpUpnpEventServerPort(), aInterface)
{
    const TUint numThread = aCpStack.Env().InitParams()->NumEventSessionThreads();
#ifndef _WIN32
    // nothing terribly bad would happen if this assertion failed so its not worth a separate Windows implementation
    ASSERT(numThread < 10);
#endif
    for (TUint i=0; i<numThread; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("EventSession %d", i);
        thName.PtrZ();
        iTcpServer.Add((const TChar*)thName.Ptr(), new EventSessionUpnp(aCpStack));
    }
}
示例#8
0
void XmlFetch::Output(IAsyncOutput& aConsole)
{
    Mutex& lock = iCpStack.Env().Mutex();
    lock.Wait();
    Bws<Ascii::kMaxUintStringBytes+1> buf;
    (void)Ascii::AppendDec(buf, iSequenceNumber);
    buf.PtrZ();
    aConsole.Output("SequenceNumber", (const TChar*)buf.Ptr());
    Bws<Uri::kMaxUriBytes+1> uri(iUri->AbsoluteUri());
    uri.PtrZ();
    aConsole.Output("XmlFetch", (const TChar*)uri.Ptr());
    if (Error()) {
        iError.Output(aConsole);
    }
    lock.Signal();
}
示例#9
0
void LogMsg(const char *format, ...)
{
#ifdef DEFINE_TRACE
    va_list args;
    va_start(args, format);
    // not all messages are errors but enough are that its handy to log everything here if we're interested in errors
    if(Debug::TestLevel(Debug::kBonjour) || Debug::TestLevel(Debug::kError)) {
        Bws<kMaxLogMsgBytes> msg;
        TUint written = mDNS_vsnprintf((char*)msg.Ptr(), msg.MaxBytes(), format, args);
        msg.SetBytes(written);
        Log::Print(msg);
        Log::Print("\n");
    }
    va_end(args);
#endif
}
示例#10
0
SocketTcpServer* DviServerLpec::CreateServer(const NetworkAdapter& aNif)
{
    SocketTcpServer* server = new SocketTcpServer(iDvStack.Env(), "LpecServer", iPort, aNif.Address());
    const TUint numThreads = iDvStack.Env().InitParams()->DvNumLpecThreads();
    AdapterData* ad = new AdapterData(aNif.Address());
    iAdapterData.push_back(ad);
    for (TUint i=0; i<numThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("LpecSession %d", i);
        thName.PtrZ();
        DviSessionLpec* session = new DviSessionLpec(iDvStack, aNif.Address(), iPort);
        server->Add((const TChar*)thName.Ptr(), session);
        ad->iSessions.push_back(session);
    }
    return server;
}
示例#11
0
TChar* CpListenerMsearch::CreateTypeString(const Brx& aDomain, const Brx& aType, TUint aVersion)
{
    TChar* type = (TChar*)malloc(aDomain.Bytes() + aType.Bytes() + 2 + Ascii::kMaxUintStringBytes + 1);
    TChar* ptr = type;
    (void)strncpy(ptr, (const TChar*)aDomain.Ptr(), aDomain.Bytes());
    ptr += aDomain.Bytes();
    *ptr = ':';
    ptr++;
    (void)strncpy(ptr, (const TChar*)aType.Ptr(), aType.Bytes());
    ptr += aType.Bytes();
    *ptr = ':';
    ptr++;
    Bws<Ascii::kMaxUintStringBytes> ver;
    Ascii::AppendDec(ver, aVersion);
    (void)strncpy(ptr, (const TChar*)ver.Ptr(), ver.Bytes());
    ptr += ver.Bytes();
    *ptr = '\0';
    return type;
}
示例#12
0
DviSubscriptionManager::DviSubscriptionManager(DvStack& aDvStack)
    : Thread("DvSubscriptionMgr")
    , iDvStack(aDvStack)
    , iLock("DSBM")
    , iFree(aDvStack.Env().InitParams()->DvNumPublisherThreads())
{
    const TUint numPublisherThreads = iDvStack.Env().InitParams()->DvNumPublisherThreads();
    LOG(kDvEvent, "> DviSubscriptionManager: creating %u publisher threads\n", numPublisherThreads);
    iPublishers = (Publisher**)malloc(sizeof(*iPublishers) * numPublisherThreads);
    for (TUint i=0; i<numPublisherThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("Publisher %d", i);
        thName.PtrZ();
        iPublishers[i] = new Publisher((const TChar*)thName.Ptr(), iFree);
        iFree.Write(iPublishers[i]);
        iPublishers[i]->Start();
    }
    Start();
}
示例#13
0
XmlFetchManager::XmlFetchManager(CpStack& aCpStack)
    : Thread("XmlFetchManager")
    , iCpStack(aCpStack)
    , iLock("FETL")
    , iFree(iCpStack.Env().InitParams()->NumXmlFetcherThreads())
{
    const TUint numThreads = iCpStack.Env().InitParams()->NumXmlFetcherThreads();
    iFetchers = (XmlFetcher**)malloc(sizeof(*iFetchers) * numThreads);
    for (TUint i=0; i<numThreads; i++) {
        Bws<Thread::kMaxNameBytes+1> thName;
        thName.AppendPrintf("XmlFetcher %d", i);
        thName.PtrZ();
        iFetchers[i] = new XmlFetcher((const TChar*)thName.Ptr(), iFree);
        iFree.Write(iFetchers[i]);
        iFetchers[i]->Start();
    }

    iActive = true;
    Start();
}
示例#14
0
void SuiteUnicast::Receiver()
{
    TBool first = true;
    iLastVal = 0;
    TUint val;
    Bws<kMsgBytes> recv;
    do {
        recv.SetBytes(0);
        (void)iReceiver->Receive(recv);
        ASSERT(recv.Bytes() >= sizeof(TUint32));
        val = *((TUint32*)recv.Ptr());
        if (val != kQuit) {
            if (first) {
                TEST(val == 0);
                first = false;
            }
            else {
                TEST(val == iLastVal+1);
            }
        }
        //Print("Received %u, last sent %u\n", val, iSendVal);
        iLastVal = val;
    } while (val != kQuit);
}
示例#15
0
Soundcard::Soundcard(TIpAddress /* aSubnet */, TUint aChannel, TUint aTtl, TBool aMulticast, TBool aEnabled, TUint aPreset, ReceiverCallback aReceiverCallback, void* aReceiverPtr)
	: iReceiverCallback(aReceiverCallback)
	, iReceiverPtr(aReceiverPtr)
{
	InitialisationParams* initParams = InitialisationParams::Create();

	UpnpLibrary::Initialise(initParams);

	std::vector<NetworkInterface*>* list = UpnpLibrary::SubnetList();

	ASSERT(list->size() > 0);

	NetworkInterface* iface = *list->begin();

	delete (list);

	UpnpLibrary::SetCurrentSubnet(*iface);

	printf("Using %x\n", iface->Address());
    
    UpnpLibrary::StartCombined();

	Bws<kMaxUdnBytes> computer;
	Bws<kMaxUdnBytes> udn;
	Bws<kMaxUdnBytes + 1> friendly;

	TUint bytes = computer.MaxBytes();

	if (!GetComputerName((LPSTR)computer.Ptr(), (LPDWORD)&bytes)) {
		THROW(SoundcardError);
	}

	computer.SetBytes(bytes);
	udn.Replace("ohSoundcard-");
	udn.Append(computer);
	friendly.Replace(udn);
	friendly.Append('\0');

	iDevice = new DvDeviceStandard(udn);
    
	iDevice->SetAttribute("Upnp.Domain", "av.openhome.org");
    iDevice->SetAttribute("Upnp.Type", "Soundcard");
    iDevice->SetAttribute("Upnp.Version", "1");
    iDevice->SetAttribute("Upnp.FriendlyName", (TChar*)friendly.Ptr());
    iDevice->SetAttribute("Upnp.Manufacturer", "Openhome");
    iDevice->SetAttribute("Upnp.ManufacturerUrl", "http://www.openhome.org");
    iDevice->SetAttribute("Upnp.ModelDescription", "OpenHome Soundcard");
    iDevice->SetAttribute("Upnp.ModelName", "ohSoundcard");
    iDevice->SetAttribute("Upnp.ModelNumber", "1");
    iDevice->SetAttribute("Upnp.ModelUrl", "http://www.openhome.org");
    iDevice->SetAttribute("Upnp.SerialNumber", "");
    iDevice->SetAttribute("Upnp.Upc", "");

    iDriver = new OhmSenderDriverWindows();
    
	Brn icon(icon_png, icon_png_len);

	iSender = new OhmSender(*iDevice, *iDriver, computer, aChannel, iface->Address(), aTtl, aMulticast, aEnabled, icon, Brn("image/png"), aPreset);
	
    iDevice->SetEnabled();

	iReceiverManager = new ReceiverManager3(*this, iSender->SenderUri(), iSender->SenderMetadata());
}
示例#16
0
void OpenHome::UnhandledExceptionHandler(std::exception& aException)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s in thread %s\n", aException.what(), thName.Ptr());
    CallFatalErrorHandler(buf);
}
示例#17
0
void OpenHome::UnhandledExceptionHandler(Exception& aException)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s at %s:%lu in thread %s\n", aException.Message(), aException.File(), (unsigned long)aException.Line(), thName.Ptr());

    TInt len = 8*1024;
    char* msg = new char[len];
    if (msg != NULL) {
        (void)strncpy(msg, buf, len);
        len -= (TInt)strlen(buf);
        (void)strncat(msg, "\n", len);
        len -= 2;

        THandle stackTrace = aException.StackTrace();
        TUint count = Os::StackTraceNumEntries(stackTrace);
        for (TUint i=0; i<count; i++) {
            const char* entry = Os::StackTraceEntry(stackTrace, i);
            (void)strncat(msg, entry, len);
            len -= (TInt)strlen(entry) + 2;
            if (len < 0) {
                break;
            }
            (void)strncat(msg, "\n", len);
        }
    }
    if (len > 0) {
        (void)strncat(msg, "\n", len);
    }

    CallFatalErrorHandler((msg!=NULL? msg : buf));
    delete msg;
}
示例#18
0
void OpenHome::UnhandledExceptionHandler(const TChar* aExceptionMessage, const TChar* aFile, TUint aLine)
{
    Bws<5> thName;
    GetThreadName(thName);
    char buf[1024];
    (void)snprintf(buf, sizeof(buf), "Unhandled exception %s at %s:%lu in thread %s\n", aExceptionMessage, aFile, (unsigned long)aLine, thName.Ptr());
    CallFatalErrorHandler(buf);
}