
/*-----------------------------------------------------------------------------------------------*/
/* signaling.cpp                                                                                 */
/* copyright (c) innovaphone 2016                                                                */
/*                                                                                               */
/*-----------------------------------------------------------------------------------------------*/

#include <platform.h>
#include "sdk/common/os/iomux.h"
#include "sdk/common/interface/socket.h"
#include "sdk/common/interface/webserver_plugin.h"
#include "sdk/common/interface/dns.h"
#include "sdk/common/interface/appwebsocket_client.h"
#include "sdk/common/interface/media.h"
#include "sdk/common/interface/ringer.h"
#include "sdk/common/interface/network.h"
#include "sdk/common/interface/appsharing.h"
#include "sdk/common/interface/remote_services.h"
#include "sdk/common/lib/appservice.h"
#include "sdk/common/build/release.h"

#include "apps/signaling/signaling_api.h"

int main(int argc, char *argv[])
{
    class IIoMux * iomux = IIoMux::Create();
	ISocketProvider * localSocketProvider = CreateLocalSocketProvider();
    IWebserverPluginProvider * webserverPluginProvider = CreateWebserverPluginProvider();
    ISocketProvider * udpSocketProvider = CreateUDPSocketProvider();
    ISocketProvider * tcpSocketProvider = CreateTCPSocketProvider();
    ISocketProvider * tlsSocketProvider = CreateTLSSocketProvider(tcpSocketProvider);
    IDns * dns = IDns::Create(iomux);
    IAppWebsocketClientProvider * appWebsocketClientProvider = CreateAppWebsocketClientProvider(iomux, tcpSocketProvider, tlsSocketProvider, dns);
    class IMediaProvider * mediaProvider = CreateMediaProvider();
    class SignalingMediaConfig * mediaConfig = new SignalingMediaConfig(udpSocketProvider, tcpSocketProvider, tlsSocketProvider, 0, 50000, 50099, 50100, 50199);
    class IAudioIo * audioIo = IAudioIo::Create(iomux, 0, 0);
    class IRinger * ringer = IRinger::Create(iomux, 0);
    class IVideoIo * videoIo = IVideoIo::Create(iomux, 0, 0);

    AppServiceArgs  serviceArgs;
    serviceArgs.serviceID = "signaling";
    serviceArgs.Parse(argc, argv);
    AppInstanceArgs instanceArgs;
    instanceArgs.appName = "signaling";
    instanceArgs.appDomain = "example.com";
    instanceArgs.appPassword = "pwd";
    instanceArgs.webserver = "/var/run/webserver/webserver";
    instanceArgs.webserverPath = "/signaling";
    instanceArgs.dbHost = "";
    instanceArgs.dbName = "signaling";
    instanceArgs.dbUser = "signaling";
    instanceArgs.dbPassword = "signaling";
    instanceArgs.Parse(argc, argv);
	
    ISignalingService * service = ISignalingService::CreateSignaling(iomux, localSocketProvider, webserverPluginProvider, appWebsocketClientProvider, mediaProvider, mediaConfig, audioIo, ringer, videoIo, NULL, NULL, NULL, NULL, NULL, &serviceArgs);
    if (!serviceArgs.manager) service->IAppStart(&instanceArgs);
    iomux->Run();

    delete service;
	delete localSocketProvider;
    delete webserverPluginProvider;
    delete tcpSocketProvider;
    delete tlsSocketProvider;
    delete dns;
    delete iomux;
    delete debug;
    
    return 0;
}
