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'
示例#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);
        }
示例#2
0
文件: Program.cs 项目: weeble/ohos
        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;
        }
示例#3
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");
            }
        }
示例#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();
 }
示例#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();
     }
 }
示例#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();
 }
示例#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);
     }
 }
示例#8
0
文件: TestProxy.cs 项目: sewood/ohNet
 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);
     }
 }
示例#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");
     }
 }
示例#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);
 }
示例#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();
     }
 }
示例#12
0
文件: OhNet.cs 项目: broonie/ohNet
        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();
            }
        }
示例#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();
        }
示例#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);
        }
示例#15
0
文件: OhNet.cs 项目: kevin5391/ohNet
 private Library(InitParams aParams)
 {
     iInitParams = aParams;
 }
示例#16
0
文件: OhNet.cs 项目: astaykov/ohNet
 public ChangedListener(InitParams.ChangeHandler aHandler)
 {
     iHandler = aHandler;
 }
示例#17
0
文件: OhNet.cs 项目: astaykov/ohNet
 public NetworkAdapterListener(InitParams.NetworkAdapterHandler aHandler)
 {
     iHandler = aHandler;
 }
示例#18
0
文件: OhNet.cs 项目: astaykov/ohNet
 public MessageListener(InitParams.MessageHandler aHandler)
 {
     iHandler = aHandler;
 }
示例#19
0
文件: OhNet.cs 项目: astaykov/ohNet
 public AsyncListener(InitParams.AsyncHandler aHandler)
 {
     iHandler = aHandler;
 }
示例#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");
     }
 }
示例#21
0
文件: OhNet.cs 项目: chinshou/ohNet
 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();
     }
 }
示例#22
0
文件: OhNet.cs 项目: chinshou/ohNet
 public NetworkAdapterListener(InitParams.NetworkAdapterHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallbackNetworkAdapter(NetworkAdapter);
 }
示例#23
0
文件: OhNet.cs 项目: chinshou/ohNet
 public ChangedListener(InitParams.ChangeHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallback(Changed);
 }
示例#24
0
文件: OhNet.cs 项目: chinshou/ohNet
 /// <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;
 }
示例#25
0
文件: OhNet.cs 项目: 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();
     }
 }
示例#26
0
文件: OhNet.cs 项目: chinshou/ohNet
 public MessageListener(InitParams.MessageHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallbackMsg(Message);
 }
示例#27
0
 private Library(InitParams aParams)
 {
     iInitParams = aParams;
 }
示例#28
0
文件: OhNet.cs 项目: chinshou/ohNet
 public AsyncListener(InitParams.AsyncHandler aHandler)
 {
     iHandler = aHandler;
     Callback = new InitParams.OhNetCallbackAsync(AsyncListenerCallback);
 }
示例#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') ;
            }
        }