コード例 #1
0
        private static void NativePostResultCallbackHandler(IntPtr resource, int err, int requestType, IntPtr responseHandle, IntPtr userData)
        {
            IntPtr responseCompletionId = userData;
            TaskCompletionSource <RemoteResponse> responseCompletionSource;

            Log.Info(IoTConnectivityErrorFactory.LogTag, "Result callback for : " + responseCompletionId);

            if (!_taskCompletionMap.TryRemove(responseCompletionId, out responseCompletionSource))
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove Key");
                return;
            }

            if (responseHandle != IntPtr.Zero)
            {
                try
                {
                    responseCompletionSource.TrySetResult(GetRemoteResponse(responseHandle));
                }
                catch (Exception exp)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get RemoteResponse: ", exp.Message);
                    responseCompletionSource.TrySetException(exp);
                }
            }
            else
            {
                responseCompletionSource.TrySetException(IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.System));
            }
        }
コード例 #2
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        private RemoteResponse GetRemoteResponse(IntPtr response)
        {
            int    result;
            IntPtr representationHandle, optionsHandle;
            int    ret = Interop.IoTConnectivity.Server.Response.GetResult(response, out result);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get result");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            ret = Interop.IoTConnectivity.Server.Response.GetRepresentation(response, out representationHandle);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get representation");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            ret = Interop.IoTConnectivity.Server.Response.GetOptions(response, out optionsHandle);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get options");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
            return(new RemoteResponse()
            {
                Result = (ResponseCode)result,
                Representation = new Representation(representationHandle),
                Options = (optionsHandle == IntPtr.Zero)? null : new ResourceOptions(optionsHandle)
            });
        }
コード例 #3
0
        /// <summary>
        /// Stops receiving presence events.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// Sends request to not to receive server's presence any more.
        /// </remarks>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <param name="presenceId">The start presence request identifier.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <pre>
        /// Initialize() should be called to initialize.
        /// </pre>
        /// <seealso cref="IoTConnectivityServerManager.StartSendingPresence(uint)"/>
        /// <seealso cref="IoTConnectivityServerManager.StopSendingPresence()"/>
        /// <seealso cref="StartReceivingPresence(string, string)"/>
        /// <seealso cref="PresenceReceived"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory.</exception>
        /// <example><code><![CDATA[
        /// EventHandler<PresenceReceivedEventArgs> handler = (sender, e) => {
        ///     Console.Log("PresenceReceived, presence id :" + e.PresenceId);
        /// }
        /// EventHandler<FindingErrorOccurredEventArgs> errorHandler = (sender, e) => {
        ///     Console.Log("Found error :" + e.Error.Message);
        /// }
        /// IoTConnectivityClientManager.PresenceReceived += handler;
        /// IoTConnectivityClientManager.FindingErrorOccurred += errorHandler;
        /// int id = IoTConnectivityClientManager.StartReceivingPresence(IoTConnectivityClientManager.MulticastAddress, "oic.iot.door");
        /// await Task.Delay(5000); // Do other things here
        /// // Call StopReceivingPresence() when receiving presence is not required any more
        /// IoTConnectivityClientManager.PresenceReceived -= handler;
        /// IoTConnectivityClientManager.FindingErrorOccurred -= errorHandler;
        /// IoTConnectivityClientManager.StopReceivingPresence(id);
        /// ]]></code></example>
        public static void StopReceivingPresence(int presenceId)
        {
            if (!s_presenceHandlesMap.ContainsKey((IntPtr)presenceId))
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "this presenceId does not exist");
                throw new ArgumentException("this presenceId does not exist");
            }

            if (s_presenceHandlesMap.ContainsKey((IntPtr)presenceId))
            {
                IntPtr presenceHandle = s_presenceHandlesMap[(IntPtr)presenceId];
                int    ret            = Interop.IoTConnectivity.Client.Presence.RemovePresenceCb(presenceHandle);
                if (ret != (int)IoTConnectivityError.None)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to deregister presence event handler");
                    throw IoTConnectivityErrorFactory.GetException(ret);
                }

                lock (s_presenceHandlesMap)
                {
                    s_presenceHandlesMap.Remove((IntPtr)presenceId);
                }
            }

            if (s_presenceCallbacksMap.ContainsKey((IntPtr)presenceId))
            {
                lock (s_presenceCallbacksMap)
                {
                    s_presenceCallbacksMap.Remove((IntPtr)presenceId);
                }
            }
        }
