Initialisation options
Most options apply equally to Control Point and Device stacks. Any functions that are specific to a particular stack include either 'Cp' or 'Dv'
Example #1
0
        /// <summary>
        /// Create the library instance.
        /// </summary>
        /// <remarks>Only one instance per process is allowed.
        /// This must be called before any other library function.</remarks>
        public static Library Create(InitParams aParams)
        {
            Library instance = new Library();

            instance.Initialise(aParams);
            return(instance);
        }
Example #2
0
        static int Main()
        {
            BasicConfigurator.Configure();
            InitParams initParams = new InitParams {UseLoopbackNetworkAdapter = true};
            string nodeGuid = Guid.NewGuid().ToString();
            using (Library library = Library.Create(initParams))
            {
                SubnetList subnetList = new SubnetList();
                NetworkAdapter nif = subnetList.SubnetAt(0);
                uint subnet = nif.Subnet();
                subnetList.Dispose();
                var combinedStack = library.StartCombined(subnet);
                AppServices services = new AppServices
                                           {
                                               NodeRebooter = new NullNodeRebooter(),
                                               DeviceFactory = new DvDeviceFactory(combinedStack.DeviceStack)
                                           };
                string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string storePath = Path.Combine(exePath, "test-store");
                ConfigFileCollection config = new ConfigFileCollection(new string[] { });
                config.AddFile("config.xml",
                    new XElement("ohos",
                        new XElement("system-settings",
                            new XElement("store", storePath)
                        )
                    )
                );
                if (Directory.Exists(storePath))
                {
                    Directory.Delete(storePath, true);
                }
                using (var installModule = new AppShellModule(services, config, null, nodeGuid))
                {
                    installModule.AppShell.Start();

                    installModule.AppShell.Install(Path.Combine(exePath, "ohOs.TestApp1.zip"));

                    List<AppInfo> apps = installModule.AppShell.GetApps().ToList();
                    if (apps.Count!=1)
                    {
                        Console.Error.WriteLine("There should be one app installed. (Found {0}.)", apps.Count);
                        return 1;
                    }
                    if (apps[0].Name!="ohOs.TestApp1")
                    {
                        Console.Error.WriteLine("Wrong app name. (Got '{0}'.)", apps[0].Name);
                        PrintAppState(apps[0]);
                        return 1;
                    }
                    if (apps[0].State!=AppState.Running)
                    {
                        Console.Error.WriteLine("App should be running. (It isn't.)");
                        PrintAppState(apps[0]);
                        return 1;
                    }

                }
            }
            return 0;
        }
        public static void Main(string[] args)
        {
            InitParams initParams = new InitParams
            {
                MsearchTimeSecs = 1,
                UseLoopbackNetworkAdapter = true
            };
            using (Library lib = Library.Create(initParams))
            {
                SubnetList subnetList = new SubnetList();
                NetworkAdapter nif = subnetList.SubnetAt(0);
                uint subnet = nif.Subnet();
                subnetList.Dispose();
                lib.StartCombined(subnet);

                Console.Write("TestCpDeviceDvCs - starting\n");
                DeviceBasic device = new DeviceBasic();
                CpDeviceDv cpDevice = new CpDeviceDv(device.Device());
                TestBasicCp cp = new TestBasicCp(cpDevice);
                cp.TestActions();
                cp.TestSubscriptions();
                cpDevice.RemoveRef();
                device.Dispose();
                Console.Write("TestCpDeviceDvCs - completed\n");
            }
        }
Example #4
0
 public static void Main(string[] args)
 {
     Core.InitParams initParams = new Core.InitParams();
     Core.Library lib = new Core.Library();
     lib.Initialise(initParams);
     lib.StartCp();
     new Runner((int)initParams.MsearchTimeSecs);
     lib.Close();
 }
Example #5
0
 public static void Main(string[] args)
 {
     Console.WriteLine("TestPerformanceDvCs - starting ('q' to quit)");
     InitParams initParams = new InitParams();
     using (Library lib = Library.Create(initParams))
     {
         lib.StartDv();
         DeviceBasic device = new DeviceBasic();
         while (Console.ReadKey(true).KeyChar != 'q') ;
         device.Dispose();
     }
 }
