Exemplo n.º 1
0
        /// <summary>
        /// This seems to be for Register objects on a DBus server.
        /// When method calls are made to the server Items in RegisteredObjects are used
        /// to respond to them.
        /// </summary>
        /// <param name="path">Path.</param>
        /// <param name="obj">Object.</param>
        public void Register(ObjectPath path, object obj)
        {
            ExportObject eo = ExportObject.CreateExportObject(this, path, obj);

            eo.Registered = true;

            //TODO: implement some kind of tree data structure or internal object hierarchy. right now we are ignoring the name and putting all object paths in one namespace, which is bad
            RegisteredObjects[path] = eo;
        }
Exemplo n.º 2
0
        public void SetHeaderData(byte[] data)
        {
            EndianFlag    endianness = (EndianFlag)data[0];
            MessageReader reader     = new MessageReader(endianness, data);

            MethodCaller2 mCaller = ExportObject.GetMCaller(hHandler);

            mCaller(this, reader, null, new MessageWriter());
        }
Exemplo n.º 3
0
        public object Unregister(ObjectPath path)
        {
            BusObject bo;

            if (!RegisteredObjects.TryGetValue(path, out bo))
            {
                throw new Exception("Cannot unregister " + path + " as it isn't registered");
            }

            RegisteredObjects.Remove(path);

            ExportObject eo = (ExportObject)bo;

            eo.Registered = false;

            return(eo.obj);
        }
Exemplo n.º 4
0
        //not particularly efficient and needs to be generalized
        internal void HandleMethodCall(MethodCall method_call)
        {
            //TODO: Ping and Introspect need to be abstracted and moved somewhere more appropriate once message filter infrastructure is complete

            //FIXME: these special cases are slightly broken for the case where the member but not the interface is specified in the message
            if (method_call.Interface == "org.freedesktop.DBus.Peer")
            {
                switch (method_call.Member)
                {
                case "Ping":
                    Send(MessageHelper.ConstructReply(method_call));
                    return;

                case "GetMachineId":
                    if (MachineId != UUID.Zero)
                    {
                        Send(MessageHelper.ConstructReply(method_call, MachineId.ToString()));
                        return;
                    }
                    else
                    {
                        // Might want to send back an error here?
                    }
                    break;
                }
            }

            if (method_call.Interface == "org.freedesktop.DBus.Introspectable" && method_call.Member == "Introspect")
            {
                Introspector intro = new Introspector();
                intro.root_path = method_call.Path;
                intro.WriteStart();

                //FIXME: do this properly
                //this is messy and inefficient
                List <string> linkNodes = new List <string> ();
                int           depth     = method_call.Path.Decomposed.Length;
                foreach (ObjectPath pth in RegisteredObjects.Keys)
                {
                    if (pth.Value == (method_call.Path.Value))
                    {
                        ExportObject exo = (ExportObject)RegisteredObjects[pth];
                        exo.WriteIntrospect(intro);
                    }
                    else
                    {
                        for (ObjectPath cur = pth; cur != null; cur = cur.Parent)
                        {
                            if (cur.Value == method_call.Path.Value)
                            {
                                string linkNode = pth.Decomposed[depth];
                                if (!linkNodes.Contains(linkNode))
                                {
                                    intro.WriteNode(linkNode);
                                    linkNodes.Add(linkNode);
                                }
                            }
                        }
                    }
                }

                intro.WriteEnd();

                Message reply = MessageHelper.ConstructReply(method_call, intro.xml);
                Send(reply);
                return;
            }

            BusObject bo;

            if (RegisteredObjects.TryGetValue(method_call.Path, out bo))
            {
                ExportObject eo = (ExportObject)bo;
                eo.HandleMethodCall(method_call);
            }
            else
            {
                MaybeSendUnknownMethodError(method_call);
            }
        }