private OCStackApplicationResult OnDiscover(IntPtr context, IntPtr handle, OCClientResponse clientResponse)
        {
            if (clientResponse == null)
            {
                return(OCStackApplicationResult.OC_STACK_DELETE_TRANSACTION);
            }
            var response = new ClientResponse <Payload>(clientResponse);

            if (response.Payload != null)
            {
                if (response.Payload is DiscoveryPayload)
                {
                    var dpayload = (DiscoveryPayload)response.Payload;
                    var addr     = response.DeviceAddress; // new DeviceAddress(clientResponse.devAddr);
                    foreach (var item in dpayload.Resources)
                    {
                        string key = $"{addr.Address}:{addr.Port}{item.Uri}";
                        if (!discoveredResources.ContainsKey(key))
                        {
                            discoveredResources[key] = DateTimeOffset.UtcNow;
                            ResourceDiscovered?.Invoke(this, new ResourceDiscoveredEventArgs(addr, item));
                        }
                    }
                }
            }
            return(OCStackApplicationResult.OC_STACK_KEEP_TRANSACTION);
        }
Example #2
0
 private OCStackApplicationResult OnDiscover(IntPtr context, IntPtr handle, OCClientResponse clientResponse)
 {
     if (clientResponse == null)
     {
         return(OCStackApplicationResult.OC_STACK_DELETE_TRANSACTION);
     }
     ResourceDiscovered?.Invoke(this, new ClientResponseEventArgs <OC.DiscoveryPayload>(clientResponse, handle));
     return(OCStackApplicationResult.OC_STACK_KEEP_TRANSACTION);
 }
 internal ClientResponse(OCClientResponse response)
 {
     _response = response;
 }
 internal ClientResponseEventArgs(OCClientResponse clientResponse, IntPtr handle)
 {
     Response = new ClientResponse <T>(clientResponse);
     Handle   = handle;
 }
        private OCStackApplicationResult OnObserveCallback(IntPtr context, IntPtr handle, OCClientResponse clientResponse)
        {
            var payload = clientResponse.payload == IntPtr.Zero ? null : new RepPayload(clientResponse.payload);

            OnObserve?.Invoke(this, new ResourceObservationEventArgs(new DeviceAddress(clientResponse.devAddr), clientResponse.resourceUri, payload));
            return(OCStackApplicationResult.OC_STACK_KEEP_TRANSACTION);
        }