DeviceStream(DeviceConnection owner, SafeStreamHandle handle)
        {
            this.handle = handle;
            this.owner  = owner;

            ServiceConfigurationResponse = null;

            Log.Write("NabtoClientStream.NabtoClientStream({0}, {1})", owner, handle);
        }
        internal static DeviceStream Create(DeviceConnection owner, string serviceConfiguration = null)
        {
            IntPtr nativeHandle;

            PlatformAdapter.Instance.nabtoStreamOpen(out nativeHandle, owner.Owner.GetNativeHandle(), owner.DeviceId);

            var safeHandle = new SafeStreamHandle(nativeHandle);
            var instance   = new DeviceStream(owner, safeHandle);

            owner.Register(instance);

            if (string.IsNullOrEmpty(serviceConfiguration) == false)
            {
                instance.ConfigureStreamService(serviceConfiguration);
            }

            return(instance);
        }