Ejemplo n.º 1
0
            static private void OnEvent_callback(IntPtr instance, IntPtr e)
            {
                DistClient client = ReferenceDictionary <DistClient> .GetObject(instance);

                if (client != null)
                {
                    DistEvent @event = Reference.CreateObject(e) as DistEvent;

                    if (@event != null)
                    {
                        if (client.UseAutoProperty && @event.GetType().IsDefined(typeof(DistPropertyAutoRestore), true))
                        {
                            @event.RestorePropertiesAndFields();
                        }

                        try
                        {
                            client.OnEvent?.Invoke(client, @event);
                        }
                        catch (Exception ex)
                        {
                            Message.SendException("DistClient", ex);
                        }
                    }
                }
            }
Ejemplo n.º 2
0
            private void RegisterEventPrototype(Type eventType, string nativeBaseTypename)
            {
                const System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Instance |
                                                             System.Reflection.BindingFlags.NonPublic |
                                                             System.Reflection.BindingFlags.CreateInstance |
                                                             System.Reflection.BindingFlags.OptionalParamBinding;

                // manually construct native dist event to use as factory object
                var factoryObj = new DistEvent();
                var nativeRef  = factoryObj.GetNativeReference();

                // create managed implementation, supplying the dist event we just created
                var prototype = (Reference)Activator.CreateInstance(eventType, flags, null, new object[] { nativeRef }, null);

                // register a factory
                if (!RegisterEventHierarchy(eventType.Name, nativeBaseTypename, factoryObj))
                {
                    Message.Send(nameof(DistManager), MessageLevel.DEBUG, $"Using native factory    >>> {eventType.Name}");
                }
                else
                {
                    Message.Send(nameof(DistManager), MessageLevel.DEBUG, $"Using managed factory   >>> {eventType.Name}");
                }

                // use the overloaded AddFactory to register with correct typename
                AddFactory(prototype, eventType.Name);
            }
Ejemplo n.º 3
0
            // --- Reflection mechanisms --------------------------------

            static public bool StorePropertiesAndFields(DistEvent e, object obj, bool allProperties = false)
            {
                foreach (System.Reflection.PropertyInfo prop in obj.GetType().GetProperties())
                {
                    if (allProperties || Attribute.IsDefined(prop, typeof(DistProperty)))
                    {
                        if (!e.SetAttributeValue(prop.Name, DynamicType.CreateDynamicType(prop.GetValue(obj), allProperties)))
                        {
                            return(false);
                        }
                    }
                }

                foreach (System.Reflection.FieldInfo field in obj.GetType().GetFields())
                {
                    if (allProperties || Attribute.IsDefined(field, typeof(DistProperty)))
                    {
                        if (!e.SetAttributeValue(field.Name, DynamicType.CreateDynamicType(field.GetValue(obj), allProperties)))
                        {
                            return(false);
                        }
                    }
                }

                return(true);
            }
Ejemplo n.º 4
0
        private static void Client_OnEvent(DistClient sender, DistEvent e)
        {
            // Check if message is from us
            if (e.GetSource() == sender.GetClientID().InstanceID)
            {
                return;
            }

            if (counter == 0)
            {
                recv_timer = new Timer();
            }

            if (e.GetAttributeValue("Cnt") != counter)
            {
                Console.WriteLine("Error");
            }

            counter++;

            if (counter == COUNT)
            {
                Console.WriteLine($"Received {COUNT} events in {recv_timer.GetTime()} seconds -> Frequency: {recv_timer.GetFrequency(COUNT)} ");
                counter = 0;
            }
        }
Ejemplo n.º 5
0
            public bool SendEvent(DistEvent e, DistSession session)
            {
                if (UseAutoProperty && e.GetType().IsDefined(typeof(DistPropertyAutoStore), true))
                {
                    e.StorePropertiesAndFields();
                }

                return(DistClient_sendEvent(GetNativeReference(), e.GetNativeReference(), session.GetNativeReference()));
            }
Ejemplo n.º 6
0
        private static void Client_OnEvent(DistClient sender, DistEvent e)
        {
            // Check if message is from us
            if (e.GetSource() == sender.GetClientID().InstanceID)
            {
                return;
            }

            System.Console.WriteLine(e.ToString());
        }
Ejemplo n.º 7
0
            public DistEvent AwaitResponse(DistEvent responseEventType, UInt32 timeout = 100)
            {
                DistEvent response = Reference.CreateObject(DistClient_awaitResponse(GetNativeReference(), responseEventType.GetNativeReference(), timeout)) as DistEvent;

                if (response?.IsValid() ?? false)
                {
                    if (UseAutoProperty && response.GetType().IsDefined(typeof(DistPropertyAutoRestore), true))
                    {
                        response.RestorePropertiesAndFields();
                    }
                }

                return(response);
            }
Ejemplo n.º 8
0
            private void OnEvent_callback(IntPtr e)
            {
                DistEvent @event = Reference.CreateObject(e) as DistEvent;

                if (@event != null)
                {
                    if (UseAutoProperty && @event.GetType().IsDefined(typeof(DistPropertyAutoRestore), true))
                    {
                        @event.RestorePropertiesAndFields();
                    }

                    OnEvent?.Invoke(this, @event);
                }
            }