Example #6
0
 public static void Main(string[] args)
 {
     InitParams initParams = new InitParams
     {
         MsearchTimeSecs = 1,
         UseLoopbackNetworkInterface = true
     };
     Library lib = new Library();
     lib.Initialise(initParams);
     lib.StartCombined();
     new Runner();
     lib.Close();
 }
Example #7
0
 public static void Main(string[] args)
 {
     Core.InitParams initParams = new Core.InitParams();
     using (Core.Library lib = Core.Library.Create(initParams))
     {
         Core.SubnetList     subnetList = new Core.SubnetList();
         Core.NetworkAdapter nif        = subnetList.SubnetAt(0);
         uint subnet = nif.Subnet();
         Console.WriteLine("Using adapter: {0}", nif.Name());
         subnetList.Dispose();
         lib.StartCp(subnet);
         new Runner((int)initParams.MsearchTimeSecs);
     }
 }
Example #8
0
 public static void Main(string[] args)
 {
     Core.InitParams initParams = new Core.InitParams();
     using (Core.Library lib = Core.Library.Create(initParams))
     {
         Core.SubnetList subnetList = new Core.SubnetList();
         Core.NetworkAdapter nif = subnetList.SubnetAt(0);
         uint subnet = nif.Subnet();
         Console.WriteLine("Using adapter: {0}", nif.Name());
         subnetList.Dispose();
         lib.StartCp(subnet);
         new Runner((int)initParams.MsearchTimeSecs);
     }
 }
Example #9
0
 public static void Main(string[] args)
 {
     // !!!! add OptionParser class rather than relying on the user guessing that the first arg
     // is an int 1..3 and the second is the path of a folder that'll serve a test UI
     Core.InitParams initParams = new Core.InitParams();
     using (Core.Library lib = Core.Library.Create(initParams))
     {
         lib.StartDv();
         Console.Write("TestDvLights - starting\n");
         DeviceLights device  = new DeviceLights(Convert.ToInt32(args[0]), args[1]);
         Semaphore    blocker = new Semaphore(0, 1);
         blocker.WaitOne(60 * 60 * 1000); // make the device available for 1 hour then assume we've been forgotten about and exit
         device.Dispose();
         Console.Write("TestDvLights - exiting\n");
     }
 }
Example #10
0
 public Runner()
 {
     iInitParams = new InitParams();
     iInitParams.DvUpnpWebServerPort = 0;
     iInitParams.LogOutput = new MessageListener(Log);
     iInitParams.SubnetListChangedListener = new ChangedListener(SubnetListChanged);
     iInitParams.SubnetAddedListener = new NetworkAdapterListener(SubnetAdded);
     iInitParams.SubnetRemovedListener = new NetworkAdapterListener(SubnetRemoved);
     iInitParams.NetworkAdapterChangedListener = new NetworkAdapterListener(NetworkAdapterChanged);
     iLibrary = Library.Create(iInitParams);
     Library.SetDebugLevel(Library.DebugLevel.Trace);
     SubnetList subnetList = new SubnetList();
     NetworkAdapter nif = subnetList.SubnetAt(0);
     uint subnet = nif.Subnet();
     subnetList.Dispose();
     iLibrary.StartCombined(subnet);
 }
Example #11
0
 public static void Main(string[] args)
 {
     InitParams initParams = new InitParams
     {
         MsearchTimeSecs = 1,
         UseLoopbackNetworkAdapter = true,
         DvUpnpWebServerPort = 0
     };
     using (Library lib = Library.Create(initParams))
     {
         SubnetList subnetList = new SubnetList();
         NetworkAdapter nif = subnetList.SubnetAt(0);
         uint subnet = nif.Subnet();
         subnetList.Dispose();
         lib.StartCombined(subnet);
         new Runner();
     }
 }
Example #12
0
        private void Initialise(InitParams aParams)
        {
            iLogOutput                     = aParams.LogOutput;
            iFatalErrorHandler             = aParams.FatalErrorHandler;
            iAsyncBeginHandler             = aParams.AsyncBeginHandler;
            iAsyncEndHandler               = aParams.AsyncEndHandler;
            iAsyncErrorHandler             = aParams.AsyncErrorHandler;
            iSubnetListChangedListener     = aParams.SubnetListChangedListener;
            iSubnetAddedListener           = aParams.SubnetAddedListener;
            iSubnetRemovedListener         = aParams.SubnetRemovedListener;
            iNetworkAdapterChangedListener = aParams.NetworkAdapterChangedListener;
            IntPtr nativeInitParams = aParams.AllocNativeInitParams(IntPtr.Zero);

            OhNetInitParamsSetFreeExternalCallback(nativeInitParams, FreeMemory);
            if (0 != OhNetLibraryInitialise(nativeInitParams))
            {
                InitParams.FreeNativeInitParams(nativeInitParams);
                throw new LibraryException();
            }
        }
