コード例 #1
0
ファイル: Session.cs プロジェクト: JEnoch/zenoh-csharp
        public Subscriber DeclareSubscriber(ResKey reskey, SubInfo subInfo, SubscriberCallback callback)
        {
            // convert the C# user callback as IntPtr to be passed as "arg" to zn_declare_subscriber()
            // and received back in each call to SubscriberCallbackNativeImpl
            IntPtr callbackPtr      = Marshal.GetFunctionPointerForDelegate(callback);
            var    nativeSubscriber = ZnDeclareSubscriber(this._nativePtr, reskey._key, subInfo._subInfo, SubscriberCallbackNativeImpl, callbackPtr);

            return(new Subscriber(nativeSubscriber));
        }
コード例 #2
0
        public Subscriber DeclareSubscriber(ResKey reskey, SubInfo subInfo, SubscriberCallback callback)
        {
            Int32 subscriberHandle = Interlocked.Increment(ref _subscriberCounter);
            var   nativeSubscriber = ZnDeclareSubscriber(_nativePtr, reskey._key, subInfo._subInfo, _subscriberCallbackNative, new IntPtr(subscriberHandle));
            var   subscriber       = new Subscriber(this, subscriberHandle, nativeSubscriber, callback);

            Subscribers[subscriberHandle] = subscriber;
            return(subscriber);
        }
コード例 #3
0
    static void Main(string[] args)
    {
        try
        {
            // initiate logging
            Zenoh.Zenoh.InitLogger();

            // arguments parsing
            var arguments = Args.Parse <ExampleArgs>(args);
            if (arguments == null)
            {
                return;
            }
            Dictionary <string, string> conf = arguments.GetConf();

            Console.WriteLine("Openning session...");
            var s = Zenoh.Net.Session.Open(conf);

            Console.WriteLine("Declaring Subscriber on '{0}'...", arguments.selector);
            var rkey    = Zenoh.Net.ResKey.RName(arguments.selector);
            var subInfo = new Zenoh.Net.SubInfo();
            s.DeclareSubscriber(rkey, subInfo, ZNSub.SubscriberCallback);

            char c = ' ';
            while (c != 'q')
            {
                c = Console.ReadKey().KeyChar;
            }

            s.Dispose();
        }
        catch (ArgException)
        {
            Console.WriteLine(ArgUsage.GenerateUsageFromTemplate <ExampleArgs>());
        }
    }