Ejemplo n.º 9
0
        private static void Client_OnEvent(DistClient sender, DistEvent e)
        {
            // Check if message is from us
            if (e.GetSource() == sender.GetClientID().InstanceID)
            {
                return;
            }

            MessageEvent mess = e as MessageEvent;

            if (mess != null)
            {
                Console.WriteLine(mess.Message);
            }
        }
Ejemplo n.º 10
0
            static public void RestorePropertiesAndFields(DistEvent e, object obj, bool allProperties = false)
            {
                foreach (System.Reflection.PropertyInfo prop in obj.GetType().GetProperties())
                {
                    if (allProperties || Attribute.IsDefined(prop, typeof(DistProperty)))
                    {
                        prop.SetValue(obj, e.GetAttributeValue(prop.Name).GetObject(prop.PropertyType, allProperties));
                    }
                }

                foreach (System.Reflection.FieldInfo field in obj.GetType().GetFields())
                {
                    if (allProperties || Attribute.IsDefined(field, typeof(DistProperty)))
                    {
                        field.SetValue(obj, e.GetAttributeValue(field.Name).GetObject(field.FieldType, allProperties));
                    }
                }
            }
Ejemplo n.º 11
0
        private static void Client_OnEvent(DistClient sender, DistEvent e)
        {
            if (counter == 0)
            {
                recv_timer = new Timer();
            }

            if (e.GetAttributeValue("Cnt") != counter)
            {
                Console.WriteLine("Error");
            }

            counter++;

            if (counter == COUNT)
            {
                Console.WriteLine($"Received {COUNT} events in {recv_timer.GetTime()} seconds -> Frequency: {recv_timer.GetFrequency(COUNT)} ");
                counter = 0;
            }
        }
Ejemplo n.º 12
0
 public DistEventAttributeIterator(DistEvent e) : base(DistEventAttributeIterator_create(e.GetNativeReference()))
 {
 }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            // Initialize platforms for various used SDKs
            GizmoSDK.GizmoBase.Platform.Initialize();
            GizmoSDK.GizmoDistribution.Platform.Initialize();


            Message.OnMessage += Message_OnMessage;

            Message.SetMessageLevel(MessageLevel.DEBUG);

            // Create a manager. The manager controls it all
            DistManager manager = DistManager.GetManager(true);

            // Start the manager with settting for transport protocols
            manager.Start();

            DistSession session = manager.GetSession("Perfa", true);

            // First Client -------------------------------------------------------------------

            // Client set up. You are a client that only sends information
            DistClient client = new DistClient("PerfClient", manager);

            // We need to tell the client how to initialize
            client.Initialize(0, 0, true);



            // Second Client -------------------------------------------------------------------

            // Client set up. You are a client that only receives information
            DistClient client2 = new DistClient("PerfClient2", manager);

            // We need to tell the client how to initialize
            client2.Initialize(0, 0, true);

            // Joint that session and subribe all events
            client2.JoinSession(session);
            client2.SubscribeEvents(session); // Subscribe All Events

            // Create a delegete
            client2.OnEvent += Client2_OnEvent;

            System.Threading.Thread.Sleep(100);

            // Create COUNT test event

            Timer timer = new Timer();

            DistEvent[] e_arr = new DistEvent[COUNT];

            for (int i = 0; i < COUNT; i++)
            {
                e_arr[i] = new DistEvent();
                e_arr[i].SetAttributeValue("Cnt", i);

                // Set some additional data e.g. two vec3
                e_arr[i].SetAttributeValue("vec1", new Vec3(1, 2, 3));
                e_arr[i].SetAttributeValue("vec2", new Vec3(4, 5, 6));
            }

            Console.WriteLine($"Created {COUNT} events in {timer.GetTime()} seconds -> Frequency: { timer.GetFrequency(COUNT)}");

            // Send COUNT events

            timer = new Timer();

            for (int i = 0; i < COUNT; i++)
            {
                client.SendEvent(e_arr[i], session);
            }

            Console.WriteLine($"Sent {COUNT} events in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT)}");

            while (manager.HasPendingData() || !stopper)
            {
                System.Threading.Thread.Sleep(10);
            }

            client.Uninitialize(true);
            client2.Uninitialize(true);

            // Some kind of graceful shutdown
            manager.Shutdown();

            // GC and platform uninit is managed by the system automatically
        }
Ejemplo n.º 14
0
 public bool SendEvent(DistEvent e, DistSession session)
 {
     return(DistClient_sendEvent(GetNativeReference(), e.GetNativeReference(), session.GetNativeReference()));
 }
Ejemplo n.º 15
0
 static public void UninitializeFactories()
 {
     DistEvent.UninitializeFactory();
     DistObject.UninitializeFactory();
 }
Ejemplo n.º 16
0
 public bool RegisterEventHierarchy(string typeName, string parentTypeName = "gzDistEvent", DistEvent factoryEvent = null)
 {
     return(DistManager_registerEventHierarchy(GetNativeReference(), typeName, parentTypeName, factoryEvent?.GetNativeReference() ?? IntPtr.Zero));
 }