Example #13
0
        public static void Main(string[] args)
        {
            InitParams initParams = new InitParams
            {
                MsearchTimeSecs = 1,
                UseLoopbackNetworkInterface = true
            };
            Library lib = new Library();
            lib.Initialise(initParams);
            lib.StartCombined();

            Console.Write("TestCpDeviceDvCs - starting\n");
            DeviceBasic device = new DeviceBasic();
            CpDeviceDv cpDevice = new CpDeviceDv(device.Device());
            TestBasicCp cp = new TestBasicCp(cpDevice);
            cp.TestActions();
            cp.TestSubscriptions();
            cpDevice.RemoveRef();
            device.Dispose();
            Console.Write("TestCpDeviceDvCs - completed\n");

            lib.Close();
        }
Example #14
0
        public override void init()
        {
            mh = new InitParams.MessageHandler(mhCb);
                ml = new MessageListener(mh);

                OpenHome.Net.Core.InitParams initParams = new OpenHome.Net.Core.InitParams();
                OpenHome.Net.Core.Library.SetDebugLevel(Library.DebugLevel.Error);
                initParams.LogOutput = ml;
                lib = OpenHome.Net.Core.Library.Create(initParams);
                OpenHome.Net.Core.SubnetList subnetList = new OpenHome.Net.Core.SubnetList();
                OpenHome.Net.Core.NetworkAdapter nif = subnetList.SubnetAt((uint)networkConnectInfo.subNetIndex);
                this.delegateStartingNetwork(nif.FullName());
                uint subnet = nif.Subnet();
                subnetList.Dispose();
                lib.StartCp(subnet);
        }
Example #15
0
 private Library(InitParams aParams)
 {
     iInitParams = aParams;
 }
Example #16
0
 public ChangedListener(InitParams.ChangeHandler aHandler)
 {
     iHandler = aHandler;
 }
Example #17
0
 public NetworkAdapterListener(InitParams.NetworkAdapterHandler aHandler)
 {
     iHandler = aHandler;
 }
Example #18
0
 public MessageListener(InitParams.MessageHandler aHandler)
 {
     iHandler = aHandler;
 }
Example #19
0
 public AsyncListener(InitParams.AsyncHandler aHandler)
 {
     iHandler = aHandler;
 }
Example #20
0
 public static void Main(string[] args)
 {
     // !!!! add OptionParser class rather than relying on the user guessing that the first arg
     // is an int 1..3 and the second is the path of a folder that'll serve a test UI
     Core.InitParams initParams = new Core.InitParams();
     using (Core.Library lib = Core.Library.Create(initParams))
     {
         lib.StartDv();
         Console.Write("TestDvLights - starting\n");
         DeviceLights device = new DeviceLights(Convert.ToInt32(args[0]), args[1]);
         Semaphore blocker = new Semaphore(0, 1);
         blocker.WaitOne(60 * 60 * 1000); // make the device available for 1 hour then assume we've been forgotten about and exit
         device.Dispose();
         Console.Write("TestDvLights - exiting\n");
     }
 }
Example #21
0
 private void Initialise(InitParams aParams)
 {
     iLogOutput = aParams.LogOutput;
     iFatalErrorHandler = aParams.FatalErrorHandler;
     iAsyncBeginHandler = aParams.AsyncBeginHandler;
     iAsyncEndHandler = aParams.AsyncEndHandler;
     iAsyncErrorHandler = aParams.AsyncErrorHandler;
     iSubnetListChangedListener = aParams.SubnetListChangedListener;
     iSubnetAddedListener = aParams.SubnetAddedListener;
     iSubnetRemovedListener = aParams.SubnetRemovedListener;
     iNetworkAdapterChangedListener = aParams.NetworkAdapterChangedListener;
     IntPtr nativeInitParams = aParams.AllocNativeInitParams(IntPtr.Zero);
     OhNetInitParamsSetFreeExternalCallback(nativeInitParams, FreeMemory);
     if (0 != OhNetLibraryInitialise(nativeInitParams))
     {
         InitParams.FreeNativeInitParams(nativeInitParams);
         throw new LibraryException();
     }
 }
