Пример #1
0
 public static extern OCStackResult OCCreateResource([Out] out IntPtr handle,
                                                     [MarshalAs(UnmanagedType.LPStr)] string resourceTypeName,
                                                     [MarshalAs(UnmanagedType.LPStr)] string resourceInterfaceName,
                                                     [MarshalAs(UnmanagedType.LPStr)] string uri,
                                                     OCEntityHandler entityHandler,
                                                     IntPtr callbackParam,
                                                     OCResourceProperty resourceProperties);
Пример #2
0
 public static extern OCStackResult OCCreateResourceWithEp([Out] out IntPtr handle,
                                                           [MarshalAs(UnmanagedType.LPStr)] string resourceTypeName,
                                                           [MarshalAs(UnmanagedType.LPStr)] string resourceInterfaceName,
                                                           [MarshalAs(UnmanagedType.LPStr)] string uri,
                                                           OCEntityHandler entityHandler,
                                                           IntPtr callbackParam,
                                                           byte resourceProperties,
                                                           OCTpsSchemeFlags resourceTpsTypes);
Пример #3
0
        public DeviceResource(string uri, string resourceTypeName, IDictionary <string, object> properties, string resourceInterfaceName = IotivityDotNet.Interop.Defines.OC_RSRVD_INTERFACE_DEFAULT)
        {
            _resourceCallback = this.OCEntityHandler;
            OCStackResult result = OCStack.OCCreateResource(out _handle, resourceTypeName, resourceInterfaceName, uri, _resourceCallback, IntPtr.Zero, OCResourceProperty.OC_DISCOVERABLE | OCResourceProperty.OC_OBSERVABLE | OCResourceProperty.OC_SECURE);

            OCStackException.ThrowIfError(result, "Failed to create resource");
            _uri = uri;
            _resourceProperties = new Dictionary <string, IotivityValueDictionary>();
            if (properties != null)
            {
                _resourceProperties.Add(resourceTypeName, new IotivityValueDictionary(properties));
            }
        }
Пример #4
0
        public static void Initialize(ServiceMode mode, string dataPath = "", string securityDBDatFilename = null)
        {
            storageHandler = new StorageHandler(dataPath, securityDBDatFilename);
            storageHandle  = GCHandle.Alloc(storageHandler);
            var fileresult = OCStack.OCRegisterPersistentStorageHandler(storageHandler.Handle);

            OCStackException.ThrowIfError(fileresult, "Failed to create storage handler");

            //var result = OCStack.OCInit(null, 0, (OCMode)mode);
            var result = OCStack.OCInit2((OCMode)mode, OCTransportFlags.OC_DEFAULT_FLAGS, OCTransportFlags.OC_DEFAULT_FLAGS, OCTransportAdapter.OC_ADAPTER_IP);

            // result = OCStack.OCInit("0.0.0.0", 0, (OCMode)mode);
            OCStackException.ThrowIfError(result);
            globalHandler = OCDefaultDeviceEntityHandler;
            GC.KeepAlive(storageHandler);
            result = OCStack.OCSetDefaultDeviceEntityHandler(globalHandler, IntPtr.Zero);
            OCStackException.ThrowIfError(result, "Failed to send to resource");


            ct  = new CancellationTokenSource();
            tcs = new TaskCompletionSource <object>();

            Task.Run(async() =>
            {
                while (!ct.IsCancellationRequested)
                {
                    var result2 = OCStack.OCProcess();
                    if (result2 != OCStackResult.OC_STACK_OK)
                    {
                        // tcs.SetException(new Exception("OCStackException on Process: " + result2.ToString()));
                        // break;
                    }
                    await Task.Delay(1);
                }
                tcs.SetResult(true);
                tcs = null;
                ct  = null;
            });
        }
Пример #5
0
 public static extern OCStackResult OCSetDefaultDeviceEntityHandler(OCEntityHandler entityHandler, IntPtr callbackParameter);