コード例 #4
0
 private void ChildrenCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         foreach (Representation r in e.NewItems)
         {
             int ret = Interop.IoTConnectivity.Common.Representation.AddChild(_representationHandle, r._representationHandle);
             if (ret != (int)IoTConnectivityError.None)
             {
                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to add child");
                 throw IoTConnectivityErrorFactory.GetException(ret);
             }
         }
     }
     else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         foreach (Representation r in e.NewItems)
         {
             int ret = Interop.IoTConnectivity.Common.Representation.RemoveChild(_representationHandle, r._representationHandle);
             if (ret != (int)IoTConnectivityError.None)
             {
                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove child");
                 throw IoTConnectivityErrorFactory.GetException(ret);
             }
         }
     }
 }
コード例 #5
0
ファイル: RemoteResource.cs プロジェクト: srinivasa-m/TizenFX
        private static void NativeDeleteResultCallbackHandler(IntPtr resource, int err, int requestType, IntPtr responseHandle, IntPtr userData)
        {
            IntPtr responseCompletionId = userData;
            TaskCompletionSource <RemoteResponse> responseCompletionSource = _taskCompletionMap[responseCompletionId];

            _taskCompletionMap.Remove(responseCompletionId);

            if (err == (int)(IoTConnectivityError.Iotivity))
            {
                RemoteResponse response = new RemoteResponse();
                response.Result         = ResponseCode.Forbidden;
                response.Representation = null;
                responseCompletionSource.TrySetResult(response);
            }
            else if (responseHandle != IntPtr.Zero)
            {
                try
                {
                    responseCompletionSource.TrySetResult(GetRemoteResponse(responseHandle));
                }
                catch (Exception exp)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get RemoteResponse: ", exp.Message);
                    responseCompletionSource.TrySetException(exp);
                }
            }
            else
            {
                responseCompletionSource.TrySetException(IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.System));
            }
        }