Example #22
0
 public NetworkAdapterListener(InitParams.NetworkAdapterHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallbackNetworkAdapter(NetworkAdapter);
 }
Example #23
0
 public ChangedListener(InitParams.ChangeHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallback(Changed);
 }
Example #24
0
 /// <summary>
 /// Create the library instance.
 /// </summary>
 /// <remarks>Only one instance per process is allowed.
 /// This must be called before any other library function.</remarks>
 public static Library Create(InitParams aParams)
 {
     Library instance = new Library();
     instance.Initialise(aParams);
     return instance;
 }
Example #25
0
File: OhNet.cs Project: hacx/ohNet
 private void Initialise(InitParams aParams)
 {
     IntPtr nativeInitParams = aParams.AllocNativeInitParams(IntPtr.Zero);
     iCallbackFreeMemory = new CallbackFreeMemory(FreeMemory);
     OhNetInitParamsSetFreeExternalCallback(nativeInitParams, iCallbackFreeMemory);
     if (0 != OhNetLibraryInitialise(nativeInitParams))
     {
         InitParams.FreeNativeInitParams(nativeInitParams);
         throw new LibraryException();
     }
 }
Example #26
0
 public MessageListener(InitParams.MessageHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallbackMsg(Message);
 }
Example #27
0
 private Library(InitParams aParams)
 {
     iInitParams = aParams;
 }
Example #28
0
 public AsyncListener(InitParams.AsyncHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallbackAsync(AsyncListenerCallback);
 }
Example #29
0
        public static void Main(string[] aArgs)
        {
            Console.WriteLine("TestPerformanceCpCs - starting");
            InitParams initParams = new InitParams();
            using (Library lib = Library.Create(initParams))
            {
                SubnetList subnetList = new SubnetList();
                NetworkAdapter nif = subnetList.SubnetAt(0);
                uint subnet = nif.Subnet();
                subnetList.Dispose();
                var deviceListFactory = new CpUpnpDeviceListFactory(lib.StartCp(subnet));
                ICpDevice device = null;
                Semaphore sem = new Semaphore(0, 1);
                var deviceList = deviceListFactory.CreateListServiceType("openhome.org", "TestBasic", 1,
                        (aDeviceList, aDevice) =>
                        {
                            if (device != null)
                            {
                                throw new Exception("Found more than one device.  Giving up as test results will probably be invalid.");
                            }
                            device = aDevice;
                            device.AddRef();
                            sem.Release();
                        },
                        (aDeviceList, aDevice) =>
                        {
                            throw new Exception("ERROR: Device removed while test is running.");
                        });
                sem.WaitOne();

                // actions
                Console.WriteLine("");
                int[] threadCounts = { 1, 2, 4 };
                foreach (int threadCount in threadCounts)
                {
                    List<Thread> threads = new List<Thread>();
                    for (int i = 0; i < threadCount; i++)
                    {
                        threads.Add(new Thread(ActionThread));
                    }
                    ThreadArgs threadArgs = new ThreadArgs(device, kTestDurationMs);
                    for (int i = 0; i < threadCount; i++)
                    {
                        threads[i].Start(threadArgs);
                    }
                    for (int i = 0; i < threadCount; i++)
                    {
                        threads[i].Join();
                    }
                    Console.WriteLine("Invoked {0} actions in {1}ms using {2} threads", threadArgs.Count, kTestDurationMs, threadCount);
                }

                // subscriptions
                Thread thread = new Thread(SubscriptionThread);
                ThreadArgs args = new ThreadArgs(device, kTestDurationMs);
                thread.Start(args);
                thread.Join();
                Console.WriteLine("\nCompleted {0} subscriptions in {1}ms\n", args.Count, kTestDurationMs);

                device.RemoveRef();
                deviceList.Dispose();
                Console.WriteLine("\nTests complete.  Press 'q' to exit.");
                while (Console.ReadKey(true).KeyChar != 'q') ;
            }
        }