Ejemplo n.º 17
0
 public T SendEventAndAwaitResponse <T>(DistEvent e, DistSession session, UInt32 timeout = 100) where T : DistEvent
 {
     return(SendEventAndAwaitResponse(e, session, manager.GetEvent <T>(), timeout) as T);
 }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            // Initialize platforms for various used SDKs
            GizmoSDK.GizmoBase.Platform.Initialize();
            GizmoSDK.GizmoDistribution.Platform.Initialize();

            // Create a manager. The manager controls it all
            DistManager manager = DistManager.GetManager(true);

            DistTransportType protocol = DistTransportType.MULTICAST;

            //string iface =  "${wi-fi}";

            //string iface = "10.132.0.5";

            string iface = "127.0.0.1";

            string adress = "234.5.6.19";

            ushort server_port = 1122;
            ushort client_port = 2211;



            //string iface = null;

            // Start the manager with settting for transport protocols
            //manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(true,protocol, iface), DistRemoteChannel.CreateDefaultServerChannel(true,protocol, iface));
            manager.Start(DistRemoteChannel.CreateChannel(5000, protocol, adress, client_port, iface), DistRemoteChannel.CreateChannel(5000, protocol, adress, server_port, iface));

            // Client set up. You are a client that sends and receives information
            DistClient client = new DistClient("PerfClient", manager);

            // We need to tell the client how to initialize
            client.Initialize(0, 0);

            // Now we can get a session. A kind of a meeting room that is used to exchange various "topics"
            DistSession session = client.GetSession("PerfSession", true, true);

            // Joint that session and subribe all events
            client.JoinSession(session);
            client.SubscribeEvents(session); // Subscribe All Events

            // Create a delegete
            client.OnEvent += Client_OnEvent;

            Console.WriteLine($"Press <RETURN> to start sending");

            // Now loops around some simple program to get strings from console and distribute them as a message app

            while (true)
            {
                string result = Console.ReadLine();

                if (result == "quit")
                {
                    break;
                }

                // Create COUNT test events

                Timer timer = new Timer();

                DistEvent [] e_arr = new DistEvent[COUNT];

                for (int i = 0; i < COUNT; i++)
                {
                    e_arr[i] = new DistEvent();
                    e_arr[i].SetAttributeValue("Cnt", i);

                    // Set some additional data e.g. two vec3
                    e_arr[i].SetAttributeValue("vec1", new Vec3(1, 2, 3));
                    e_arr[i].SetAttributeValue("vec2", new Vec3(4, 5, 6));
                }

                Console.WriteLine($"Created {COUNT} events in {timer.GetTime()} seconds -> Frequency: { timer.GetFrequency(COUNT)}");

                // Send COUNT events

                timer = new Timer();

                for (
                    int i = 0; i < COUNT; i++)
                {
                    client.SendEvent(e_arr[i], session);
                }

                Console.WriteLine($"Sent {COUNT} events in {timer.GetTime()} seconds -> Frequency: {timer.GetFrequency(COUNT)}");
            }

            while (manager.HasPendingData())
            {
                System.Threading.Thread.Sleep(10);
            }

            client.Uninitialize(true);

            // Some kind of graceful shutdown
            manager.Shutdown();


            // GC and platform uninit is managed by the system automatically
        }
Ejemplo n.º 19
0
        static void Main(string[] args)
        {
            // Add a message receiver
            Message.OnMessage += Message_OnMessage;

            // Set message level to debug
            Message.SetMessageLevel(MessageLevel.DEBUG);


            // Initialize platforms for various used SDKs
            GizmoSDK.GizmoBase.Platform.Initialize();
            GizmoSDK.GizmoDistribution.Platform.Initialize();



            // Create a manager. The manager controls it all
            DistManager manager = DistManager.GetManager(true);

            // Start the manager with settting for transport protocols
            manager.Start(DistRemoteChannel.CreateDefaultSessionChannel(), DistRemoteChannel.CreateDefaultServerChannel());

            //If we want to attach the DistMonitor debugger
            manager.EnableDebug(true);

            // Client set up. You are a client that sends and receives information
            DistClient client = new DistClient("Our Test Client", manager);

            // We need to tell the client how to initialize
            client.Initialize();

            // Now we can get a session. A kind of a meeting room that is used to exchange various "topics"
            DistSession session = client.GetSession("MessageSession", true, true);

            // Joint that session and subribe all events
            client.JoinSession(session);

            // Subscribe standard events
            client.SubscribeEvents(session);

            // Create a delegete
            client.OnEvent += Client_OnEvent;

            for (int i = 0; i < 100; i++)
            {
                DistEvent e = manager.GetEvent();

                e.SetAttributeValue("Message", "Helluuuu");

                e.SetAttributeValue("Count", i);

                client.SendEvent(e, session);

                System.Threading.Thread.Sleep(1000);
            }



            client.ResignSession(session);

            client.Uninitialize();

            // Some kind of graceful shutdown
            manager.Shutdown();


            // GC and platform uninit is managed by the system automatically
        }