コード例 #6
0
 private void ChildrenCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs eventArgs)
 {
     if (eventArgs.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
     {
         foreach (Resource r in eventArgs.NewItems)
         {
             int ret = Interop.IoTConnectivity.Server.Resource.BindChildResource(_resourceHandle, r._resourceHandle);
             if (ret != (int)IoTConnectivityError.None)
             {
                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to bind resource ");
                 throw IoTConnectivityErrorFactory.GetException(ret);
             }
         }
     }
     else if (eventArgs.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
     {
         foreach (Resource r in eventArgs.NewItems)
         {
             int ret = Interop.IoTConnectivity.Server.Resource.UnbindChildResource(_resourceHandle, r._resourceHandle);
             if (ret != (int)IoTConnectivityError.None)
             {
                 Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to unbind resource");
                 throw IoTConnectivityErrorFactory.GetException(ret);
             }
         }
     }
 }
コード例 #7
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        private void SetRemoteResource()
        {
            IntPtr hostAddressPtr, uriPathPtr;
            int    ret = Interop.IoTConnectivity.Client.RemoteResource.GetHostAddress(_remoteResourceHandle, out hostAddressPtr);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to get host address");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            ret = Interop.IoTConnectivity.Client.RemoteResource.GetUriPath(_remoteResourceHandle, out uriPathPtr);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to get uri path");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            int policy = (int)ResourcePolicy.NoProperty;

            ret = Interop.IoTConnectivity.Client.RemoteResource.GetPolicies(_remoteResourceHandle, out policy);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to get uri path");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            IntPtr typesHandle, interfacesHandle;

            ret = Interop.IoTConnectivity.Client.RemoteResource.GetTypes(_remoteResourceHandle, out typesHandle);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get resource types");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            ret = Interop.IoTConnectivity.Client.RemoteResource.GetInterfaces(_remoteResourceHandle, out interfacesHandle);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get resource interfaces");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            IntPtr deviceIdPtr;

            ret = Interop.IoTConnectivity.Client.RemoteResource.GetDeviceId(_remoteResourceHandle, out deviceIdPtr);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get device id");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
            DeviceId    = (deviceIdPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(deviceIdPtr) : string.Empty;
            HostAddress = (hostAddressPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(hostAddressPtr) : string.Empty;
            UriPath     = (uriPathPtr != IntPtr.Zero) ? Marshal.PtrToStringAnsi(uriPathPtr) : string.Empty;
            Types       = new ResourceTypes(typesHandle);
            Interfaces  = new ResourceInterfaces(interfacesHandle);
            Policy      = (ResourcePolicy)policy;
        }
コード例 #8
0
        /// <summary>
        /// Stops presence of a server.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// Use this API to stop sending server's announcements to clients.
        /// Server can call this API when terminating, entering to offline or out of network.
        /// </remarks>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <pre>
        /// Initialize() should be called to initialize.
        /// </pre>
        /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence(string, string)"/>
        /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence(int)"/>
        /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
        /// <seealso cref="StartSendingPresence(uint)"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <example><code>
        /// IoTConnectivityServerManager.StopSendingPresence();
        /// </code></example>
        public static void StopSendingPresence()
        {
            int ret = Interop.IoTConnectivity.Server.IoTCon.StopPresence();

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed cancel presence");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #9
0
        /// <summary>
        /// The Attributes constructor.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory.</exception>
        /// <example><code>
        /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
        /// </code></example>
        public Attributes()
        {
            int ret = Interop.IoTConnectivity.Common.Attributes.Create(out _resourceAttributesHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #10
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        /// <summary>
        /// Stops observing on the resource.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        public void StopObserving()
        {
            int ret = Interop.IoTConnectivity.Client.RemoteResource.DeregisterObserve(_remoteResourceHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to deregister observe callbacks");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #11
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        private void UnregisterStateChangedEvent()
        {
            int ret = Interop.IoTConnectivity.Client.RemoteResource.StopMonitoring(_remoteResourceHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove state changed event handler");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #12
0
        private static FindingErrorOccurredEventArgs GetFindingErrorOccurredEventArgs(int requestId, int err)
        {
            FindingErrorOccurredEventArgs e = new FindingErrorOccurredEventArgs()
            {
                RequestId = requestId,
                Error     = IoTConnectivityErrorFactory.GetException(err)
            };

            return(e);
        }
コード例 #13
0
        /// <summary>
        /// Invokes a next message from a queue for receiving messages from others, immediately.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// This API invokes a next message from a queue for receiving messages from others, immediately.
        /// After calling the API, it continues the polling with existing interval.
        /// </remarks>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <pre>
        /// Initialize() should be called to initialize.
        /// </pre>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <example><code>
        /// IoTConnectivityClientManager.InvokePolling();
        /// </code></example>
        public static void InvokePolling()
        {
            int ret = Interop.IoTConnectivity.Client.IoTCon.InvokePolling();

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to invoke polling");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #14
0
        /// <summary>
        /// Initializes IoTCon.
        /// Call this function to start IoTCon.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// <paramref name="filePath"/> points to a file for handling secure virtual resources.
        /// The file that is CBOR(Concise Binary Object Representation)-format must already exist
        /// in <paramref name="filePath" />. We recommend to use application-local file for <paramref name="filePath" />.
        /// </remarks>
        /// <privilege>http://tizen.org/privilege/network.get</privilege>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <param name="filePath">The file path pointing to storage for handling secure virtual resources.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <post>
        /// You must call Deinitialize() if IoTCon API is no longer needed.
        /// </post>
        /// <seealso cref="Deinitialize()"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <example><code>
        /// string filePath = "../../res/iotcon-test-svr-db-client.dat";
        /// IoTConnectivityClientManager.Initialize(filePath);
        /// </code></example>
        public static void Initialize(string filePath)
        {
            int ret = Interop.IoTConnectivity.Client.IoTCon.Initialize(filePath);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to initialize");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #15
0
        /// <summary>
        /// The resource query constructor.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <seealso cref="Add(string, string)"/>
        /// <seealso cref="Remove(string)"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory.</exception>
        /// <example><code>
        /// ResourceQuery query = new ResourceQuery();
        /// </code></example>
        public ResourceQuery()
        {
            int ret = Interop.IoTConnectivity.Common.Query.Create(out _resourceQueryHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create query");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #16
0
        /// <summary>
        /// Sets the device name.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// <para>This API sets the name of the local device (the device calling the API).</para>
        /// <para>If the device name is set, clients can get the name using <see cref="IoTConnectivityClientManager.StartFindingDeviceInformation(string, ResourceQuery)"/>.</para>
        /// </remarks>
        /// <param name="deviceName">The device name.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <seealso cref="IoTConnectivityClientManager.DeviceInformationFound"/>
        /// <seealso cref="IoTConnectivityClientManager.StartFindingDeviceInformation(string, ResourceQuery)"/>
        /// <seealso cref="DeviceInformationFoundEventArgs"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <example><code>
        /// IoTConnectivityServerManager.SetDeviceName("my-tizen");
        /// </code></example>
        public static void SetDeviceName(string deviceName)
        {
            int ret = Interop.IoTConnectivity.Server.IoTCon.SetDeviceName(deviceName);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed set device name");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #17
0
        /// <summary>
        /// Starts presence of a server.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// <para>Use this API to send server's announcements to clients.
        /// Server can call this API when online for the first time or come back from offline to online.</para>
        /// <para>If <paramref name="time" /> is 0, server will set default value as 60 seconds.</para>
        /// <para>If <paramref name="time" /> is very big, server will set maximum value as (60 * 60 * 24) seconds, (24 hours).</para>
        /// </remarks>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <param name="time">The interval of announcing presence in seconds.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <pre>
        /// Initialize() should be called to initialize.
        /// </pre>
        /// <seealso cref="IoTConnectivityClientManager.StartReceivingPresence(string, string)"/>
        /// <seealso cref="IoTConnectivityClientManager.StopReceivingPresence(int)"/>
        /// <seealso cref="IoTConnectivityClientManager.PresenceReceived"/>
        /// <seealso cref="StopSendingPresence()"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <example><code>
        /// try {
        ///     IoTConnectivityServerManager.StartSendingPresence(120);
        /// } catch(Exception ex) {
        ///     Console.Log("Exception caught : " + ex.Message);
        /// }
        /// </code></example>
        public static void StartSendingPresence(uint time)
        {
            int ret = Interop.IoTConnectivity.Server.IoTCon.StartPresence(time);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to start presence");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #18
0
        /// <summary>
        /// Notify the specified representation and qos.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <param name="representation">Representation.</param>
        /// <param name="qos">The quality of service for message transfer.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <pre>
        /// IoTConnectivityServerManager.Initialize() should be called to initialize.
        /// </pre>
        /// <seealso cref="Representation"/>
        /// <seealso cref="QualityOfService"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <example><code><![CDATA[
        /// ResourceInterfaces ifaces = new ResourceInterfaces(new List<string>(){ ResourceInterfaces.DefaultInterface });
        /// ResourceTypes types = new ResourceTypes(new List<string>(){ "oic.iot.door.new.notify" });
        /// Resource resource = new DoorResource("/door/uri/new/notify", types, ifaces, ResourcePolicy.Discoverable | ResourcePolicy.Observable);
        /// IoTConnectivityServerManager.RegisterResource(resource);
        ///
        /// Representation repr = new Representation();
        /// repr.UriPath = "/door/uri/new/notify";
        /// repr.Type = new ResourceTypes(new List<string>(){ "oic.iot.door.new.notify" });
        /// repr.Attributes = new Attributes() {
        ///      _attribute, 1 }
        /// };
        /// resource.Notify(repr, QualityOfService.High);
        /// ]]></code></example>
        public void Notify(Representation representation, QualityOfService qos)
        {
            int ret = (int)IoTConnectivityError.None;

            ret = Interop.IoTConnectivity.Server.Resource.Notify(_resourceHandle, representation._representationHandle, _observerHandle, (int)qos);
            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to send notification");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }
コード例 #19
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        /// <summary>
        /// Starts observing on the resource.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <remarks>
        /// When server sends notification message, <see cref="ObserverNotified"/> will be called.
        /// </remarks>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <param name="policy">The type to specify how client wants to observe.</param>
        /// <param name="query">The query to send to server.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have privilege to access.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory.</exception>
        public void StartObserving(ObservePolicy policy, ResourceQuery query = null)
        {
            _observeCallback = (IntPtr resource, int err, int sequenceNumber, IntPtr response, IntPtr userData) =>
            {
                int    result;
                IntPtr representationHandle;
                int    ret = Interop.IoTConnectivity.Server.Response.GetResult(response, out result);
                if (ret != (int)IoTConnectivityError.None)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get result");
                    return;
                }

                ret = Interop.IoTConnectivity.Server.Response.GetRepresentation(response, out representationHandle);
                if (ret != (int)IoTConnectivityError.None)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get representation");
                    return;
                }

                Representation repr = null;
                try
                {
                    repr = new Representation(representationHandle);
                }
                catch (Exception exp)
                {
                    Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to new representation: " + exp.Message);
                    return;
                }

                ObserverNotifiedEventArgs e = new ObserverNotifiedEventArgs()
                {
                    Representation = repr,
                    Result         = (ResponseCode)result
                };
                ObserverNotified?.Invoke(this, e);
            };

            IntPtr queryHandle = IntPtr.Zero;

            if (query != null)
            {
                queryHandle = query._resourceQueryHandle;
            }

            int errCode = Interop.IoTConnectivity.Client.RemoteResource.RegisterObserve(_remoteResourceHandle, (int)policy, queryHandle, _observeCallback, IntPtr.Zero);

            if (errCode != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to register observe callbacks");
                throw IoTConnectivityErrorFactory.GetException(errCode);
            }
        }
コード例 #20
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        internal RemoteResource(IntPtr handleToClone)
        {
            int ret = Interop.IoTConnectivity.Client.RemoteResource.Clone(handleToClone, out _remoteResourceHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Faled to clone");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
            SetRemoteResource();
        }
コード例 #21
0
        /// <summary>
        /// The Representation constructor.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory.</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter.</exception>
        /// <example><code>
        /// Representation repr = new Representation();
        /// </code></example>
        public Representation()
        {
            int ret = Interop.IoTConnectivity.Common.Representation.Create(out _representationHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create representation");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            _children.CollectionChanged += ChildrenCollectionChanged;
        }
コード例 #22
0
        /// <summary>
        /// Removes a resource type from the list.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="item">The string data to delete from the resource types.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <seealso cref="Add(string)"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter.</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid.</exception>
        /// <example><code><![CDATA[
        /// ResourceTypes resourceTypes = new ResourceTypes(new List<string>() { "org.tizen.light", "oic.if.room" });
        /// resourceTypes.Remove("oic.if.room");
        /// ]]></code></example>
        public void Remove(string item)
        {
            int ret = Interop.IoTConnectivity.Common.ResourceTypes.Remove(_resourceTypeHandle, item);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove type");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            _resourceTypes.Remove(item);
        }
コード例 #23
0
        internal Attributes(IntPtr attributesHandleToClone)
        {
            int ret = Interop.IoTConnectivity.Common.Attributes.Clone(attributesHandleToClone, out _resourceAttributesHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create attributes handle");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            SetAttributes(_resourceAttributesHandle);
        }
コード例 #24
0
 /// <summary>
 /// Clears attributes collection.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <feature>http://tizen.org/feature/iot.ocf</feature>
 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
 /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
 /// <example><code>
 /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes();
 /// attributes.Add("brightness", 50);
 /// attributes.Clear();
 /// </code></example>
 public void Clear()
 {
     foreach (string key in _attributes.Keys)
     {
         int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);
         if (ret != (int)IoTConnectivityError.None)
         {
             Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to clear attributes");
             throw IoTConnectivityErrorFactory.GetException(ret);
         }
     }
     _attributes.Clear();
 }
コード例 #25
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        /// <summary>
        /// Deletes the resource asynchronously.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <privilege>http://tizen.org/privilege/internet</privilege>
        /// <privlevel>public</privlevel>
        /// <returns>Remote response with result and representation.</returns>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        public async Task <RemoteResponse> DeleteAsync()
        {
            TaskCompletionSource <RemoteResponse> tcsRemoteResponse = new TaskCompletionSource <RemoteResponse>();

            IntPtr id = IntPtr.Zero;

            lock (_responseCallbacksMap)
            {
                id = (IntPtr)_responseCallbackId++;
            }
            _responseCallbacksMap[id] = (IntPtr resource, int err, int requestType, IntPtr responseHandle, IntPtr userData) =>
            {
                IntPtr responseCallbackId = userData;
                lock (_responseCallbacksMap)
                {
                    _responseCallbacksMap.Remove(responseCallbackId);
                }
                if (err == (int)(IoTConnectivityError.Iotivity))
                {
                    RemoteResponse response = new RemoteResponse();
                    response.Result         = ResponseCode.Forbidden;
                    response.Representation = null;
                    tcsRemoteResponse.TrySetResult(response);
                }
                else if (responseHandle != IntPtr.Zero)
                {
                    try
                    {
                        tcsRemoteResponse.TrySetResult(GetRemoteResponse(responseHandle));
                    }
                    catch (Exception exp)
                    {
                        Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get RemoteResponse: ", exp.Message);
                        tcsRemoteResponse.TrySetException(exp);
                    }
                }
                else
                {
                    tcsRemoteResponse.TrySetException(IoTConnectivityErrorFactory.GetException((int)IoTConnectivityError.System));
                }
            };

            int errCode = Interop.IoTConnectivity.Client.RemoteResource.Delete(_remoteResourceHandle, _responseCallbacksMap[id], id);

            if (errCode != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to delete");
                tcsRemoteResponse.TrySetException(IoTConnectivityErrorFactory.GetException(errCode));
            }
            return(await tcsRemoteResponse.Task);
        }
コード例 #26
0
ファイル: ResourceOptions.cs プロジェクト: yunmiha/TizenFX
        /// <summary>
        /// Removes the ID and its associated data from the options.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="key">The ID of the option to delete.</param>
        /// <returns>True if operation is successful. Otherwise, false.</returns>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <seealso cref="Add(ushort, string)"/>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter.</exception>
        /// <example><code>
        /// ResourceOptions options = new ResourceOptions();
        /// options.Add(2050, "12345");
        /// var result = options.Remove(2050);
        /// </code></example>
        public bool Remove(ushort key)
        {
            int ret = Interop.IoTConnectivity.Common.Options.Remove(_resourceOptionsHandle, key);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove option");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            bool isRemoved = _options.Remove(key);

            return(isRemoved);
        }
コード例 #27
0
ファイル: ResourceInterfaces.cs プロジェクト: yunmiha/TizenFX
        /// <summary>
        /// Constructor of ResourceInterfaces using list of interfaces.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="ifaces">List of resource interfaces.</param>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when there is not enough memory.</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter.</exception>
        /// <example><code><![CDATA[
        /// ResourceInterfaces resourceInterfaces = new ResourceInterfaces(new List<string>()
        ///     { ResourceInterfaces.LinkInterface, ResourceInterfaces.ReadonlyInterface });
        /// ]]></code></example>
        public ResourceInterfaces(IEnumerable <string> ifaces)
        {
            int ret = Interop.IoTConnectivity.Common.ResourceInterfaces.Create(out _resourceInterfacesHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to create interface");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
            foreach (string iface in ifaces)
            {
                Add(iface);
            }
        }
コード例 #28
0
ファイル: ResourceOptions.cs プロジェクト: yunmiha/TizenFX
 /// <summary>
 /// Clears the Options collection.
 /// </summary>
 /// <since_tizen> 3 </since_tizen>
 /// <feature>http://tizen.org/feature/iot.ocf</feature>
 /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported.</exception>
 /// <example><code>
 /// ResourceOptions options = new ResourceOptions();
 /// options.Add(2050, "12345");
 /// options.Add(2055, "sample");
 /// options.Clear();
 /// </code></example>
 public void Clear()
 {
     foreach (ushort key in Keys)
     {
         int ret = Interop.IoTConnectivity.Common.Options.Remove(_resourceOptionsHandle, key);
         if (ret != (int)IoTConnectivityError.None)
         {
             Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove option");
             throw IoTConnectivityErrorFactory.GetException(ret);
         }
         ;
     }
     _options.Clear();
 }
コード例 #29
0
        /// <summary>
        /// Removes an attribute from collection using a key.
        /// </summary>
        /// <since_tizen> 3 </since_tizen>
        /// <param name="key">The attributes element to remove.</param>
        /// <returns>true if operation is successful, otherwise, false.</returns>
        /// <feature>http://tizen.org/feature/iot.ocf</feature>
        /// <exception cref="NotSupportedException">Thrown when the iotcon is not supported</exception>
        /// <exception cref="ArgumentException">Thrown when there is an invalid parameter</exception>
        /// <exception cref="InvalidOperationException">Thrown when the operation is invalid</exception>
        /// <example><code>
        /// Tizen.Network.IoTConnectivity.Attributes attributes = new Tizen.Network.IoTConnectivity.Attributes() {
        ///     { "state", "ON" },
        ///     { "dim", 10 }
        /// };
        /// if (attributes.Remove("state"))
        ///     Console.WriteLine("Remove was successful");
        /// </code></example>
        public bool Remove(string key)
        {
            int ret = Interop.IoTConnectivity.Common.Attributes.Remove(_resourceAttributesHandle, key);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to remove attributes");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }

            bool isRemoved = _attributes.Remove(key);

            return(isRemoved);
        }
コード例 #30
0
ファイル: RemoteResource.cs プロジェクト: yourina/TizenFX
        private void CreateRemoteResource(IntPtr resourceTypeHandle, IntPtr resourceInterfaceHandle)
        {
            Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType connectivityType = GetConnectivityType(HostAddress);
            if (connectivityType == Interop.IoTConnectivity.Client.RemoteResource.ConnectivityType.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Unable to parse host address");
                throw new ArgumentException("Unable to parse host address");
            }
            int ret = Interop.IoTConnectivity.Client.RemoteResource.Create(HostAddress, (int)connectivityType, UriPath, (int)Policy, resourceTypeHandle, resourceInterfaceHandle, out _remoteResourceHandle);

            if (ret != (int)IoTConnectivityError.None)
            {
                Log.Error(IoTConnectivityErrorFactory.LogTag, "Failed to get remote resource");
                throw IoTConnectivityErrorFactory.GetException(ret);
            }
        }