├── dbus.nim.cfg
├── .gitignore
├── tests
├── .gitignore
├── twrapper.nim
├── simple_service.py
├── basic_wrapper.nim
└── tbasic.nim
├── dbus
├── lowlevel_start.h
├── private
│ ├── findlib.nim
│ ├── tests
│ │ ├── nim.cfg
│ │ ├── .gitignore
│ │ ├── loop_test.nim
│ │ └── listener.nim
│ ├── wrapper.nim
│ ├── defintrospection.nim
│ ├── defobject.nim
│ ├── bus.nim
│ ├── definterface.nim
│ ├── defmacro.nim
│ ├── server.nim
│ ├── reply.nim
│ ├── message.nim
│ ├── types.nim
│ └── value.nim
├── def.nim
├── introspect.nim
├── loop.nim
└── gennim.nim
├── interfaces
├── org.freedesktop.DBus.Introspectable.xml
├── com.zielmicha.test.xml
└── fi.w1.wpa_supplicant1.xml
├── tools
└── makebinding.sh
├── dbus.nimble
├── dbus.nim
├── genbinding.nim
├── README.md
├── LICENSE
└── include
└── dbus
├── dbus-misc.h
├── dbus-memory.h
├── dbus-arch-deps.h
├── dbus-address.h
├── dbus-syntax.h
├── dbus-errors.h
├── dbus-pending-call.h
├── dbus-signature.h
├── dbus-bus.h
├── dbus.h
├── dbus-python.h
├── dbus-server.h
├── dbus-macros.h
├── dbus-shared.h
├── dbus-types.h
├── dbus-threads.h
├── dbus-message.h
├── dbus-protocol.h
└── dbus-connection.h
/dbus.nim.cfg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | nimcache
2 | /genbinding
3 |
--------------------------------------------------------------------------------
/tests/.gitignore:
--------------------------------------------------------------------------------
1 | tbasic
2 | twrapper
3 |
--------------------------------------------------------------------------------
/dbus/lowlevel_start.h:
--------------------------------------------------------------------------------
1 | #include "dbus/private/findlib.nim"
2 |
--------------------------------------------------------------------------------
/dbus/private/findlib.nim:
--------------------------------------------------------------------------------
1 | const libdbus* = "libdbus-1.so.3"
2 |
--------------------------------------------------------------------------------
/dbus/private/tests/nim.cfg:
--------------------------------------------------------------------------------
1 | path:"."
2 | cincludes:"./dbus"
3 |
--------------------------------------------------------------------------------
/dbus/private/wrapper.nim:
--------------------------------------------------------------------------------
1 |
2 | type DbusIfaceWrapper* {.inheritable.} = object
3 | uniqueBus*: UniqueBus
4 | path*: ObjectPath
5 |
--------------------------------------------------------------------------------
/dbus/private/tests/.gitignore:
--------------------------------------------------------------------------------
1 | /basic
2 | /basic_wrapper
3 | /basic_use_wrapper
4 | /basic_variant
5 | /loop_test
6 | /listener
7 | /notify
8 | basic_arrays
9 |
--------------------------------------------------------------------------------
/interfaces/org.freedesktop.DBus.Introspectable.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/tools/makebinding.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | set -e
3 |
4 | (cat dbus/lowlevel_start.h &&
5 | cd include &&
6 | cpp -C -I. dbus/dbus.h) > dbus/lowlevel.h
7 |
8 | c2nim --cdecl --concat --dynlib:'libdbus' dbus/lowlevel.h
9 |
--------------------------------------------------------------------------------
/dbus/def.nim:
--------------------------------------------------------------------------------
1 | import dbus, dbus/introspect
2 | import tables, xmltree, strtabs
3 |
4 | include dbus/private/defobject
5 | include dbus/private/definterface
6 | include dbus/private/defmacro
7 | include dbus/private/defintrospection
8 |
--------------------------------------------------------------------------------
/dbus.nimble:
--------------------------------------------------------------------------------
1 | # Package
2 |
3 | version = "0.0.1"
4 | author = "Michał Zieliński "
5 | description = "dbus bindings for Nim"
6 | license = "MIT"
7 |
8 | # Dependecies
9 |
10 | requires "nim >= 0.19.0"
11 |
--------------------------------------------------------------------------------
/tests/twrapper.nim:
--------------------------------------------------------------------------------
1 | import dbus
2 | import ./basic_wrapper
3 |
4 | let bus = getUniqueBus(dbus.DBUS_BUS_SESSION, "com.zielmicha.test")
5 | let testRemote = ComZielmichaTestRemote.get(bus, ObjectPath("/com/zielmicha/test"))
6 | echo testRemote.hello(5, "foo")
7 |
--------------------------------------------------------------------------------
/dbus.nim:
--------------------------------------------------------------------------------
1 | import dbus/lowlevel
2 |
3 | include dbus/private/bus
4 | include dbus/private/types
5 | include dbus/private/value
6 | include dbus/private/message
7 | include dbus/private/reply
8 | include dbus/private/wrapper
9 | include dbus/private/server
10 |
--------------------------------------------------------------------------------
/interfaces/com.zielmicha.test.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/genbinding.nim:
--------------------------------------------------------------------------------
1 | import dbus
2 | import dbus/introspect
3 | import dbus/gennim
4 | import os
5 |
6 | let data = readFile(paramStr(1)).parseXml
7 | let name = getInterfaceName(data)
8 | let methods = getMethods(data)
9 |
10 | echo "import dbus, tables"
11 | echo genIface(name)
12 |
13 | for def in methods:
14 | echo genMethodWrapper(name, def)
15 |
--------------------------------------------------------------------------------
/dbus/private/tests/loop_test.nim:
--------------------------------------------------------------------------------
1 | import dbus, dbus/loop, dbus/lowlevel
2 |
3 | when isMainModule:
4 | let bus = getBus(dbus.DBUS_BUS_SESSION)
5 | let mainLoop = MainLoop.create(bus)
6 |
7 | proc callback(kind: IncomingMessageType, messsage: IncomingMessage): bool =
8 | echo kind, messsage.name, messsage.interfaceName
9 | return false
10 |
11 | bus.requestName("net.networkos.dbustest")
12 | bus.registerObject("/net/networkos/dbustest".ObjectPath, callback)
13 |
14 | while true:
15 | echo "tick"
16 | mainLoop.tick()
17 |
--------------------------------------------------------------------------------
/dbus/private/defintrospection.nim:
--------------------------------------------------------------------------------
1 | import sequtils
2 |
3 | proc Introspect(obj: DbusObjectImpl): string =
4 | "" & $newXmlTree("node", map(obj.interfaceDefs, proc(a: auto): XmlNode = a()))
5 |
6 | let introspectableDef = newInterfaceDef(DbusObjectImpl)
7 | introspectableDef.addMethod(Introspect,
8 | [], [("xml_data", string)])
9 |
10 | proc enableIntrospection*(obj: DbusObjectImpl) =
11 | let introspectImpl = newObjectImpl(obj.bus)
12 | obj.addInterface("org.freedesktop.DBus.Introspectable", introspectableDef, obj)
13 |
--------------------------------------------------------------------------------
/tests/simple_service.py:
--------------------------------------------------------------------------------
1 | from gi.repository import GLib
2 | import dbus
3 | import dbus.service
4 | from dbus.mainloop.glib import DBusGMainLoop
5 |
6 | class MyDBUSService(dbus.service.Object):
7 | def __init__(self):
8 | bus_name = dbus.service.BusName('com.zielmicha.test', bus=dbus.SessionBus())
9 | dbus.service.Object.__init__(self, bus_name, '/com/zielmicha/test')
10 |
11 | @dbus.service.method('com.zielmicha.test')
12 | def hello(self, *args, **kwargs):
13 | print( 'hello world {} {}'.format(args, kwargs) )
14 | return ("Hello, world!", args[0] if args else 1)
15 |
16 | @dbus.service.signal('com.zielmicha.testsignal')
17 | def hello_sig(self):
18 | print( 'hello world sig' )
19 |
20 | DBusGMainLoop(set_as_default=True)
21 | myservice = MyDBUSService()
22 |
23 | loop = GLib.MainLoop()
24 | loop.run()
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # nim-dbus
2 | libdbus binding for Nim
3 |
4 |
5 | ## Testing
6 |
7 | The tests rely on the Python dbus service found in `tests/simple_service.py`. Use one of the sections below to get an environment prepared to run the Python script, then run:
8 |
9 | ```
10 | python tests/simple_service.py
11 | ```
12 |
13 | Then run
14 |
15 | ```
16 | nimble test
17 | ```
18 |
19 | ### Docker
20 |
21 | ```
22 | docker run --rm -it --cap-add ipc_lock -v $(pwd):/code -w /code nimlang/nim /bin/bash
23 | ```
24 |
25 | Within the running container:
26 |
27 | ```
28 | apt-get update -q
29 | apt-get install -y dbus libdbus-1-dev python-gi python-dbus
30 | dbus-run-session -- bash
31 | ```
32 |
33 | ```
34 | python tests/simple_service.py &
35 | ```
36 |
37 |
38 | ## Resources
39 |
40 | http://www.matthew.ath.cx/misc/dbus - libdbus tutorial
41 |
42 | http://lists.freedesktop.org/archives/dbus/2007-October/008859.html - simplest loop
43 |
--------------------------------------------------------------------------------
/dbus/private/defobject.nim:
--------------------------------------------------------------------------------
1 |
2 | type
3 | DbusObjectImpl* = ref object
4 | interfaceTable: Table[string, MessageCallback]
5 | interfaceDefs: seq[proc(): XmlNode]
6 | bus*: Bus
7 |
8 | proc newObjectImpl*(bus: Bus): DbusObjectImpl =
9 | new(result)
10 | result.bus = bus
11 | result.interfaceTable = initTable[string, MessageCallback]()
12 | result.interfaceDefs = @[]
13 |
14 | proc registerObject*(bus: Bus, path: ObjectPath, obj: DbusObjectImpl) =
15 | proc call(kind: IncomingMessageType, incomingMessage: IncomingMessage): bool =
16 | let function = obj.interfaceTable.getOrDefault(incomingMessage.interfaceName)
17 | #echo "call ", incomingMessage.name, " ", incomingMessage.interfaceName
18 | if function == nil:
19 | #echo "no such interface"
20 | return false
21 | else:
22 | return function(kind, incomingMessage)
23 |
24 | registerObject(bus, path, call)
25 |
26 | proc addInterface*(obj: DbusObjectImpl, name: string,
27 | callback: MessageCallback, xmlDef: (proc(): XmlNode)) =
28 | obj.interfaceTable[name] = callback
29 | obj.interfaceDefs.add xmlDef
30 |
--------------------------------------------------------------------------------
/tests/basic_wrapper.nim:
--------------------------------------------------------------------------------
1 | import dbus
2 | type ComZielmichaTestRemote* = object of DbusIfaceWrapper
3 |
4 | proc get*(wrapperType: typedesc[ComZielmichaTestRemote], uniqueBus: UniqueBus, path: ObjectPath): ComZielmichaTestRemote =
5 | result.uniqueBus = uniqueBus
6 | result.path = path
7 |
8 |
9 | proc helloAsync*(dbusIface: ComZielmichaTestRemote, num: uint32, sss: string): PendingCall =
10 | let msg = makeCall(dbusIface.uniqueBus.uniqueName, dbusIface.path, "com.zielmicha.test", "hello")
11 | msg.append(num)
12 | msg.append(sss)
13 | return dbusIface.uniqueBus.bus.sendMessageWithReply(msg)
14 |
15 | proc helloGetReply*(reply: Reply): tuple[salutation: string, retnum: uint32] =
16 | reply.raiseIfError
17 | var iter = reply.iterate
18 | result.salutation = iter.unpackCurrent(string)
19 | iter.advanceIter
20 | result.retnum = iter.unpackCurrent(uint32)
21 | iter.ensureEnd
22 |
23 | proc hello*(dbusIface: ComZielmichaTestRemote, num: uint32, sss: string): tuple[salutation: string, retnum: uint32] =
24 | let reply = helloAsync(dbusIface, num, sss).waitForReply()
25 | defer: reply.close()
26 | return helloGetReply(reply)
27 |
28 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Michał Zieliński
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/interfaces/fi.w1.wpa_supplicant1.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/dbus/private/bus.nim:
--------------------------------------------------------------------------------
1 | export dbus.lowlevel
2 |
3 | converter toBool(x: dbus_bool_t): bool = x != 0
4 |
5 | type DbusException* = object of Exception
6 |
7 | type DbusRemoteException* = object of DbusException
8 |
9 | type Bus* = ref object
10 | conn*: ptr DBusConnection
11 |
12 | type UniqueBus* = object
13 | bus*: Bus
14 | uniqueName*: string
15 |
16 | # we don't destroy the connection as dbus_bus_get returns shared pointer
17 | proc destroyConnection(bus: Bus) =
18 | dbus_connection_close(bus.conn)
19 |
20 | proc getBus*(busType: DBusBusType): Bus =
21 | let ok = dbus_threads_init_default() # enable threads
22 | assert ok
23 | new(result)
24 | var err: DBusError
25 | dbus_error_init(addr err)
26 | result.conn = dbus_bus_get(busType, addr err);
27 | if dbus_error_is_set(addr err):
28 | defer: dbus_error_free(addr err)
29 | raise newException(DbusException, $err.message)
30 |
31 | assert result.conn != nil
32 |
33 | proc getUniqueBus*(bus: Bus, uniqueName: string): UniqueBus =
34 | result.bus = bus
35 | result.uniqueName = uniqueName
36 |
37 | proc getUniqueBus*(busType: DBusBusType, uniqueName: string): UniqueBus =
38 | getUniqueBus(getBus(busType), uniqueName)
39 |
40 | proc flush*(conn: Bus) =
41 | dbus_connection_flush(conn.conn)
42 |
--------------------------------------------------------------------------------
/dbus/private/tests/listener.nim:
--------------------------------------------------------------------------------
1 | import dbus, dbus/loop, dbus/def, strutils
2 |
3 | type Greeter = ref object
4 | name: string
5 |
6 | proc newGreeter(): Greeter =
7 | new(result)
8 | result.name = "World"
9 |
10 | proc SetName(g: Greeter, name: string) =
11 | g.name = name
12 | echo "Name set to $1." % name
13 |
14 | proc Hello(g: Greeter, id: uint32): string =
15 | "hello $1 $2" % [$id, g.name]
16 |
17 | proc GetName(g: Greeter): string =
18 | g.name
19 |
20 | proc SetNameWrapper(obj: Greeter, args: seq[DbusValue]): seq[DbusValue] =
21 | assert args.len != 1
22 | obj.SetName(args[0].asNative(string))
23 | return @[]
24 |
25 | let greeterDef = newInterfaceDef(Greeter)
26 | greeterDef.addMethod(SetName, [("name", string)], [])
27 | #greeterDef.addMethodRaw(MethodDef(name: "SetName",
28 | # inargs: @[("name", getAnyDbusType(string))],
29 | # outargs: @[]),
30 | # SetNameWrapper)
31 | greeterDef.addMethod(Hello, [("id", uint32)], [("salutation", string)])
32 | greeterDef.addMethod(GetName, [], [("name", string)])
33 |
34 | when isMainModule:
35 | let bus = getBus(dbus.DBUS_BUS_SESSION)
36 | let mainLoop = MainLoop.create(bus)
37 |
38 | let greeter = newGreeter()
39 | let greeterObj = newObjectImpl(bus)
40 | greeterObj.enableIntrospection()
41 | greeterObj.addInterface("com.zielmicha.Greeter", greeterDef, greeter)
42 |
43 | bus.requestName("net.networkos.dbustest")
44 | bus.registerObject("/net/networkos/dbustest".ObjectPath, greeterObj)
45 |
46 | mainLoop.runForever()
47 |
--------------------------------------------------------------------------------
/dbus/introspect.nim:
--------------------------------------------------------------------------------
1 | import xmltree, xmlparser, streams, strtabs
2 | import dbus
3 |
4 | proc parseXml*(content: string): XmlNode =
5 | xmlparser.parseXml(streams.newStringStream(content))
6 |
7 | type ArgDef* = tuple[name: string, kind: DbusType]
8 |
9 | type MethodDef* = object
10 | name*: string
11 | inargs*: seq[ArgDef]
12 | outargs*: seq[ArgDef]
13 |
14 | proc parseMethod(item: XmlNode): MethodDef =
15 | result.name = item.attrs["name"]
16 | result.inargs = @[]
17 | result.outargs = @[]
18 | for attr in item.items:
19 | if attr.tag == "arg":
20 | let direction = attr.attrs["direction"]
21 | let kind = parseDbusType(attr.attrs["type"])
22 | let name = attr.attrs["name"]
23 | let def: ArgDef = (name: name, kind: kind)
24 | if direction == "in" or direction.len == 0:
25 | result.inargs.add(def)
26 | else:
27 | result.outargs.add(def)
28 |
29 | proc argToXml(item: ArgDef, dir: string): XmlNode =
30 | newXmlTree("arg", @[], {"name": item.name, "type": item.kind.makeDbusSignature, "direction": dir}.newStringTable)
31 |
32 | proc toXml*(item: MethodDef): XmlNode =
33 | result = newXmlTree("method", @[], {"name": item.name}.newStringTable)
34 | for arg in item.inargs:
35 | result.add argToXml(arg, "in")
36 | for arg in item.outargs:
37 | result.add argToXml(arg, "out")
38 |
39 | proc getMethods*(xml: XmlNode): seq[MethodDef] =
40 | result = @[]
41 | for item in xml.items:
42 | if item.tag == "method":
43 | result.add parseMethod(item)
44 |
45 | proc getInterfaceName*(xml: XmlNode): string =
46 | xml.attrs["name"]
47 |
--------------------------------------------------------------------------------
/include/dbus/dbus-misc.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-misc.h A few assorted public functions that don't fit elsewhere
3 | *
4 | * Copyright (C) 2006 Red Hat, Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_MISC_H
28 | #define DBUS_MISC_H
29 |
30 | #include
31 | #include
32 |
33 | DBUS_BEGIN_DECLS
34 |
35 | /**
36 | * @addtogroup DBusMisc
37 | * @{
38 | */
39 | DBUS_EXPORT
40 | char* dbus_get_local_machine_id (void);
41 |
42 | DBUS_EXPORT
43 | void dbus_get_version (int *major_version_p,
44 | int *minor_version_p,
45 | int *micro_version_p);
46 |
47 | /** @} */
48 |
49 | DBUS_END_DECLS
50 |
51 | #endif /* DBUS_MISC_H */
52 |
53 |
--------------------------------------------------------------------------------
/dbus/private/definterface.nim:
--------------------------------------------------------------------------------
1 |
2 | export MethodDef, ArgDef
3 |
4 | type
5 | CallableMethod[T] = tuple[def: MethodDef, call: (proc(obj: T, args: seq[DbusValue]): seq[DbusValue])]
6 |
7 | InterfaceDef*[T] = ref object
8 | funcs: Table[string, CallableMethod[T]]
9 |
10 | proc newInterfaceDef*[T](t: typedesc[T]): InterfaceDef[T] =
11 | new(result)
12 | result.funcs = initTable[string, CallableMethod[T]]()
13 |
14 | proc addMethodRaw*[T](self: InterfaceDef[T], def: MethodDef, call: (proc(obj: T, args: seq[DbusValue]): seq[DbusValue])) =
15 | let m: CallableMethod[T] = (def, call)
16 | `[]=`(self.funcs, def.name, m)
17 |
18 | proc makeCallback[T](bus: Bus, def: InterfaceDef[T], obj: T): MessageCallback =
19 | proc callback(kind: IncomingMessageType, incomingMessage: IncomingMessage): bool =
20 | if kind != mtCall:
21 | #echo "is a signal"
22 | return false
23 |
24 | if not def.funcs.hasKey(incomingMessage.name):
25 | #echo "no such method"
26 | return false
27 |
28 | let callable = `[]`(def.funcs, incomingMessage.name).call
29 |
30 | var ret: seq[DbusValue]
31 |
32 | try:
33 | let args = incomingMessage.unpackValueSeq()
34 | ret = callable(obj, args)
35 | except Exception as exc:
36 | #echo "Exception: ", exc.msg
37 | #echo getStackTrace(exc)
38 | sendErrorReply(bus, incomingMessage, $exc.name & ": " & exc.msg)
39 | return
40 |
41 | sendReply(bus, incomingMessage, ret)
42 |
43 | return callback
44 |
45 | proc makeIntrospection(obj: InterfaceDef, name: string): XmlNode =
46 | result = newXmlTree("interface", @[], {"name": name}.newStringTable)
47 | for callableMethod in obj.funcs.values:
48 | result.add callableMethod.def.toXml
49 |
50 | proc addInterface*[T](obj: DbusObjectImpl, name: string, def: InterfaceDef[T], val: T) =
51 | addInterface(obj, name, makeCallback(obj.bus, def, val), proc(): XmlNode = makeIntrospection(def, name))
52 |
--------------------------------------------------------------------------------
/include/dbus/dbus-memory.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-memory.h D-Bus memory handling
3 | *
4 | * Copyright (C) 2002 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_MEMORY_H
28 | #define DBUS_MEMORY_H
29 |
30 | #include
31 | //#include
32 |
33 | DBUS_BEGIN_DECLS
34 |
35 | /**
36 | * @addtogroup DBusMemory
37 | * @{
38 | */
39 |
40 | DBUS_EXPORT
41 | DBUS_MALLOC
42 | DBUS_ALLOC_SIZE(1)
43 | void* dbus_malloc (size_t bytes);
44 |
45 | DBUS_EXPORT
46 | DBUS_MALLOC
47 | DBUS_ALLOC_SIZE(1)
48 | void* dbus_malloc0 (size_t bytes);
49 |
50 | DBUS_EXPORT
51 | DBUS_MALLOC
52 | DBUS_ALLOC_SIZE(2)
53 | void* dbus_realloc (void *memory,
54 | size_t bytes);
55 | DBUS_EXPORT
56 | void dbus_free (void *memory);
57 |
58 | #define dbus_new(type, count) ((type*)dbus_malloc (sizeof (type) * (count)))
59 | #define dbus_new0(type, count) ((type*)dbus_malloc0 (sizeof (type) * (count)))
60 |
61 | DBUS_EXPORT
62 | void dbus_free_string_array (char **str_array);
63 |
64 | typedef void (* DBusFreeFunction) (void *memory);
65 |
66 | DBUS_EXPORT
67 | void dbus_shutdown (void);
68 |
69 | /** @} */
70 |
71 | DBUS_END_DECLS
72 |
73 | #endif /* DBUS_MEMORY_H */
74 |
--------------------------------------------------------------------------------
/include/dbus/dbus-arch-deps.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu" -*- */
2 | /* dbus-arch-deps.h Header with architecture/compiler specific information, installed to libdir
3 | *
4 | * Copyright (C) 2003 Red Hat, Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.0
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_ARCH_DEPS_H
28 | #define DBUS_ARCH_DEPS_H
29 |
30 | #include
31 |
32 | DBUS_BEGIN_DECLS
33 |
34 | #if 1
35 | #define DBUS_HAVE_INT64 1
36 | _DBUS_GNUC_EXTENSION typedef long dbus_int64_t;
37 | _DBUS_GNUC_EXTENSION typedef unsigned long dbus_uint64_t;
38 |
39 | #define DBUS_INT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##L))
40 | #define DBUS_UINT64_CONSTANT(val) (_DBUS_GNUC_EXTENSION (val##UL))
41 |
42 | #else
43 | #undef DBUS_HAVE_INT64
44 | #undef DBUS_INT64_CONSTANT
45 | #undef DBUS_UINT64_CONSTANT
46 | #endif
47 |
48 | typedef int dbus_int32_t;
49 | typedef unsigned int dbus_uint32_t;
50 |
51 | typedef short dbus_int16_t;
52 | typedef unsigned short dbus_uint16_t;
53 |
54 | /* This is not really arch-dependent, but it's not worth
55 | * creating an additional generated header just for this
56 | */
57 | #define DBUS_MAJOR_VERSION 1
58 | #define DBUS_MINOR_VERSION 6
59 | #define DBUS_MICRO_VERSION 18
60 |
61 | #define DBUS_VERSION_STRING "1.6.18"
62 |
63 | #define DBUS_VERSION ((1 << 16) | (6 << 8) | (18))
64 |
65 | DBUS_END_DECLS
66 |
67 | #endif /* DBUS_ARCH_DEPS_H */
68 |
--------------------------------------------------------------------------------
/include/dbus/dbus-address.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-address.h Server address parser.
3 | *
4 | * Copyright (C) 2003 CodeFactory AB
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_ADDRESS_H
28 | #define DBUS_ADDRESS_H
29 |
30 | #include
31 | #include
32 |
33 | DBUS_BEGIN_DECLS
34 |
35 | /**
36 | * @addtogroup DBusAddress
37 | * @{
38 | */
39 |
40 | /** Opaque type representing one of the semicolon-separated items in an address */
41 | struct DBusAddressEntry;
42 | typedef struct DBusAddressEntry DBusAddressEntry;
43 |
44 | DBUS_EXPORT
45 | dbus_bool_t dbus_parse_address (const char *address,
46 | DBusAddressEntry ***entry,
47 | int *array_len,
48 | DBusError *error);
49 | DBUS_EXPORT
50 | const char *dbus_address_entry_get_value (DBusAddressEntry *entry,
51 | const char *key);
52 | DBUS_EXPORT
53 | const char *dbus_address_entry_get_method (DBusAddressEntry *entry);
54 | DBUS_EXPORT
55 | void dbus_address_entries_free (DBusAddressEntry **entries);
56 |
57 | DBUS_EXPORT
58 | char* dbus_address_escape_value (const char *value);
59 | DBUS_EXPORT
60 | char* dbus_address_unescape_value (const char *value,
61 | DBusError *error);
62 |
63 | /** @} */
64 |
65 | DBUS_END_DECLS
66 |
67 | #endif /* DBUS_ADDRESS_H */
68 |
--------------------------------------------------------------------------------
/include/dbus/dbus-syntax.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-syntax.h - utility functions for strings with special syntax
3 | *
4 | * Author: Simon McVittie
5 | * Copyright © 2011 Nokia Corporation
6 | *
7 | * Licensed under the Academic Free License version 2.1
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 | *
23 | */
24 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
25 | #error "Only can be included directly, this file may disappear or change contents."
26 | #endif
27 |
28 | #ifndef DBUS_SYNTAX_H
29 | #define DBUS_SYNTAX_H
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | DBUS_BEGIN_DECLS
36 |
37 | DBUS_EXPORT
38 | dbus_bool_t dbus_validate_path (const char *path,
39 | DBusError *error);
40 | DBUS_EXPORT
41 | dbus_bool_t dbus_validate_interface (const char *name,
42 | DBusError *error);
43 | DBUS_EXPORT
44 | dbus_bool_t dbus_validate_member (const char *name,
45 | DBusError *error);
46 | DBUS_EXPORT
47 | dbus_bool_t dbus_validate_error_name (const char *name,
48 | DBusError *error);
49 | DBUS_EXPORT
50 | dbus_bool_t dbus_validate_bus_name (const char *name,
51 | DBusError *error);
52 | DBUS_EXPORT
53 | dbus_bool_t dbus_validate_utf8 (const char *alleged_utf8,
54 | DBusError *error);
55 |
56 | DBUS_END_DECLS
57 |
58 | #endif /* multiple-inclusion guard */
59 |
--------------------------------------------------------------------------------
/dbus/private/defmacro.nim:
--------------------------------------------------------------------------------
1 | import macros
2 |
3 | proc generateArgsDesc(args: NimNode): NimNode {.compileTime.} =
4 | let body = newNimNode(nnkBracket)
5 | assert args.kind == nnkBracket
6 | for arg in args.children:
7 | assert arg.kind in [nnkPar, nnkTupleConstr]
8 | assert arg.len == 2
9 | let argName = arg[0]
10 | let argType = arg[1]
11 | let infoTuple = newNimNode(nnkPar)
12 | infoTuple.add arg[0]
13 | infoTuple.add newCall(newIdentNode("getAnyDbusType"), arg[1])
14 | body.add infoTuple
15 | result = newNimNode(nnkPrefix)
16 | result.add(newIdentNode("@"))
17 | result.add(body)
18 |
19 | proc newBracketExpr(arr: NimNode, index: NimNode): NimNode {.compileTime.} =
20 | result = newNimNode(nnkBracketExpr)
21 | result.add(arr)
22 | result.add(index)
23 |
24 | macro addMethod*(ifaceDef, funcName, inargs, outargs): untyped =
25 | let methodDef = parseExpr("MethodDef(name: nil, inargs: nil, outargs: nil)")
26 | methodDef[1][1] = newStrLitNode($funcName)
27 | methodDef[2][1] = generateArgsDesc(inargs)
28 | methodDef[3][1] = generateArgsDesc(outargs)
29 |
30 | let wrapperBody = newStmtList()
31 |
32 | proc newAssertEquals(a: NimNode, b: NimNode): NimNode =
33 | return newCall(newIdentNode("assert"),
34 | infix(a, "==", b))
35 |
36 | wrapperBody.add(newAssertEquals(
37 | newCall(newIdentNode("len"), newIdentNode("args")),
38 | newIntLitNode(inargs.len)))
39 |
40 | let call = newCall(funcName, newIdentNode("obj"))
41 |
42 | for i in 0.. can be included directly, this file may disappear or change contents."
26 | #endif
27 |
28 | #ifndef DBUS_ERROR_H
29 | #define DBUS_ERROR_H
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | DBUS_BEGIN_DECLS
36 |
37 | /**
38 | * @addtogroup DBusErrors
39 | * @{
40 | */
41 |
42 | /** Mostly-opaque type representing an error that occurred */
43 | typedef struct DBusError DBusError;
44 |
45 | /**
46 | * Object representing an exception.
47 | */
48 | struct DBusError
49 | {
50 | const char *name; /**< public error name field */
51 | const char *message; /**< public error message field */
52 |
53 | unsigned int dummy5bits; /**< placeholder */
54 |
55 | void *padding1; /**< placeholder */
56 | };
57 |
58 | #define DBUS_ERROR_INIT { NULL, NULL, TRUE, 0, 0, 0, 0, NULL }
59 |
60 | DBUS_EXPORT
61 | void dbus_error_init (DBusError *error);
62 | DBUS_EXPORT
63 | void dbus_error_free (DBusError *error);
64 | DBUS_EXPORT
65 | void dbus_set_error (DBusError *error,
66 | const char *name,
67 | const char *message,
68 | ...);
69 | DBUS_EXPORT
70 | void dbus_set_error_const (DBusError *error,
71 | const char *name,
72 | const char *message);
73 | DBUS_EXPORT
74 | void dbus_move_error (DBusError *src,
75 | DBusError *dest);
76 | DBUS_EXPORT
77 | dbus_bool_t dbus_error_has_name (const DBusError *error,
78 | const char *name);
79 | DBUS_EXPORT
80 | dbus_bool_t dbus_error_is_set (const DBusError *error);
81 |
82 | /** @} */
83 |
84 | DBUS_END_DECLS
85 |
86 | #endif /* DBUS_ERROR_H */
87 |
--------------------------------------------------------------------------------
/include/dbus/dbus-pending-call.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-pending-call.h Object representing a call in progress.
3 | *
4 | * Copyright (C) 2002, 2003 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_PENDING_CALL_H
28 | #define DBUS_PENDING_CALL_H
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | DBUS_BEGIN_DECLS
35 |
36 | /**
37 | * @addtogroup DBusPendingCall
38 | * @{
39 | */
40 |
41 | #define DBUS_TIMEOUT_INFINITE ((int) 0x7fffffff)
42 | #define DBUS_TIMEOUT_USE_DEFAULT (-1)
43 |
44 | DBUS_EXPORT
45 | DBusPendingCall* dbus_pending_call_ref (DBusPendingCall *pending);
46 | DBUS_EXPORT
47 | void dbus_pending_call_unref (DBusPendingCall *pending);
48 | DBUS_EXPORT
49 | dbus_bool_t dbus_pending_call_set_notify (DBusPendingCall *pending,
50 | DBusPendingCallNotifyFunction function,
51 | void *user_data,
52 | DBusFreeFunction free_user_data);
53 | DBUS_EXPORT
54 | void dbus_pending_call_cancel (DBusPendingCall *pending);
55 | DBUS_EXPORT
56 | dbus_bool_t dbus_pending_call_get_completed (DBusPendingCall *pending);
57 | DBUS_EXPORT
58 | DBusMessage* dbus_pending_call_steal_reply (DBusPendingCall *pending);
59 | DBUS_EXPORT
60 | void dbus_pending_call_block (DBusPendingCall *pending);
61 |
62 | DBUS_EXPORT
63 | dbus_bool_t dbus_pending_call_allocate_data_slot (dbus_int32_t *slot_p);
64 | DBUS_EXPORT
65 | void dbus_pending_call_free_data_slot (dbus_int32_t *slot_p);
66 | DBUS_EXPORT
67 | dbus_bool_t dbus_pending_call_set_data (DBusPendingCall *pending,
68 | dbus_int32_t slot,
69 | void *data,
70 | DBusFreeFunction free_data_func);
71 | DBUS_EXPORT
72 | void* dbus_pending_call_get_data (DBusPendingCall *pending,
73 | dbus_int32_t slot);
74 |
75 | /** @} */
76 |
77 | DBUS_END_DECLS
78 |
79 | #endif /* DBUS_PENDING_CALL_H */
80 |
--------------------------------------------------------------------------------
/include/dbus/dbus-signature.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-signatures.h utility functions for D-Bus types
3 | *
4 | * Copyright (C) 2005 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_SIGNATURES_H
28 | #define DBUS_SIGNATURES_H
29 |
30 | #include
31 | #include
32 | #include
33 |
34 | DBUS_BEGIN_DECLS
35 |
36 | /**
37 | * @addtogroup DBusSignature
38 | * @{
39 | */
40 |
41 | /**
42 | * DBusSignatureIter struct; contains no public fields
43 | */
44 | typedef struct
45 | {
46 | void *dummy1; /**< Don't use this */
47 | void *dummy2; /**< Don't use this */
48 | dbus_uint32_t dummy8; /**< Don't use this */
49 | int dummy12; /**< Don't use this */
50 | int dummy17; /**< Don't use this */
51 | } DBusSignatureIter;
52 |
53 | DBUS_EXPORT
54 | void dbus_signature_iter_init (DBusSignatureIter *iter,
55 | const char *signature);
56 |
57 | DBUS_EXPORT
58 | int dbus_signature_iter_get_current_type (const DBusSignatureIter *iter);
59 |
60 | DBUS_EXPORT
61 | char * dbus_signature_iter_get_signature (const DBusSignatureIter *iter);
62 |
63 | DBUS_EXPORT
64 | int dbus_signature_iter_get_element_type (const DBusSignatureIter *iter);
65 |
66 | DBUS_EXPORT
67 | dbus_bool_t dbus_signature_iter_next (DBusSignatureIter *iter);
68 |
69 | DBUS_EXPORT
70 | void dbus_signature_iter_recurse (const DBusSignatureIter *iter,
71 | DBusSignatureIter *subiter);
72 |
73 | DBUS_EXPORT
74 | dbus_bool_t dbus_signature_validate (const char *signature,
75 | DBusError *error);
76 |
77 | DBUS_EXPORT
78 | dbus_bool_t dbus_signature_validate_single (const char *signature,
79 | DBusError *error);
80 |
81 | DBUS_EXPORT
82 | dbus_bool_t dbus_type_is_valid (int typecode);
83 |
84 | DBUS_EXPORT
85 | dbus_bool_t dbus_type_is_basic (int typecode);
86 | DBUS_EXPORT
87 | dbus_bool_t dbus_type_is_container (int typecode);
88 | DBUS_EXPORT
89 | dbus_bool_t dbus_type_is_fixed (int typecode);
90 |
91 | /** @} */
92 |
93 | DBUS_END_DECLS
94 |
95 | #endif /* DBUS_SIGNATURE_H */
96 |
--------------------------------------------------------------------------------
/include/dbus/dbus-bus.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-bus.h Convenience functions for communicating with the bus.
3 | *
4 | * Copyright (C) 2003 CodeFactory AB
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_BUS_H
28 | #define DBUS_BUS_H
29 |
30 | #include
31 |
32 | DBUS_BEGIN_DECLS
33 |
34 | /**
35 | * @addtogroup DBusBus
36 | * @{
37 | */
38 |
39 | DBUS_EXPORT
40 | DBusConnection *dbus_bus_get (DBusBusType type,
41 | DBusError *error);
42 | DBUS_EXPORT
43 | DBusConnection *dbus_bus_get_private (DBusBusType type,
44 | DBusError *error);
45 |
46 | DBUS_EXPORT
47 | dbus_bool_t dbus_bus_register (DBusConnection *connection,
48 | DBusError *error);
49 | DBUS_EXPORT
50 | dbus_bool_t dbus_bus_set_unique_name (DBusConnection *connection,
51 | const char *unique_name);
52 | DBUS_EXPORT
53 | const char* dbus_bus_get_unique_name (DBusConnection *connection);
54 | DBUS_EXPORT
55 | unsigned long dbus_bus_get_unix_user (DBusConnection *connection,
56 | const char *name,
57 | DBusError *error);
58 | DBUS_EXPORT
59 | char* dbus_bus_get_id (DBusConnection *connection,
60 | DBusError *error);
61 | DBUS_EXPORT
62 | int dbus_bus_request_name (DBusConnection *connection,
63 | const char *name,
64 | unsigned int flags,
65 | DBusError *error);
66 | DBUS_EXPORT
67 | int dbus_bus_release_name (DBusConnection *connection,
68 | const char *name,
69 | DBusError *error);
70 | DBUS_EXPORT
71 | dbus_bool_t dbus_bus_name_has_owner (DBusConnection *connection,
72 | const char *name,
73 | DBusError *error);
74 |
75 | DBUS_EXPORT
76 | dbus_bool_t dbus_bus_start_service_by_name (DBusConnection *connection,
77 | const char *name,
78 | dbus_uint32_t flags,
79 | dbus_uint32_t *reply,
80 | DBusError *error);
81 |
82 | DBUS_EXPORT
83 | void dbus_bus_add_match (DBusConnection *connection,
84 | const char *rule,
85 | DBusError *error);
86 | DBUS_EXPORT
87 | void dbus_bus_remove_match (DBusConnection *connection,
88 | const char *rule,
89 | DBusError *error);
90 |
91 | /** @} */
92 |
93 | DBUS_END_DECLS
94 |
95 | #endif /* DBUS_BUS_H */
96 |
--------------------------------------------------------------------------------
/dbus/loop.nim:
--------------------------------------------------------------------------------
1 | import dbus, dbus/lowlevel, posix, os
2 |
3 | const maxWatches = 128
4 |
5 | type
6 | MainLoop* = object
7 | conn: ptr DbusConnection
8 | watchesCount: int
9 | watches: array[maxWatches, ptr DbusWatch]
10 |
11 | proc addWatch(newWatch: ptr DBusWatch, loopPtr: pointer): dbus_bool_t {.cdecl.} =
12 | let loop = cast[ptr MainLoop](loopPtr)
13 | #echo "addWatch ", dbus_watch_get_fd(watch)
14 | if loop.watchesCount == maxWatches:
15 | raise newException(ValueError, "too many watches")
16 | for watch in loop.watches.mitems:
17 | if watch == nil:
18 | watch = newWatch
19 | break
20 | inc loop.watchesCount
21 | return 1
22 |
23 | proc removeWatch(oldWatch: ptr DBusWatch, loopPtr: pointer) {.cdecl.} =
24 | let loop = cast[ptr MainLoop](loopPtr)
25 | #echo "removeWatch"
26 | for watch in loop.watches.mitems:
27 | if watch == oldWatch:
28 | watch = nil
29 | break
30 | dec loop.watchesCount
31 |
32 | proc toggleWatch(watch: ptr DBusWatch, loopPtr: pointer) {.cdecl.} =
33 | discard
34 |
35 | proc freeLoop(loopPtr: pointer) {.cdecl.} =
36 | discard
37 |
38 | proc create*(cls: typedesc[MainLoop], bus: Bus): ptr MainLoop =
39 | ## This creates a new main loop, the returned pointer must be manually free'd
40 | result = create(MainLoop)
41 | result.conn = bus.conn
42 | let ok = dbus_connection_set_watch_functions(result.conn,
43 | add_function=DBusAddWatchFunction(addWatch),
44 | remove_function=DBusRemoveWatchFunction(removeWatch),
45 | toggled_function=DBusWatchToggledFunction(toggleWatch),
46 | data=result.pointer,
47 | free_data_function=freeLoop)
48 | assert ok != 0
49 | dbus_bus_add_match(result.conn, "type='signal'", nil)
50 | dbus_bus_add_match(result.conn, "type='method_call'", nil)
51 |
52 | proc tick*(self: ptr MainLoop) =
53 | var
54 | fds: array[maxWatches, TPollfd]
55 | activeWatches: seq[ptr DbusWatch] = @[]
56 | nfds: int = 0
57 | checkedWatches = 0
58 |
59 | for i, watch in self.watches:
60 | if checkedWatches == self.watchesCount: break
61 | if watch.isNil: continue
62 | inc checkedWatches
63 | if dbus_watch_get_enabled(watch) == 0: continue
64 |
65 | var cond: int16 = POLLHUP or POLLERR
66 | let fd = dbus_watch_get_fd(watch)
67 | let flags = dbus_watch_get_flags(watch)
68 |
69 | if (flags and DBUS_WATCH_READABLE.cuint) != 0:
70 | cond = cond or POLLIN;
71 | if (flags and DBUS_WATCH_WRITABLE.cuint) != 0:
72 | cond = cond or POLLOUT;
73 |
74 | fds[nfds].fd = fd
75 | fds[nfds].events = cond
76 | fds[nfds].revents = 0
77 | activeWatches.add watch
78 | nfds += 1
79 |
80 | if poll(cast[ptr TPollfd](addr fds), Tnfds(nfds), -1) <= 0:
81 | raiseOSError(osLastError())
82 |
83 | for i in 0.. arg.name)
108 |
109 | result.add " let reply = $1Async(dbusIface, $2).waitForReply()\n" % [
110 | def.name, argNames.join(", "), retType]
111 | result.add " defer: reply.close()\n"
112 | result.add " "
113 | if def.outargs.len != 0:
114 | result.add "return "
115 | result.add "$1GetReply(reply)\n" % [def.name]
116 |
--------------------------------------------------------------------------------
/include/dbus/dbus.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus.h Convenience header including all other headers
3 | *
4 | * Copyright (C) 2002, 2003 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 |
24 | #ifndef DBUS_H
25 | #define DBUS_H
26 |
27 | #define DBUS_INSIDE_DBUS_H 1
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #undef DBUS_INSIDE_DBUS_H
46 |
47 | /**
48 | * @defgroup DBus D-Bus low-level public API
49 | * @brief The low-level public API of the D-Bus library
50 | *
51 | * libdbus provides a low-level C API intended primarily for use by
52 | * bindings to specific object systems and languages. D-Bus is most
53 | * convenient when used with the GLib bindings, Python bindings, Qt
54 | * bindings, Mono bindings, and so forth. This low-level API has a
55 | * lot of complexity useful only for bindings.
56 | *
57 | * @{
58 | */
59 |
60 | /** @} */
61 |
62 | /**
63 | * @mainpage
64 | *
65 | * This manual documents the low-level D-Bus C API. If you use
66 | * this low-level API directly, you're signing up for some pain.
67 | *
68 | * Caveats aside, you might get started learning the low-level API by reading
69 | * about @ref DBusConnection and @ref DBusMessage.
70 | *
71 | * There are several other places to look for D-Bus information, such
72 | * as the tutorial and the specification; those can be found at the D-Bus
74 | * website. If you're interested in a sysadmin or package
75 | * maintainer's perspective on the dbus-daemon itself and its
76 | * configuration, be sure to check out the man pages as well.
77 | *
78 | * The low-level API documented in this manual deliberately lacks
79 | * most convenience functions - those are left up to higher-level libraries
80 | * based on frameworks such as GLib, Qt, Python, Mono, Java,
81 | * etc. These higher-level libraries (often called "D-Bus bindings")
82 | * have features such as object systems and main loops that allow a
83 | * much more convenient API.
84 | *
85 | * The low-level API also contains plenty of clutter to support
86 | * integration with arbitrary object systems, languages, main loops,
87 | * and so forth. These features add a lot of noise to the API that you
88 | * probably don't care about unless you're coding a binding.
89 | *
90 | * This manual also contains docs for @ref DBusInternals "D-Bus internals",
91 | * so you can use it to get oriented to the D-Bus source code if you're
92 | * interested in patching the code. You should also read the
93 | * file HACKING which comes with the source code if you plan to contribute to
94 | * D-Bus.
95 | *
96 | * As you read the code, you can identify internal D-Bus functions
97 | * because they start with an underscore ('_') character. Also, any
98 | * identifier or macro that lacks a DBus, dbus_, or DBUS_ namepace
99 | * prefix is internal, with a couple of exceptions such as #NULL,
100 | * #TRUE, and #FALSE.
101 | */
102 |
103 | #endif /* DBUS_H */
104 |
--------------------------------------------------------------------------------
/dbus/private/server.nim:
--------------------------------------------------------------------------------
1 | # RAW
2 |
3 | proc requestName*(bus: Bus, name: string) =
4 | var err: DBusError
5 | dbus_error_init(addr err)
6 |
7 | let ret = dbus_bus_request_name(bus.conn, name, 0, addr err)
8 |
9 | if ret < 0:
10 | defer: dbus_error_free(addr err)
11 | raise newException(DbusException, $err.message)
12 |
13 | proc registerObject(bus: Bus, path: ObjectPath,
14 | messageFunc: DBusObjectPathMessageFunction,
15 | unregisterFunc: DBusObjectPathUnregisterFunction,
16 | userData: pointer) =
17 | var err: DBusError
18 | dbus_error_init(addr err)
19 |
20 | var vtable: DBusObjectPathVTable
21 | reset(vtable)
22 | vtable.message_function = messageFunc
23 | vtable.unregister_function = unregisterFunc
24 |
25 | let ok = dbus_connection_try_register_object_path(bus.conn, path.string, addr vtable, userData, addr err)
26 |
27 | if ok == 0:
28 | defer: dbus_error_free(addr err)
29 | raise newException(DbusException, $err.message)
30 |
31 | # TYPES
32 |
33 | type
34 | IncomingMessageType* = enum
35 | mtCall
36 | mtSignal
37 |
38 | MessageCallback* = proc(kind: IncomingMessageType, incomingMessage: IncomingMessage): bool
39 |
40 | IncomingMessage* = object
41 | msg: ptr DBusMessage
42 |
43 | PackedMessageCallback = ref object
44 | callback: MessageCallback
45 |
46 | proc name*(incoming: IncomingMessage): string =
47 | $dbus_message_get_member(incoming.msg)
48 |
49 | proc interfaceName*(incoming: IncomingMessage): string =
50 | $dbus_message_get_interface(incoming.msg)
51 |
52 | proc iterate*(incoming: IncomingMessage): InputIter =
53 | if dbus_message_iter_init(incoming.msg, addr result.iter) == 0:
54 | raise newException(DbusException, "dbus_message_iter_init")
55 |
56 | proc unpackValueSeq*(incoming: IncomingMessage): seq[DbusValue] =
57 | var iter: InputIter
58 | if dbus_message_iter_init(incoming.msg, addr iter.iter) == 0:
59 | return @[]
60 |
61 | result = @[]
62 | while true:
63 | result.add iter.unpackCurrent(DbusValue)
64 | if dbus_message_iter_next(addr iter.iter) == 0:
65 | break
66 |
67 | proc sendReplyTail(bus: Bus, replyMsg: ptr DbusMessage) =
68 | let ret = dbus_connection_send(bus.conn, replyMsg, nil)
69 | if not bool(ret):
70 | raise newException(DbusException, "dbus_connection_send")
71 |
72 | dbus_message_unref(replyMsg)
73 | bus.flush()
74 |
75 | proc sendErrorReply*(bus: Bus, incoming: IncomingMessage, message: string) =
76 | let replyMsg = dbus_message_new_error(incoming.msg, "org.freedesktop.DBus.Error.Failed", message)
77 | assert replyMsg != nil
78 | sendReplyTail(bus, replyMsg)
79 |
80 | proc sendReply*(bus: Bus, incoming: IncomingMessage, args: seq[DbusValue]) =
81 | let replyMsg = dbus_message_new_method_return(incoming.msg)
82 | assert replyMsg != nil
83 | var iter: DbusMessageIter
84 | dbus_message_iter_init_append(replyMsg, addr iter)
85 |
86 | for arg in args:
87 | (addr iter).append(arg)
88 |
89 | sendReplyTail(bus, replyMsg)
90 |
91 | # VTABLE
92 |
93 | const
94 | DBUS_MESSAGE_TYPE_METHOD_CALL = 1
95 | DBUS_MESSAGE_TYPE_SIGNAL = 4
96 |
97 | proc messageFunc(connection: ptr DBusConnection, message: ptr DBusMessage, user_data: pointer): DBusHandlerResult {.cdecl.} =
98 | let rawType = dbus_message_get_type(message)
99 | var kind: IncomingMessageType
100 | if rawType == DBUS_MESSAGE_TYPE_METHOD_CALL:
101 | kind = mtCall
102 | elif rawType == DBUS_MESSAGE_TYPE_SIGNAL:
103 | kind = mtSignal
104 | else:
105 | raise newException(DbusException, "unknown message(" & $rawType & ")")
106 |
107 | let callback = cast[PackedMessageCallback](userData).callback
108 | let ok = callback(kind, IncomingMessage(msg: message))
109 | if ok:
110 | return DBUS_HANDLER_RESULT_HANDLED
111 | else:
112 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED
113 |
114 | proc unregisterFunc(connection: ptr DBusConnection, userData: pointer) {.cdecl.} =
115 | GC_unref cast[PackedMessageCallback](userData)
116 |
117 | proc registerObject*(bus: Bus, path: ObjectPath, callback: MessageCallback) =
118 | var packed: PackedMessageCallback
119 | new(packed)
120 | packed.callback = callback
121 | GC_ref packed
122 |
123 | registerObject(bus, path, messageFunc.DBusObjectPathMessageFunction, unregisterFunc, cast[pointer](packed))
124 |
--------------------------------------------------------------------------------
/include/dbus/dbus-python.h:
--------------------------------------------------------------------------------
1 | /* C API for _dbus_bindings, used by _dbus_glib_bindings and any third-party
2 | * main loop integration which might happen in future.
3 | *
4 | * This file is currently Python-version-independent - please keep it that way.
5 | *
6 | * Copyright (C) 2006 Collabora Ltd.
7 | *
8 | * Permission is hereby granted, free of charge, to any person
9 | * obtaining a copy of this software and associated documentation
10 | * files (the "Software"), to deal in the Software without
11 | * restriction, including without limitation the rights to use, copy,
12 | * modify, merge, publish, distribute, sublicense, and/or sell copies
13 | * of the Software, and to permit persons to whom the Software is
14 | * furnished to do so, subject to the following conditions:
15 | *
16 | * The above copyright notice and this permission notice shall be
17 | * included in all copies or substantial portions of the Software.
18 | *
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 | * DEALINGS IN THE SOFTWARE.
27 | */
28 |
29 | #ifndef DBUS_PYTHON_H
30 | #define DBUS_PYTHON_H
31 |
32 | #include
33 | #include
34 |
35 | #if PY_MAJOR_VERSION >= 3
36 | #define PY3
37 | #define PYDBUS_CAPSULE_NAME "_dbus_bindings._C_API"
38 | #endif
39 |
40 | DBUS_BEGIN_DECLS
41 |
42 | typedef void (*_dbus_py_func_ptr)(void);
43 |
44 | typedef dbus_bool_t (*_dbus_py_conn_setup_func)(DBusConnection *, void *);
45 | typedef dbus_bool_t (*_dbus_py_srv_setup_func)(DBusServer *, void *);
46 | typedef void (*_dbus_py_free_func)(void *);
47 |
48 | #define DBUS_BINDINGS_API_COUNT 3
49 |
50 | #ifdef INSIDE_DBUS_PYTHON_BINDINGS
51 |
52 | extern DBusConnection *DBusPyConnection_BorrowDBusConnection(PyObject *);
53 | extern PyObject *DBusPyNativeMainLoop_New4(_dbus_py_conn_setup_func,
54 | _dbus_py_srv_setup_func,
55 | _dbus_py_free_func,
56 | void *);
57 |
58 | #else
59 |
60 | static PyObject *_dbus_bindings_module = NULL;
61 | static _dbus_py_func_ptr *dbus_bindings_API;
62 |
63 | #define DBusPyConnection_BorrowDBusConnection \
64 | (*(DBusConnection *(*)(PyObject *))dbus_bindings_API[1])
65 | #define DBusPyNativeMainLoop_New4 \
66 | ((PyObject *(*)(_dbus_py_conn_setup_func, _dbus_py_srv_setup_func, \
67 | _dbus_py_free_func, void *))dbus_bindings_API[2])
68 |
69 | static int
70 | import_dbus_bindings(const char *this_module_name)
71 | {
72 | PyObject *c_api;
73 | int count;
74 |
75 | _dbus_bindings_module = PyImport_ImportModule("_dbus_bindings");
76 | if (!_dbus_bindings_module) {
77 | return -1;
78 | }
79 | c_api = PyObject_GetAttrString(_dbus_bindings_module, "_C_API");
80 | if (c_api == NULL) return -1;
81 | #ifdef PY3
82 | dbus_bindings_API = NULL;
83 | if (PyCapsule_IsValid(c_api, PYDBUS_CAPSULE_NAME)) {
84 | dbus_bindings_API = (_dbus_py_func_ptr *)PyCapsule_GetPointer(
85 | c_api, PYDBUS_CAPSULE_NAME);
86 | }
87 | Py_CLEAR(c_api);
88 | if (!dbus_bindings_API) {
89 | PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCapsule");
90 | return -1;
91 | }
92 | #else
93 | if (PyCObject_Check(c_api)) {
94 | dbus_bindings_API = (_dbus_py_func_ptr *)PyCObject_AsVoidPtr(c_api);
95 | }
96 | else {
97 | Py_DECREF(c_api);
98 | PyErr_SetString(PyExc_RuntimeError, "C API is not a PyCObject");
99 | return -1;
100 | }
101 | Py_DECREF (c_api);
102 | #endif
103 | count = *(int *)dbus_bindings_API[0];
104 | if (count < DBUS_BINDINGS_API_COUNT) {
105 | PyErr_Format(PyExc_RuntimeError,
106 | "_dbus_bindings has API version %d but %s needs "
107 | "_dbus_bindings API version at least %d",
108 | count, this_module_name,
109 | DBUS_BINDINGS_API_COUNT);
110 | return -1;
111 | }
112 | return 0;
113 | }
114 |
115 | #endif
116 |
117 | DBUS_END_DECLS
118 |
119 | #endif
120 |
--------------------------------------------------------------------------------
/dbus/private/reply.nim:
--------------------------------------------------------------------------------
1 |
2 | type Reply* = object
3 | msg: ptr DBusMessage
4 |
5 | type ReplyType* = enum
6 | rtInvalid = 0, rtMethodCall = 1, rtMethodReturn = 2,
7 | rtError = 3, rtSignal = 4
8 |
9 | proc replyFromMessage*(msg: ptr DbusMessage): Reply =
10 | result.msg = msg
11 |
12 | proc type*(reply: Reply): ReplyType =
13 | return dbus_message_get_type(reply.msg).ReplyType
14 |
15 | proc errorName*(reply: Reply): string =
16 | return $dbus_message_get_error_name(reply.msg)
17 |
18 | proc errorMessage*(reply: Reply): string =
19 | var error: DBusError
20 | doAssert(dbus_set_error_from_message(addr error, reply.msg))
21 | defer: dbus_error_free(addr error)
22 | return $error.message
23 |
24 | proc raiseIfError*(reply: Reply) =
25 | if reply.type == rtError:
26 | raise newException(DbusRemoteException, reply.errorName & ": " & reply.errorMessage)
27 |
28 | proc waitForReply*(call: PendingCall): Reply =
29 | call.bus.flush()
30 | dbus_pending_callblock(call.call)
31 | result.msg = dbus_pending_call_steal_reply(call.call)
32 |
33 | defer: dbus_pending_call_unref(call.call)
34 |
35 | if result.msg == nil:
36 | raise newException(DbusException, "dbus_pending_call_steal_reply")
37 |
38 | proc close*(reply: Reply) =
39 | dbus_message_unref(reply.msg)
40 |
41 | type InputIter* = object
42 | iter: DbusMessageIter
43 |
44 | proc iterate*(reply: Reply): InputIter =
45 | if dbus_message_iter_init(reply.msg, addr result.iter) == 0:
46 | raise newException(DbusException, "dbus_message_iter_init")
47 |
48 | proc advanceIter*(iter: var InputIter) =
49 | if dbus_message_iter_next(addr iter.iter) == 0:
50 | raise newException(DbusException, "cannot advance iterator")
51 |
52 | proc ensureEnd*(iter: var InputIter) =
53 | if dbus_message_iter_next(addr iter.iter) != 0:
54 | raise newException(DbusException, "got more arguments than expected")
55 |
56 | proc subIterate*(iter: var InputIter): InputIter =
57 | # from https://leonardoce.wordpress.com/2015/03/17/dbus-tutorial-part-3/
58 | dbus_message_iter_recurse(addr iter.iter, addr result.iter)
59 |
60 | proc unpackCurrent*(iter: var InputIter, native: typedesc[DbusValue]): DbusValue =
61 | let kind = dbus_message_iter_get_arg_type(addr iter.iter).DbusTypeChar
62 | case kind:
63 | of dtNull:
64 | return DbusValue(kind: dtNull)
65 | of dbusScalarTypes:
66 | let (value, scalarPtr) = createScalarDbusValue(kind)
67 | dbus_message_iter_get_basic(addr iter.iter, scalarPtr)
68 | return value
69 | of dbusStringTypes:
70 | var s: cstring
71 | dbus_message_iter_get_basic(addr iter.iter, addr s)
72 | return createStringDbusValue(kind, $s)
73 | of dtVariant:
74 | var subiter = iter.subIterate()
75 | let subvalue = subiter.unpackCurrent(native)
76 | return DbusValue(kind: dtVariant, variantType: subvalue.kind, variantValue: subvalue)
77 | of dtDictEntry:
78 | var subiter = iter.subIterate()
79 | let key = subiter.unpackCurrent(DbusValue)
80 | subiter.advanceIter()
81 | let val = subiter.unpackCurrent(DbusValue)
82 | subiter.ensureEnd()
83 | return DbusValue(kind: dtDictEntry, dictKey: key, dictValue: val)
84 | of dtArray:
85 | var subiter = iter.subIterate()
86 | var values: seq[DbusValue]
87 | var subkind: DbusType
88 | while true:
89 | let subkindInt = dbus_message_iter_get_arg_type(addr subiter.iter)
90 | subkind = subkindInt.DbusTypeChar
91 | if subkind.kind == dtNull:
92 | break
93 | values.add(subiter.unpackCurrent(native))
94 | if dbus_message_iter_has_next(addr subiter.iter) == 0:
95 | break
96 | subiter.advanceIter()
97 | if values.len > 0 and subkind.kind == dtDictEntry:
98 | # Hard to get these when there are no values in the current system
99 | subkind.keyType = values[0].dictKey.kind
100 | subkind.valueType = values[0].dictValue.kind
101 | return DbusValue(kind: dtArray, arrayValueType: subkind, arrayValue: values)
102 | of dtStruct:
103 | var subiter = iter.subIterate()
104 | var values:seq[DbusValue]
105 | while true:
106 | values.add(subiter.unpackCurrent(DbusValue))
107 | if dbus_message_iter_has_next(addr subiter.iter) == 0:
108 | break
109 | subiter.advanceIter()
110 | return DbusValue(kind: dtStruct, structValues: values)
111 | else:
112 | raise newException(DbusException, "nim-dbus does not support unpacking " & $kind)
113 |
114 | proc unpackCurrent*[T](iter: var InputIter, native: typedesc[T]): T =
115 | unpackCurrent(iter, DbusValue).asNative(native)
116 |
--------------------------------------------------------------------------------
/dbus/private/message.nim:
--------------------------------------------------------------------------------
1 |
2 | type Message* = object
3 | msg: ptr DBusMessage
4 |
5 | proc makeSignal*(path: string, iface: string, name: string): Message =
6 | result.msg = dbus_message_new_signal(path, iface, name)
7 |
8 | proc makeCall*(uniqueName: string, path: ObjectPath, iface: string, name: string): Message =
9 | result.msg = dbus_message_new_method_call(uniqueName, path.string, iface, name)
10 |
11 | proc sendMessage*(conn: Bus, msg: var Message): dbus_uint32_t {.discardable.} =
12 | var serial: dbus_uint32_t
13 | let ret = dbus_connection_send(conn.conn, msg.msg, addr serial)
14 | dbus_message_unref(msg.msg)
15 | msg.msg = nil
16 | if not bool(ret):
17 | raise newException(DbusException, "dbus_connection_send")
18 | return serial
19 |
20 | type PendingCall* = object
21 | call: ptr DBusPendingCall
22 | bus: Bus
23 |
24 | proc sendMessageWithReply*(bus: Bus, msg: Message): PendingCall =
25 | result.bus = bus
26 | let ret = dbus_connection_send_with_reply(bus.conn, msg.msg, addr result.call, -1)
27 | dbus_message_unref(msg.msg)
28 | if not bool(ret):
29 | raise newException(DbusException, "dbus_connection_send_with_reply")
30 | if result.call == nil:
31 | raise newException(DbusException, "pending call still nil")
32 |
33 | # Serialization
34 |
35 | proc append*(iter: ptr DbusMessageIter, x: DbusValue)
36 | proc append*[T](iter: ptr DbusMessageIter, x: T)
37 |
38 | proc initIter*(msg: Message): DbusMessageIter =
39 | dbus_message_iter_init_append(msg.msg, addr result)
40 |
41 | proc appendPtr(iter: ptr DbusMessageIter, typecode: DbusType, data: pointer) =
42 | if dbus_message_iter_append_basic(iter, typecode.kind.char.cint, data) == 0:
43 | raise newException(DbusException, "append_basic")
44 |
45 | proc appendArray(iter: ptr DbusMessageIter, sig: string, arr: openarray[DbusValue]) =
46 | var subIter: DBusMessageIter
47 | var subIterPtr = addr subIter
48 | if dbus_message_iter_open_container(iter, cint(dtArray), cstring(sig), subIterPtr) == 0:
49 | raise newException(DbusException, "open_container")
50 | for item in arr:
51 | subIterPtr.append(item)
52 | if dbus_message_iter_close_container(iter, subIterPtr) == 0:
53 | raise newException(DbusException, "close_container")
54 |
55 | proc appendDictEntry(iter: ptr DbusMessageIter, key, val: DbusValue) =
56 | var subIter: DbusMessageIter
57 | var subIterPtr = addr subIter
58 | if dbus_message_iter_open_container(iter, cint(dtDictEntry), nil, subIterPtr) == 0:
59 | raise newException(DbusException, "open_container")
60 | subIterPtr.append(key)
61 | subIterPtr.append(val)
62 | if dbus_message_iter_close_container(iter, subIterPtr) == 0:
63 | raise newException(DbusException, "close_container")
64 |
65 | proc appendVariant(iter: ptr DbusMessageIter, sig: string, val: DbusValue) =
66 | var subIter: DbusMessageIter
67 | var subIterPtr = addr subIter
68 | if dbus_message_iter_open_container(iter, cint(dtVariant), sig, subIterPtr) == 0:
69 | raise newException(DbusException, "open_container")
70 | subIterPtr.append(val)
71 | if dbus_message_iter_close_container(iter, subIterPtr) == 0:
72 | raise newException(DbusException, "close_container")
73 |
74 | proc appendStruct(iter: ptr DbusMessageIter, arr: openarray[DbusValue]) =
75 | var subIter: DbusMessageIter
76 | var subIterPtr = addr subIter
77 | if dbus_message_iter_open_container(iter, cint(dtStruct), nil, subIterPtr) == 0:
78 | raise newException(DbusException, "open_container")
79 | for item in arr:
80 | subIterPtr.append(item)
81 | if dbus_message_iter_close_container(iter, subIterPtr) == 0:
82 | raise newException(DbusException, "close_container")
83 |
84 | proc append*(iter: ptr DbusMessageIter, x: DbusValue) =
85 | case x.kind:
86 | of dtBool:
87 | let val = x.boolValue.uint32
88 | iter.appendPtr(x.kind, addr val)
89 | of dbusScalarTypes - {dtBool}:
90 | iter.appendPtr(x.kind, x.getPrimitive)
91 | of dbusStringTypes:
92 | # dbus_message_iter_append_basic copies its argument, so this is safe
93 | var str = x.getString.cstring
94 | iter.appendPtr(x.kind, addr str)
95 | of dtArray:
96 | iter.appendArray(x.arrayValueType.makeDbusSignature, x.arrayValue)
97 | of dtDictEntry:
98 | iter.appendDictEntry(x.dictKey, x.dictValue)
99 | of dtVariant:
100 | iter.appendVariant(x.variantType.makeDbusSignature, x.variantValue)
101 | of dtStruct:
102 | iter.appendStruct(x.structValues)
103 | else:
104 | raise newException(ValueError, "not serializable")
105 |
106 | # anything convertible to DbusValue
107 | proc append*[T](iter: ptr DbusMessageIter, x: T) =
108 | iter.append(x.asDbusValue)
109 |
110 | proc append*[T](msg: Message, x: T) =
111 | var iter = initIter(msg)
112 | append(addr iter, x)
113 |
--------------------------------------------------------------------------------
/include/dbus/dbus-server.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-server.h DBusServer object
3 | *
4 | * Copyright (C) 2002, 2003 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_SERVER_H
28 | #define DBUS_SERVER_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | DBUS_BEGIN_DECLS
36 |
37 | /**
38 | * @addtogroup DBusServer
39 | * @{
40 | */
41 |
42 | struct DBusServer;
43 | typedef struct DBusServer DBusServer;
44 |
45 | /** Called when a new connection to the server is available. Must reference and save the new
46 | * connection, or close the new connection. Set with dbus_server_set_new_connection_function().
47 | */
48 | typedef void (* DBusNewConnectionFunction) (DBusServer *server,
49 | DBusConnection *new_connection,
50 | void *data);
51 |
52 | DBUS_EXPORT
53 | DBusServer* dbus_server_listen (const char *address,
54 | DBusError *error);
55 | DBUS_EXPORT
56 | DBusServer* dbus_server_ref (DBusServer *server);
57 | DBUS_EXPORT
58 | void dbus_server_unref (DBusServer *server);
59 | DBUS_EXPORT
60 | void dbus_server_disconnect (DBusServer *server);
61 | DBUS_EXPORT
62 | dbus_bool_t dbus_server_get_is_connected (DBusServer *server);
63 | DBUS_EXPORT
64 | char* dbus_server_get_address (DBusServer *server);
65 | DBUS_EXPORT
66 | char* dbus_server_get_id (DBusServer *server);
67 | DBUS_EXPORT
68 | void dbus_server_set_new_connection_function (DBusServer *server,
69 | DBusNewConnectionFunction function,
70 | void *data,
71 | DBusFreeFunction free_data_function);
72 | DBUS_EXPORT
73 | dbus_bool_t dbus_server_set_watch_functions (DBusServer *server,
74 | DBusAddWatchFunction add_function,
75 | DBusRemoveWatchFunction remove_function,
76 | DBusWatchToggledFunction toggled_function,
77 | void *data,
78 | DBusFreeFunction free_data_function);
79 | DBUS_EXPORT
80 | dbus_bool_t dbus_server_set_timeout_functions (DBusServer *server,
81 | DBusAddTimeoutFunction add_function,
82 | DBusRemoveTimeoutFunction remove_function,
83 | DBusTimeoutToggledFunction toggled_function,
84 | void *data,
85 | DBusFreeFunction free_data_function);
86 | DBUS_EXPORT
87 | dbus_bool_t dbus_server_set_auth_mechanisms (DBusServer *server,
88 | const char **mechanisms);
89 |
90 | DBUS_EXPORT
91 | dbus_bool_t dbus_server_allocate_data_slot (dbus_int32_t *slot_p);
92 | DBUS_EXPORT
93 | void dbus_server_free_data_slot (dbus_int32_t *slot_p);
94 | DBUS_EXPORT
95 | dbus_bool_t dbus_server_set_data (DBusServer *server,
96 | int slot,
97 | void *data,
98 | DBusFreeFunction free_data_func);
99 | DBUS_EXPORT
100 | void* dbus_server_get_data (DBusServer *server,
101 | int slot);
102 |
103 | /** @} */
104 |
105 | DBUS_END_DECLS
106 |
107 | #endif /* DBUS_SERVER_H */
108 |
--------------------------------------------------------------------------------
/include/dbus/dbus-macros.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-macros.h generic macros
3 | *
4 | * Copyright (C) 2002 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_MACROS_H
28 | #define DBUS_MACROS_H
29 |
30 | #ifdef __cplusplus
31 | # define DBUS_BEGIN_DECLS extern "C" {
32 | # define DBUS_END_DECLS }
33 | #else
34 | # define DBUS_BEGIN_DECLS
35 | # define DBUS_END_DECLS
36 | #endif
37 |
38 | #ifndef TRUE
39 | # define TRUE 1
40 | #endif
41 | #ifndef FALSE
42 | # define FALSE 0
43 | #endif
44 |
45 | #ifndef NULL
46 | # ifdef __cplusplus
47 | # define NULL (0L)
48 | # else /* !__cplusplus */
49 | # define NULL ((void*) 0)
50 | # endif /* !__cplusplus */
51 | #endif
52 |
53 | #if 0
54 | # define DBUS_DEPRECATED __attribute__ ((__deprecated__))
55 | #elif defined(_MSC_VER) && (_MSC_VER >= 1300)
56 | # define DBUS_DEPRECATED __declspec(deprecated)
57 | #else
58 | # define DBUS_DEPRECATED
59 | #endif
60 |
61 | #if 0
62 | # define _DBUS_GNUC_EXTENSION __extension__
63 | #else
64 | # define _DBUS_GNUC_EXTENSION
65 | #endif
66 |
67 | #if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
68 | #define _DBUS_GNUC_PRINTF( format_idx, arg_idx ) \
69 | __attribute__((__format__ (__printf__, format_idx, arg_idx)))
70 | #define _DBUS_GNUC_NORETURN \
71 | __attribute__((__noreturn__))
72 | #define _DBUS_GNUC_UNUSED \
73 | __attribute__((__unused__))
74 | #else /* !__GNUC__ */
75 | #define _DBUS_GNUC_PRINTF( format_idx, arg_idx )
76 | #define _DBUS_GNUC_NORETURN
77 | #define _DBUS_GNUC_UNUSED
78 | #endif /* !__GNUC__ */
79 |
80 | #if 0
81 | #define DBUS_MALLOC __attribute__((__malloc__))
82 | #else
83 | #define DBUS_MALLOC
84 | #endif
85 |
86 | #if 0
87 | #define DBUS_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
88 | #define DBUS_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
89 | #else
90 | #define DBUS_ALLOC_SIZE(x)
91 | #define DBUS_ALLOC_SIZE2(x,y)
92 | #endif
93 |
94 | /** @def _DBUS_GNUC_PRINTF
95 | * used to tell gcc about printf format strings
96 | */
97 | /** @def _DBUS_GNUC_NORETURN
98 | * used to tell gcc about functions that never return, such as _dbus_abort()
99 | */
100 |
101 |
102 | /* Normally docs are in .c files, but there isn't a .c file for this. */
103 | /**
104 | * @defgroup DBusMacros Utility macros
105 | * @ingroup DBus
106 | * @brief #TRUE, #FALSE, #NULL, and so on
107 | *
108 | * Utility macros.
109 | *
110 | * @{
111 | */
112 |
113 | /**
114 | * @def DBUS_BEGIN_DECLS
115 | *
116 | * Macro used prior to declaring functions in the D-Bus header
117 | * files. Expands to "extern "C"" when using a C++ compiler,
118 | * and expands to nothing when using a C compiler.
119 | *
120 | * Please don't use this in your own code, consider it
121 | * D-Bus internal.
122 | */
123 | /**
124 | * @def DBUS_END_DECLS
125 | *
126 | * Macro used after declaring functions in the D-Bus header
127 | * files. Expands to "}" when using a C++ compiler,
128 | * and expands to nothing when using a C compiler.
129 | *
130 | * Please don't use this in your own code, consider it
131 | * D-Bus internal.
132 | */
133 | /**
134 | * @def TRUE
135 | *
136 | * Expands to "1"
137 | */
138 | /**
139 | * @def FALSE
140 | *
141 | * Expands to "0"
142 | */
143 | /**
144 | * @def NULL
145 | *
146 | * A null pointer, defined appropriately for C or C++.
147 | */
148 | /**
149 | * @def DBUS_DEPRECATED
150 | *
151 | * Tells the compiler to warn about a function or type if it's used.
152 | * Code marked in this way should also be enclosed in
153 | * @code
154 | * #ifndef DBUS_DISABLE_DEPRECATED
155 | * deprecated stuff here
156 | * #endif
157 | * @endcode
158 | *
159 | * Please don't use this in your own code, consider it
160 | * D-Bus internal.
161 | */
162 | /**
163 | * @def _DBUS_GNUC_EXTENSION
164 | *
165 | * Tells gcc not to warn about extensions to the C standard in the
166 | * following expression, even if compiling with -pedantic. Do not use
167 | * this macro in your own code; please consider it to be internal to libdbus.
168 | */
169 |
170 | /*
171 | * @def DBUS_EXPORT
172 | *
173 | * Declare the following symbol as public. This is currently a noop on
174 | * platforms other than Windows.
175 | */
176 |
177 | #if defined(_WIN32)
178 | # if defined(DBUS_STATIC_BUILD)
179 | # define DBUS_EXPORT
180 | # elif defined(dbus_1_EXPORTS)
181 | # define DBUS_EXPORT __declspec(dllexport)
182 | # else
183 | # define DBUS_EXPORT __declspec(dllimport)
184 | # endif
185 | #else
186 | #define DBUS_EXPORT
187 | #endif
188 |
189 | /** @} */
190 |
191 | #endif /* DBUS_MACROS_H */
192 |
--------------------------------------------------------------------------------
/include/dbus/dbus-shared.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-shared.h Stuff used by both dbus/dbus.h low-level and C/C++ binding APIs
3 | *
4 | * Copyright (C) 2004 Red Hat, Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 |
24 | #ifndef DBUS_SHARED_H
25 | #define DBUS_SHARED_H
26 |
27 | /* Don't include anything in here from anywhere else. It's
28 | * intended for use by any random library.
29 | */
30 |
31 | #ifdef __cplusplus
32 | extern "C" {
33 | #if 0
34 | } /* avoids confusing emacs indentation */
35 | #endif
36 | #endif
37 |
38 | /* Normally docs are in .c files, but there isn't a .c file for this. */
39 | /**
40 | * @defgroup DBusShared Shared constants
41 | * @ingroup DBus
42 | *
43 | * @brief Shared header included by both libdbus and C/C++ bindings such as the GLib bindings.
44 | *
45 | * Usually a C/C++ binding such as the GLib or Qt binding won't want to include dbus.h in its
46 | * public headers. However, a few constants and macros may be useful to include; those are
47 | * found here and in dbus-protocol.h
48 | *
49 | * @{
50 | */
51 |
52 |
53 | /**
54 | * Well-known bus types. See dbus_bus_get().
55 | */
56 | typedef enum
57 | {
58 | DBUS_BUS_SESSION, /**< The login session bus */
59 | DBUS_BUS_SYSTEM, /**< The systemwide bus */
60 | DBUS_BUS_STARTER /**< The bus that started us, if any */
61 | } DBusBusType;
62 |
63 | /**
64 | * Results that a message handler can return.
65 | */
66 | typedef enum
67 | {
68 | DBUS_HANDLER_RESULT_HANDLED, /**< Message has had its effect - no need to run more handlers. */
69 | DBUS_HANDLER_RESULT_NOT_YET_HANDLED, /**< Message has not had any effect - see if other handlers want it. */
70 | DBUS_HANDLER_RESULT_NEED_MEMORY /**< Need more memory in order to return #DBUS_HANDLER_RESULT_HANDLED or #DBUS_HANDLER_RESULT_NOT_YET_HANDLED. Please try again later with more memory. */
71 | } DBusHandlerResult;
72 |
73 | /* Bus names */
74 |
75 | /** The bus name used to talk to the bus itself. */
76 | #define DBUS_SERVICE_DBUS "org.freedesktop.DBus"
77 |
78 | /* Paths */
79 | /** The object path used to talk to the bus itself. */
80 | #define DBUS_PATH_DBUS "/org/freedesktop/DBus"
81 | /** The object path used in local/in-process-generated messages. */
82 | #define DBUS_PATH_LOCAL "/org/freedesktop/DBus/Local"
83 |
84 | /* Interfaces, these #define don't do much other than
85 | * catch typos at compile time
86 | */
87 | /** The interface exported by the object with #DBUS_SERVICE_DBUS and #DBUS_PATH_DBUS */
88 | #define DBUS_INTERFACE_DBUS "org.freedesktop.DBus"
89 | /** The interface supported by introspectable objects */
90 | #define DBUS_INTERFACE_INTROSPECTABLE "org.freedesktop.DBus.Introspectable"
91 | /** The interface supported by objects with properties */
92 | #define DBUS_INTERFACE_PROPERTIES "org.freedesktop.DBus.Properties"
93 | /** The interface supported by most dbus peers */
94 | #define DBUS_INTERFACE_PEER "org.freedesktop.DBus.Peer"
95 |
96 | /** This is a special interface whose methods can only be invoked
97 | * by the local implementation (messages from remote apps aren't
98 | * allowed to specify this interface).
99 | */
100 | #define DBUS_INTERFACE_LOCAL "org.freedesktop.DBus.Local"
101 |
102 | /* Owner flags */
103 | #define DBUS_NAME_FLAG_ALLOW_REPLACEMENT 0x1 /**< Allow another service to become the primary owner if requested */
104 | #define DBUS_NAME_FLAG_REPLACE_EXISTING 0x2 /**< Request to replace the current primary owner */
105 | #define DBUS_NAME_FLAG_DO_NOT_QUEUE 0x4 /**< If we can not become the primary owner do not place us in the queue */
106 |
107 | /* Replies to request for a name */
108 | #define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1 /**< Service has become the primary owner of the requested name */
109 | #define DBUS_REQUEST_NAME_REPLY_IN_QUEUE 2 /**< Service could not become the primary owner and has been placed in the queue */
110 | #define DBUS_REQUEST_NAME_REPLY_EXISTS 3 /**< Service is already in the queue */
111 | #define DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER 4 /**< Service is already the primary owner */
112 |
113 | /* Replies to releasing a name */
114 | #define DBUS_RELEASE_NAME_REPLY_RELEASED 1 /**< Service was released from the given name */
115 | #define DBUS_RELEASE_NAME_REPLY_NON_EXISTENT 2 /**< The given name does not exist on the bus */
116 | #define DBUS_RELEASE_NAME_REPLY_NOT_OWNER 3 /**< Service is not an owner of the given name */
117 |
118 | /* Replies to service starts */
119 | #define DBUS_START_REPLY_SUCCESS 1 /**< Service was auto started */
120 | #define DBUS_START_REPLY_ALREADY_RUNNING 2 /**< Service was already running */
121 |
122 | /** @} */
123 |
124 | #ifdef __cplusplus
125 | #if 0
126 | { /* avoids confusing emacs indentation */
127 | #endif
128 | }
129 | #endif
130 |
131 | #endif /* DBUS_SHARED_H */
132 |
--------------------------------------------------------------------------------
/include/dbus/dbus-types.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-types.h types such as dbus_bool_t
3 | *
4 | * Copyright (C) 2002 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_TYPES_H
28 | #define DBUS_TYPES_H
29 |
30 | //#include
31 | #include
32 |
33 | typedef dbus_uint32_t dbus_unichar_t;
34 | /* boolean size must be fixed at 4 bytes due to wire protocol! */
35 | typedef dbus_uint32_t dbus_bool_t;
36 |
37 | /* Normally docs are in .c files, but there isn't a .c file for this. */
38 | /**
39 | * @defgroup DBusTypes Basic types
40 | * @ingroup DBus
41 | * @brief dbus_bool_t, dbus_int32_t, etc.
42 | *
43 | * Typedefs for common primitive types.
44 | *
45 | * @{
46 | */
47 |
48 | /**
49 | * @typedef dbus_bool_t
50 | *
51 | * A boolean, valid values are #TRUE and #FALSE.
52 | */
53 |
54 | /**
55 | * @typedef dbus_uint32_t
56 | *
57 | * A 32-bit unsigned integer on all platforms.
58 | */
59 |
60 | /**
61 | * @typedef dbus_int32_t
62 | *
63 | * A 32-bit signed integer on all platforms.
64 | */
65 |
66 | /**
67 | * @typedef dbus_uint16_t
68 | *
69 | * A 16-bit unsigned integer on all platforms.
70 | */
71 |
72 | /**
73 | * @typedef dbus_int16_t
74 | *
75 | * A 16-bit signed integer on all platforms.
76 | */
77 |
78 |
79 | /**
80 | * @typedef dbus_uint64_t
81 | *
82 | * A 64-bit unsigned integer on all platforms that support it.
83 | * If supported, #DBUS_HAVE_INT64 will be defined.
84 | *
85 | * C99 requires a 64-bit type and most likely all interesting
86 | * compilers support one. GLib for example flat-out requires
87 | * a 64-bit type.
88 | *
89 | * You probably want to just assume #DBUS_HAVE_INT64 is always defined.
90 | */
91 |
92 | /**
93 | * @typedef dbus_int64_t
94 | *
95 | * A 64-bit signed integer on all platforms that support it.
96 | * If supported, #DBUS_HAVE_INT64 will be defined.
97 | *
98 | * C99 requires a 64-bit type and most likely all interesting
99 | * compilers support one. GLib for example flat-out requires
100 | * a 64-bit type.
101 | *
102 | * You probably want to just assume #DBUS_HAVE_INT64 is always defined.
103 | */
104 |
105 | /**
106 | * @def DBUS_HAVE_INT64
107 | *
108 | * Defined if 64-bit integers are available. Will be defined
109 | * on any platform you care about, unless you care about
110 | * some truly ancient UNIX, or some bizarre embedded platform.
111 | *
112 | * C99 requires a 64-bit type and most likely all interesting
113 | * compilers support one. GLib for example flat-out requires
114 | * a 64-bit type.
115 | *
116 | * You should feel comfortable ignoring this macro and just using
117 | * int64 unconditionally.
118 | *
119 | */
120 |
121 | /**
122 | * @def DBUS_INT64_CONSTANT
123 | *
124 | * Declare a 64-bit signed integer constant. The macro
125 | * adds the necessary "LL" or whatever after the integer,
126 | * giving a literal such as "325145246765LL"
127 | */
128 |
129 | /**
130 | * @def DBUS_UINT64_CONSTANT
131 | *
132 | * Declare a 64-bit unsigned integer constant. The macro
133 | * adds the necessary "ULL" or whatever after the integer,
134 | * giving a literal such as "325145246765ULL"
135 | */
136 |
137 | /**
138 | * An 8-byte struct you could use to access int64 without having
139 | * int64 support
140 | */
141 | typedef struct
142 | {
143 | dbus_uint32_t first32; /**< first 32 bits in the 8 bytes (beware endian issues) */
144 | dbus_uint32_t second32; /**< second 32 bits in the 8 bytes (beware endian issues) */
145 | } DBus8ByteStruct;
146 |
147 | /**
148 | * A simple value union that lets you access bytes as if they
149 | * were various types; useful when dealing with basic types via
150 | * void pointers and varargs.
151 | *
152 | * This union also contains a pointer member (which can be used
153 | * to retrieve a string from dbus_message_iter_get_basic(), for
154 | * instance), so on future platforms it could conceivably be larger
155 | * than 8 bytes.
156 | */
157 | typedef union
158 | {
159 | unsigned char bytes[8]; /**< as 8 individual bytes */
160 | dbus_int16_t i16; /**< as int16 */
161 | dbus_uint16_t u16; /**< as int16 */
162 | dbus_int32_t i32; /**< as int32 */
163 | dbus_uint32_t u32; /**< as int32 */
164 | dbus_bool_t bool_val; /**< as boolean */
165 | #ifdef DBUS_HAVE_INT64
166 | dbus_int64_t i64; /**< as int64 */
167 | dbus_uint64_t u64; /**< as int64 */
168 | #endif
169 | DBus8ByteStruct eight; /**< as 8-byte struct */
170 | double dbl; /**< as double */
171 | unsigned char byt; /**< as byte */
172 | char *str; /**< as char* (string, object path or signature) */
173 | int fd; /**< as Unix file descriptor */
174 | } DBusBasicValue;
175 |
176 | /** @} */
177 |
178 | #endif /* DBUS_TYPES_H */
179 |
--------------------------------------------------------------------------------
/dbus/private/types.nim:
--------------------------------------------------------------------------------
1 | import strutils, tables
2 |
3 | type ObjectPath* = distinct string
4 | type Signature* = distinct string
5 |
6 | type Variant[T] = object
7 | value: T
8 |
9 | proc newVariant*[T](val: T): Variant[T] = Variant[T](value: val)
10 |
11 | type DbusTypeChar* = enum
12 | dtNull = '\0', # workaround for Nim bug #3096
13 | dtArray = 'a',
14 | dtBool = 'b',
15 | dtDouble = 'd',
16 | dtDictEntry = 'e',
17 | dtSignature = 'g',
18 | dtUnixFd = 'h'
19 | dtInt32 = 'i',
20 | dtInt16 = 'n',
21 | dtObjectPath = 'o',
22 | dtUint16 = 'q',
23 | dtStruct = 'r',
24 | dtString = 's',
25 | dtUint64 = 't',
26 | dtUint32 = 'u',
27 | dtVariant = 'v'
28 | dtInt64 = 'x',
29 | dtByte = 'y'
30 | dtDict = '{'
31 |
32 | const dbusScalarTypes* = {dtBool, dtDouble, dtInt32, dtInt16, dtUint16, dtUint64, dtUint32, dtInt64, dtByte}
33 | const dbusStringTypes* = {dtString, dtObjectPath, dtSignature}
34 | const dbusContainerTypes* = {dtArray, dtStruct, dtDict, dtDictEntry, dtVariant}
35 |
36 | type DbusType* = ref object
37 | case kind*: DbusTypeChar
38 | of dtArray:
39 | itemType*: DbusType
40 | of dtDictEntry:
41 | keyType*: DbusType
42 | valueType*: DbusType
43 | of dtStruct:
44 | itemTypes*: seq[DbusType]
45 | of dtVariant:
46 | variantType*: DbusType
47 | else:
48 | discard
49 |
50 | proc `$`*(t: DbusType): string =
51 | result.add("")
64 |
65 | converter fromScalar*(ch: DbusTypeChar): DbusType =
66 | # assert ch notin dbusContainerTypes
67 | DbusType(kind: ch)
68 |
69 | proc initArrayType*(itemType: DbusType): DbusType =
70 | DbusType(kind: dtArray, itemType: itemType)
71 |
72 | proc initDictEntryType*(keyType: DbusType, valueType: DbusType): DbusType =
73 | doAssert keyType.kind notin dbusContainerTypes
74 | DbusType(kind: dtDictEntry, keyType: keyType, valueType: valueType)
75 |
76 | proc initStructType*(itemTypes: seq[DbusType]): DbusType =
77 | DbusType(kind: dtStruct, itemTypes: itemTypes)
78 |
79 | proc initVariantType*(variantType: DbusType): DbusType =
80 | DbusType(kind: dtVariant, variantType: variantType)
81 |
82 | proc parseDbusFragment(signature: string): tuple[kind: DbusType, rest: string] =
83 | case signature[0]:
84 | of 'a':
85 | let ret = parseDbusFragment(signature[1..^1])
86 | return (initArrayType(ret.kind), ret.rest)
87 | of '{':
88 | let keyRet = parseDbusFragment(signature[1..^1])
89 | let valueRet = parseDbusFragment(keyRet.rest)
90 | assert valueRet.rest[0] == "}"[0]
91 | return (initDictEntryType(keyRet.kind, valueRet.kind), valueRet.rest[1..^1])
92 | of '(':
93 | var left = signature[1..^1]
94 | var types: seq[DbusType] = @[]
95 | while left[0] != ')':
96 | let ret = parseDbusFragment(left)
97 | left = ret.rest
98 | types.add ret.kind
99 | return (initStructType(types), left[1..^1])
100 | else:
101 | let kind = signature[0].DbusTypeChar
102 | return (fromScalar(kind), signature[1..^1])
103 |
104 | proc parseDbusType*(signature: string): DbusType =
105 | let ret = parseDbusFragment(signature)
106 | if ret.rest != "":
107 | raise newException(Exception, "leftover data in signature: $1" % signature)
108 | return ret.kind
109 |
110 | proc makeDbusSignature*(kind: DbusType): string =
111 | case kind.kind:
112 | of dtArray:
113 | result = "a" & makeDbusSignature(kind.itemType)
114 | of dtDictEntry:
115 | result = "{" & makeDbusSignature(kind.keyType) & makeDbusSignature(kind.valueType) & "}"
116 | of dtStruct:
117 | result = "("
118 | for t in kind.itemTypes:
119 | result.add makeDbusSignature(t)
120 | result.add ")"
121 | else:
122 | result = $(kind.kind.char)
123 |
124 | proc getDbusType(native: typedesc[uint32]): DbusType =
125 | dtUint32
126 |
127 | proc getDbusType(native: typedesc[uint16]): DbusType =
128 | dtUint16
129 |
130 | proc getDbusType(native: typedesc[uint8]): DbusType =
131 | dtByte
132 |
133 | proc getDbusType(native: typedesc[int32]): DbusType =
134 | dtInt32
135 |
136 | proc getDbusType(native: typedesc[int16]): DbusType =
137 | dtInt16
138 |
139 | proc getDbusType(native: typedesc[cstring]): DbusType =
140 | dtString
141 |
142 | proc getDbusType(native: typedesc[ObjectPath]): DbusType =
143 | dtObjectPath
144 |
145 | proc getAnyDbusType*[T](native: typedesc[T]): DbusType
146 | proc getAnyDbusType*(native: typedesc[string]): DbusType
147 | proc getAnyDbusType*(native: typedesc[ObjectPath]): DbusType
148 | proc getAnyDbusType*[T](native: typedesc[seq[T]]): DbusType
149 | proc getAnyDbusType*[K, V](native: typedesc[Table[K, V]]): DbusType
150 | proc getAnyDbusType*[K, V](native: typedesc[TableRef[K, V]]): DbusType
151 |
152 | proc getDbusType[T](native: typedesc[Variant[T]]): DbusType =
153 | initVariantType(getAnyDbusType(T))
154 |
155 | proc getAnyDbusType*[T](native: typedesc[T]): DbusType =
156 | getDbusType(native)
157 |
158 | proc getAnyDbusType*(native: typedesc[string]): DbusType =
159 | getDbusType(cstring)
160 |
161 | proc getAnyDbusType*(native: typedesc[ObjectPath]): DbusType =
162 | getDbusType(ObjectPath)
163 |
164 | proc getAnyDbusType*[T](native: typedesc[seq[T]]): DbusType =
165 | initArrayType(getDbusType(T))
166 |
167 | proc getAnyDbusType*[K, V](native: typedesc[Table[K, V]]): DbusType =
168 | initArrayType(initDictEntryType(getAnyDbusType(K), getAnyDbusType(V)))
169 |
170 | proc getAnyDbusType*[K, V](native: typedesc[TableRef[K, V]]): DbusType =
171 | initArrayType(initDictEntryType(getAnyDbusType(K), getAnyDbusType(V)))
172 |
--------------------------------------------------------------------------------
/tests/tbasic.nim:
--------------------------------------------------------------------------------
1 | import unittest
2 |
3 | import tables
4 | import dbus
5 |
6 | const
7 | TEST_BUSNAME = "com.zielmicha.test"
8 | TEST_OBJECTPATH = ObjectPath("/com/zielmicha/test")
9 | TEST_INTERFACE = "com.zielmicha.test"
10 | TEST_METHOD = "hello"
11 |
12 | proc testEcho[T](val: T): DbusValue =
13 | ## Test helper proc that sends a value to the test echo Dbus
14 | ## service and returns the echoed value. Useful for testing
15 | ## that values can be sent and retrieved through the bus
16 | let bus = getBus(dbus.DBUS_BUS_SESSION)
17 | var msg = makeCall(TEST_BUSNAME,
18 | TEST_OBJECTPATH,
19 | TEST_INTERFACE,
20 | TEST_METHOD)
21 |
22 | msg.append(val)
23 |
24 | let pending = bus.sendMessageWithReply(msg)
25 | let reply = pending.waitForReply()
26 | reply.raiseIfError()
27 |
28 | var it = reply.iterate
29 | # let v = it.unpackCurrent(DbusValue)
30 | # assert v.asNative(string) == "Hello, world!"
31 | it.advanceIter
32 | return it.unpackCurrent(DbusValue)
33 |
34 |
35 | test "basic":
36 | let bus = getBus(dbus.DBUS_BUS_SESSION)
37 | var msg = makeCall(TEST_BUSNAME,
38 | TEST_OBJECTPATH,
39 | TEST_INTERFACE,
40 | TEST_METHOD)
41 |
42 | msg.append(uint32(6))
43 | msg.append("hello")
44 | msg.append(1'i32)
45 | msg.append("hello".asDbusValue)
46 | msg.append(@["a", "b"])
47 | msg.append({"a": "b"}.toTable)
48 | msg.append(ObjectPath("/a"))
49 | msg.append(@[ObjectPath("/b")])
50 |
51 | let pending = bus.sendMessageWithReply(msg)
52 | let reply = pending.waitForReply()
53 | reply.raiseIfError()
54 |
55 | var it = reply.iterate
56 | let v = it.unpackCurrent(DbusValue)
57 | assert v.asNative(string) == "Hello, world!"
58 | it.advanceIter
59 | assert it.unpackCurrent(uint32) == 6
60 |
61 | test "int":
62 | let val = testEcho(uint32(6))
63 | assert val.kind == dtUint32
64 | assert val.asNative(uint32) == 6
65 |
66 | test "arrays":
67 | let val = testEcho(@["a", "b"])
68 | assert val.kind == dtArray
69 | assert val.arrayValue[0].asNative(string) == "a"
70 | assert val.arrayValue[1].asNative(string) == "b"
71 |
72 | test "variant":
73 | let val = testEcho(newVariant("hi"))
74 | assert val.variantType.kind == dtString
75 | assert val.variantValue.asNative(string) == "hi"
76 |
77 | test "struct":
78 | let val = testEcho(DbusValue(kind: dtStruct, structValues: @[
79 | "hi".asDbusValue(),
80 | uint32(2).asDbusValue(),
81 | ]))
82 | assert val.kind == dtStruct
83 | assert val.structValues.len == 2
84 | assert val.structValues[0].asNative(string) == "hi"
85 | assert val.structValues[1].asNative(uint32) == 2
86 |
87 | test "tables":
88 | let val = testEcho({"a":"b"}.toTable())
89 | assert val.kind == dtArray
90 | assert val.arrayValueType.kind == dtDictEntry
91 | assert val.arrayValue[0].dictKey.asNative(string) == "a"
92 | assert val.arrayValue[0].dictValue.asNative(string) == "b"
93 |
94 | test "tables nested":
95 | let val = testEcho({
96 | "a": newVariant({
97 | "c":"d"
98 | }.toTable())
99 | }.toTable())
100 | assert val.kind == dtArray
101 | assert val.arrayValue[0].dictKey.asNative(string) == "a"
102 | assert val.arrayValue[0].dictValue.variantValue.arrayValue[0].dictKey.asNative(string) == "c"
103 | assert val.arrayValue[0].dictValue.variantValue.arrayValue[0].dictValue.asNative(string) == "d"
104 |
105 | test "tables mixed variant":
106 | let var1 = newVariant("foo").asDbusValue()
107 | let var2 = newVariant(12.uint32).asDbusValue()
108 | var dict = DbusValue(
109 | kind: dtArray,
110 | arrayValueType: DbusType(
111 | kind: dtDictEntry,
112 | keyType: dtString,
113 | valueType: dtVariant,
114 | )
115 | )
116 | dict.add("a".asDbusValue(), var1)
117 | dict.add("b".asDbusValue(), var2)
118 | let val = testEcho(dict)
119 | assert val.kind == dtArray
120 | assert val.arrayValue[0].dictKey.asNative(string) == "a"
121 | assert val.arrayValue[0].dictValue.variantValue.asNative(string) == "foo"
122 | assert val.arrayValue[1].dictKey.asNative(string) == "b"
123 | assert val.arrayValue[1].dictValue.variantValue.asNative(uint32) == 12
124 |
125 | test "tables mixed variant":
126 | # TODO: make a nicer syntax for this
127 | var outer = DbusValue(
128 | kind: dtArray,
129 | arrayValueType: DbusType(
130 | kind: dtDictEntry,
131 | keyType: dtString,
132 | valueType: dtVariant,
133 | )
134 | )
135 | var inner = DbusValue(
136 | kind: dtArray,
137 | arrayValueType: DbusType(
138 | kind: dtDictEntry,
139 | keyType: dtString,
140 | valueType: dtString,
141 | )
142 | )
143 | outer.add("a".asDbusValue(), newVariant("foo").asDbusValue())
144 | inner.add("c".asDbusValue(), "d".asDbusValue())
145 | outer.add("b".asDbusValue(), newVariant(inner).asDbusValue())
146 | let val = testEcho(outer)
147 | assert val.kind == dtArray
148 | assert val.arrayValue[0].dictKey.asNative(string) == "a"
149 | assert val.arrayValue[0].dictValue.variantValue.asNative(string) == "foo"
150 | assert val.arrayValue[1].dictKey.asNative(string) == "b"
151 | assert val.arrayValue[1].dictValue.variantValue.arrayValue[0].dictKey.asNative(string) == "c"
152 | assert val.arrayValue[1].dictValue.variantValue.arrayValue[0].dictValue.asNative(string) == "d"
153 |
154 | test "notify":
155 | let bus = getBus(DBUS_BUS_SESSION)
156 | var msg = makeCall("org.freedesktop.Notifications",
157 | ObjectPath("/org/freedesktop/Notifications"),
158 | "org.freedesktop.Notifications",
159 | "Notify")
160 |
161 | msg.append("nim-dbus")
162 | msg.append(0'u32)
163 | msg.append("dialog-information")
164 | msg.append("Test notification")
165 | msg.append("Test notification body")
166 | msg.append(newSeq[string]())
167 | msg.append({"urgency": newVariant(1'u8)}.toTable)
168 | msg.append(-1'i32)
169 |
170 | let pending = bus.sendMessage(msg)
171 |
172 |
--------------------------------------------------------------------------------
/include/dbus/dbus-threads.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-threads.h D-Bus threads handling
3 | *
4 | * Copyright (C) 2002 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_THREADS_H
28 | #define DBUS_THREADS_H
29 |
30 | #include
31 | #include
32 |
33 | DBUS_BEGIN_DECLS
34 |
35 | /**
36 | * @addtogroup DBusThreads
37 | * @{
38 | */
39 |
40 | /** An opaque mutex type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */
41 | struct DBusMutex;
42 | typedef struct DBusMutex DBusMutex;
43 | /** An opaque condition variable type provided by the #DBusThreadFunctions implementation installed by dbus_threads_init(). */
44 | struct DBusCondVar;
45 | typedef struct DBusCondVar DBusCondVar;
46 |
47 | /** Deprecated, provide DBusRecursiveMutexNewFunction instead. */
48 | typedef DBusMutex* (* DBusMutexNewFunction) (void);
49 | /** Deprecated, provide DBusRecursiveMutexFreeFunction instead. */
50 | typedef void (* DBusMutexFreeFunction) (DBusMutex *mutex);
51 | /** Deprecated, provide DBusRecursiveMutexLockFunction instead. Return value is lock success, but gets ignored in practice. */
52 | typedef dbus_bool_t (* DBusMutexLockFunction) (DBusMutex *mutex);
53 | /** Deprecated, provide DBusRecursiveMutexUnlockFunction instead. Return value is unlock success, but gets ignored in practice. */
54 | typedef dbus_bool_t (* DBusMutexUnlockFunction) (DBusMutex *mutex);
55 |
56 | /** Creates a new recursively-lockable mutex, or returns #NULL if not
57 | * enough memory. Can only fail due to lack of memory. Found in
58 | * #DBusThreadFunctions. Do not just use PTHREAD_MUTEX_RECURSIVE for
59 | * this, because it does not save/restore the recursion count when
60 | * waiting on a condition. libdbus requires the Java-style behavior
61 | * where the mutex is fully unlocked to wait on a condition.
62 | */
63 | typedef DBusMutex* (* DBusRecursiveMutexNewFunction) (void);
64 | /** Frees a recursively-lockable mutex. Found in #DBusThreadFunctions.
65 | */
66 | typedef void (* DBusRecursiveMutexFreeFunction) (DBusMutex *mutex);
67 | /** Locks a recursively-lockable mutex. Found in #DBusThreadFunctions.
68 | * Can only fail due to lack of memory.
69 | */
70 | typedef void (* DBusRecursiveMutexLockFunction) (DBusMutex *mutex);
71 | /** Unlocks a recursively-lockable mutex. Found in #DBusThreadFunctions.
72 | * Can only fail due to lack of memory.
73 | */
74 | typedef void (* DBusRecursiveMutexUnlockFunction) (DBusMutex *mutex);
75 |
76 | /** Creates a new condition variable. Found in #DBusThreadFunctions.
77 | * Can only fail (returning #NULL) due to lack of memory.
78 | */
79 | typedef DBusCondVar* (* DBusCondVarNewFunction) (void);
80 | /** Frees a condition variable. Found in #DBusThreadFunctions.
81 | */
82 | typedef void (* DBusCondVarFreeFunction) (DBusCondVar *cond);
83 |
84 | /** Waits on a condition variable. Found in
85 | * #DBusThreadFunctions. Must work with either a recursive or
86 | * nonrecursive mutex, whichever the thread implementation
87 | * provides. Note that PTHREAD_MUTEX_RECURSIVE does not work with
88 | * condition variables (does not save/restore the recursion count) so
89 | * don't try using simply pthread_cond_wait() and a
90 | * PTHREAD_MUTEX_RECURSIVE to implement this, it won't work right.
91 | *
92 | * Has no error conditions. Must succeed if it returns.
93 | */
94 | typedef void (* DBusCondVarWaitFunction) (DBusCondVar *cond,
95 | DBusMutex *mutex);
96 |
97 | /** Waits on a condition variable with a timeout. Found in
98 | * #DBusThreadFunctions. Returns #TRUE if the wait did not
99 | * time out, and #FALSE if it did.
100 | *
101 | * Has no error conditions. Must succeed if it returns.
102 | */
103 | typedef dbus_bool_t (* DBusCondVarWaitTimeoutFunction) (DBusCondVar *cond,
104 | DBusMutex *mutex,
105 | int timeout_milliseconds);
106 | /** Wakes one waiting thread on a condition variable. Found in #DBusThreadFunctions.
107 | *
108 | * Has no error conditions. Must succeed if it returns.
109 | */
110 | typedef void (* DBusCondVarWakeOneFunction) (DBusCondVar *cond);
111 |
112 | /** Wakes all waiting threads on a condition variable. Found in #DBusThreadFunctions.
113 | *
114 | * Has no error conditions. Must succeed if it returns.
115 | */
116 | typedef void (* DBusCondVarWakeAllFunction) (DBusCondVar *cond);
117 |
118 | /**
119 | * Flags indicating which functions are present in #DBusThreadFunctions. Used to allow
120 | * the library to detect older callers of dbus_threads_init() if new possible functions
121 | * are added to #DBusThreadFunctions.
122 | */
123 | typedef enum
124 | {
125 | DBUS_THREAD_FUNCTIONS_MUTEX_NEW_MASK = 1 << 0,
126 | DBUS_THREAD_FUNCTIONS_MUTEX_FREE_MASK = 1 << 1,
127 | DBUS_THREAD_FUNCTIONS_MUTEX_LOCK_MASK = 1 << 2,
128 | DBUS_THREAD_FUNCTIONS_MUTEX_UNLOCK_MASK = 1 << 3,
129 | DBUS_THREAD_FUNCTIONS_CONDVAR_NEW_MASK = 1 << 4,
130 | DBUS_THREAD_FUNCTIONS_CONDVAR_FREE_MASK = 1 << 5,
131 | DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_MASK = 1 << 6,
132 | DBUS_THREAD_FUNCTIONS_CONDVAR_WAIT_TIMEOUT_MASK = 1 << 7,
133 | DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ONE_MASK = 1 << 8,
134 | DBUS_THREAD_FUNCTIONS_CONDVAR_WAKE_ALL_MASK = 1 << 9,
135 | DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_NEW_MASK = 1 << 10,
136 | DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_FREE_MASK = 1 << 11,
137 | DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_LOCK_MASK = 1 << 12,
138 | DBUS_THREAD_FUNCTIONS_RECURSIVE_MUTEX_UNLOCK_MASK = 1 << 13,
139 | DBUS_THREAD_FUNCTIONS_ALL_MASK = (1 << 14) - 1
140 | } DBusThreadFunctionsMask;
141 |
142 | /**
143 | * Functions that must be implemented to make the D-Bus library
144 | * thread-aware.
145 | *
146 | * If you supply both recursive and non-recursive mutexes,
147 | * libdbus will use the non-recursive version for condition variables,
148 | * and the recursive version in other contexts.
149 | *
150 | * The condition variable functions have to work with nonrecursive
151 | * mutexes if you provide those, or with recursive mutexes if you
152 | * don't.
153 | */
154 | typedef struct
155 | {
156 | unsigned int mask; /**< Mask indicating which functions are present. */
157 |
158 | DBusMutexNewFunction mutex_new; /**< Function to create a mutex; optional and deprecated. */
159 | DBusMutexFreeFunction mutex_free; /**< Function to free a mutex; optional and deprecated. */
160 | DBusMutexLockFunction mutex_lock; /**< Function to lock a mutex; optional and deprecated. */
161 | DBusMutexUnlockFunction mutex_unlock; /**< Function to unlock a mutex; optional and deprecated. */
162 |
163 | DBusCondVarNewFunction condvar_new; /**< Function to create a condition variable */
164 | DBusCondVarFreeFunction condvar_free; /**< Function to free a condition variable */
165 | DBusCondVarWaitFunction condvar_wait; /**< Function to wait on a condition */
166 | DBusCondVarWaitTimeoutFunction condvar_wait_timeout; /**< Function to wait on a condition with a timeout */
167 | DBusCondVarWakeOneFunction condvar_wake_one; /**< Function to wake one thread waiting on the condition */
168 | DBusCondVarWakeAllFunction condvar_wake_all; /**< Function to wake all threads waiting on the condition */
169 |
170 | DBusRecursiveMutexNewFunction recursive_mutex_new; /**< Function to create a recursive mutex */
171 | DBusRecursiveMutexFreeFunction recursive_mutex_free; /**< Function to free a recursive mutex */
172 | DBusRecursiveMutexLockFunction recursive_mutex_lock; /**< Function to lock a recursive mutex */
173 | DBusRecursiveMutexUnlockFunction recursive_mutex_unlock; /**< Function to unlock a recursive mutex */
174 |
175 | void (* padding1) (void); /**< Reserved for future expansion */
176 | void (* padding2) (void); /**< Reserved for future expansion */
177 | void (* padding3) (void); /**< Reserved for future expansion */
178 | void (* padding4) (void); /**< Reserved for future expansion */
179 |
180 | } DBusThreadFunctions;
181 |
182 | DBUS_EXPORT
183 | dbus_bool_t dbus_threads_init (const DBusThreadFunctions *functions);
184 | DBUS_EXPORT
185 | dbus_bool_t dbus_threads_init_default (void);
186 |
187 | /** @} */
188 |
189 | DBUS_END_DECLS
190 |
191 | #endif /* DBUS_THREADS_H */
192 |
--------------------------------------------------------------------------------
/dbus/private/value.nim:
--------------------------------------------------------------------------------
1 | import tables
2 | import sequtils
3 |
4 | type
5 | FD* = cint
6 |
7 | DbusValue* = ref object
8 | case kind*: DbusTypeChar
9 | of dtArray:
10 | arrayValueType*: DbusType
11 | arrayValue*: seq[DbusValue]
12 | of dtBool:
13 | boolValue*: bool
14 | of dtDictEntry:
15 | dictKey*, dictValue*: DbusValue
16 | of dtDouble:
17 | doubleValue*: float64
18 | of dtSignature:
19 | signatureValue*: Signature
20 | of dtUnixFd:
21 | fdValue*: FD
22 | of dtInt32:
23 | int32Value*: int32
24 | of dtInt16:
25 | int16Value*: int16
26 | of dtObjectPath:
27 | objectPathValue*: ObjectPath
28 | of dtUint16:
29 | uint16Value*: uint16
30 | of dtString:
31 | stringValue*: string
32 | of dtStruct:
33 | structValues*: seq[DbusValue]
34 | of dtUint64:
35 | uint64Value*: uint64
36 | of dtUint32:
37 | uint32Value*: uint32
38 | of dtInt64:
39 | int64Value*: int64
40 | of dtByte:
41 | byteValue*: uint8
42 | of dtVariant:
43 | variantType*: DbusType
44 | variantValue*: DbusValue
45 | else:
46 | discard
47 |
48 | proc `$`*(val: DbusValue): string =
49 | result.add("')
90 |
91 | type DbusNativePrimitive = bool | float64 | int32 | int16 | uint16 | uint64 | uint32 | int64 | uint8
92 |
93 | proc getPrimitive(val: DbusValue): pointer =
94 | case val.kind
95 | of dtDouble:
96 | return addr val.doubleValue
97 | of dtInt32:
98 | return addr val.int32Value
99 | of dtInt16:
100 | return addr val.int16Value
101 | of dtUint16:
102 | return addr val.uint16Value
103 | of dtUint64:
104 | return addr val.uint64Value
105 | of dtUint32:
106 | return addr val.uint32Value
107 | of dtInt64:
108 | return addr val.int64Value
109 | of dtByte:
110 | return addr val.byteValue
111 | else:
112 | raise newException(ValueError, "value is not primitive")
113 |
114 | proc getString(val: DbusValue): var string =
115 | case val.kind
116 | of dtString:
117 | return val.stringValue
118 | of dtSignature:
119 | return val.signatureValue.string
120 | of dtObjectPath:
121 | return val.objectPathValue.string
122 | else:
123 | raise newException(ValueError, "value is not string")
124 |
125 | proc createStringDbusValue(kind: DbusTypeChar, val: string): DbusValue =
126 | case kind
127 | of dtString:
128 | result = DbusValue(kind: kind, stringValue: val)
129 | of dtSignature:
130 | result = DbusValue(kind: kind, signatureValue: val.Signature)
131 | of dtObjectPath:
132 | result = DbusValue(kind: kind, objectPathValue: val.ObjectPath)
133 | else:
134 | raise newException(ValueError, "value is not string")
135 |
136 | proc createScalarDbusValue(kind: DbusTypeChar): tuple[value: DbusValue, scalarPtr: pointer] =
137 | var value = DBusValue(kind: kind)
138 | (value, getPrimitive(value))
139 |
140 | proc createDictEntryDbusValue(key, val: DbusValue): DbusValue =
141 | DbusValue(kind: dtDictEntry, dictKey: key, dictValue: val)
142 |
143 | proc asDbusValue*(val: bool): DbusValue =
144 | DbusValue(kind: dtBool, boolValue: val)
145 |
146 | proc asDbusValue*(val: float64): DbusValue =
147 | DbusValue(kind: dtDouble, doubleValue: val)
148 |
149 | proc asDbusValue*(val: int16): DbusValue =
150 | DbusValue(kind: dtInt16, int16Value: val)
151 |
152 | proc asDbusValue*(val: int32): DbusValue =
153 | DbusValue(kind: dtInt32, int32Value: val)
154 |
155 | proc asDbusValue*(val: int64): DbusValue =
156 | DbusValue(kind: dtInt64, int64Value: val)
157 |
158 | proc asDbusValue*(val: uint16): DbusValue =
159 | DbusValue(kind: dtUint16, uint16Value: val)
160 |
161 | proc asDbusValue*(val: uint32): DbusValue =
162 | DbusValue(kind: dtUint32, uint32Value: val)
163 |
164 | proc asDbusValue*(val: uint64): DbusValue =
165 | DbusValue(kind: dtUint64, uint64Value: val)
166 |
167 | proc asDbusValue*(val: uint8): DbusValue =
168 | DbusValue(kind: dtByte, byteValue: val)
169 |
170 | proc asDbusValue*(val: string): DbusValue =
171 | DbusValue(kind: dtString, stringValue: val)
172 |
173 | proc asDbusValue*(val: ObjectPath): DbusValue =
174 | DbusValue(kind: dtObjectPath, objectPathValue: val)
175 |
176 | proc asDbusValue*(val: Signature): DbusValue =
177 | DbusValue(kind: dtSignature, signatureValue: val)
178 |
179 | proc asDbusValue*(val: DbusValue): DbusValue =
180 | val
181 |
182 | proc getDbusType*(val: DbusValue): DbusType =
183 | case val.kind
184 | of dbusScalarTypes:
185 | return val.kind
186 | of dbusStringTypes:
187 | return val.kind
188 | of dtArray:
189 | return DbusType(kind: dtArray, itemType: val.arrayValueType)
190 | of dtNull:
191 | return dtNull
192 | of dtDictEntry:
193 | return DbusType(kind: dtDictEntry,
194 | keyType: getDbusType(val.dictKey),
195 | valueType: getDbusType(val.dictValue))
196 | of dtUnixFd:
197 | return dtUnixFd
198 | of dtStruct:
199 | return DbusType(kind: dtStruct,
200 | itemTypes: val.structValues.mapIt(getDbusType(it)))
201 | of dtVariant:
202 | return DbusType(kind: dtVariant, variantType: val.variantType)
203 | of dtDict:
204 | return val.kind
205 |
206 | proc getAnyDbusType*(val: DbusValue): DbusType =
207 | getDbusType(val)
208 |
209 | proc asDbusValue*[T](val: seq[T]): DbusValue =
210 | result = DbusValue(kind: dtArray, arrayValueType: getAnyDbusType(T))
211 | for x in val:
212 | result.arrayValue.add x.asDbusValue
213 |
214 | proc asDbusValue*[K, V](val: Table[K, V]): DbusValue =
215 | result = DbusValue(kind: dtArray,
216 | arrayValueType: DbusType(kind: dtDictEntry,
217 | keyType: getAnyDbusType(K),
218 | valueType: getAnyDbusType(V)))
219 | for k, v in val:
220 | result.arrayValue.add(
221 | createDictEntryDbusValue(asDbusValue(k), asDbusValue(v)))
222 |
223 | proc asDbusValue*(val: Variant[DbusValue]): DbusValue =
224 | DbusValue(kind: dtVariant, variantType: getDbusType(val.value),
225 | variantValue: val.value)
226 |
227 | proc asDbusValue*[T](val: Variant[T]): DbusValue =
228 | DbusValue(kind: dtVariant, variantType: getAnyDbusType(T),
229 | variantValue: asDbusValue(val.value))
230 |
231 | proc asNative*(value: DbusValue, native: typedesc[bool]): bool =
232 | value.boolValue
233 |
234 | proc asNative*(value: DbusValue, native: typedesc[float64]): float64 =
235 | value.doubleValue
236 |
237 | proc asNative*(value: DbusValue, native: typedesc[int16]): int16 =
238 | value.int16Value
239 |
240 | proc asNative*(value: DbusValue, native: typedesc[int32]): int32 =
241 | value.int32Value
242 |
243 | proc asNative*(value: DbusValue, native: typedesc[int64]): int64 =
244 | value.int64Value
245 |
246 | proc asNative*(value: DbusValue, native: typedesc[uint16]): uint16 =
247 | value.uint16Value
248 |
249 | proc asNative*(value: DbusValue, native: typedesc[uint32]): uint32 =
250 | value.uint32Value
251 |
252 | proc asNative*(value: DbusValue, native: typedesc[uint64]): uint64 =
253 | value.uint64Value
254 |
255 | proc asNative*(value: DbusValue, native: typedesc[uint8]): uint8 =
256 | value.byteValue
257 |
258 | proc asNative*(value: DbusValue, native: typedesc[string]): string =
259 | value.stringValue
260 |
261 | proc asNative*(value: DbusValue, native: typedesc[ObjectPath]): ObjectPath =
262 | value.objectPathValue
263 |
264 | proc asNative*(value: DbusValue, native: typedesc[Signature]): Signature =
265 | value.signatureValue
266 |
267 | proc asNative*[T](value: DbusValue, native: typedesc[seq[T]]): seq[T] =
268 | for str in value.arrayValue:
269 | result.add asNative(str, T)
270 |
271 | proc asNative*[T, K](value: DbusValue, native: typedesc[Table[T, K]]): Table[T, K] =
272 | if value == nil: return
273 | for kv in value.arrayValue:
274 | result[asNative(kv.dictKey, T)] = asNative(kv.dictValue, K)
275 |
276 | proc add*(dict: DbusValue, key: DbusValue, value: DbusValue) =
277 | doAssert dict.kind == dtArray
278 | dict.arrayValue.add(
279 | createDictEntryDbusValue(asDbusValue(key), asDbusValue(value)))
280 |
--------------------------------------------------------------------------------
/include/dbus/dbus-message.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-message.h DBusMessage object
3 | *
4 | * Copyright (C) 2002, 2003, 2005 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_MESSAGE_H
28 | #define DBUS_MESSAGE_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 | #include
35 | //#include
36 |
37 | DBUS_BEGIN_DECLS
38 |
39 | /**
40 | * @addtogroup DBusMessage
41 | * @{
42 | */
43 |
44 | struct DBusMessage;
45 | typedef struct DBusMessage DBusMessage;
46 | /** Opaque type representing a message iterator. Can be copied by value, and contains no allocated memory so never needs to be freed and can be allocated on the stack. */;
47 | typedef struct DBusMessageIter DBusMessageIter;
48 |
49 | /**
50 | * DBusMessageIter struct; contains no public fields.
51 | */
52 | struct DBusMessageIter
53 | {
54 | void *dummy1; /**< Don't use this */
55 | void *dummy2; /**< Don't use this */
56 | dbus_uint32_t dummy3; /**< Don't use this */
57 | int dummy4; /**< Don't use this */
58 | int dummy5; /**< Don't use this */
59 | int dummy6; /**< Don't use this */
60 | int dummy7; /**< Don't use this */
61 | int dummy8; /**< Don't use this */
62 | int dummy9; /**< Don't use this */
63 | int dummy10; /**< Don't use this */
64 | int dummy11; /**< Don't use this */
65 | int pad1; /**< Don't use this */
66 | int pad2; /**< Don't use this */
67 | void *pad3; /**< Don't use this */
68 | };
69 |
70 | DBUS_EXPORT
71 | DBusMessage* dbus_message_new (int message_type);
72 | DBUS_EXPORT
73 | DBusMessage* dbus_message_new_method_call (const char *bus_name,
74 | const char *path,
75 | const char *iface,
76 | const char *method);
77 | DBUS_EXPORT
78 | DBusMessage* dbus_message_new_method_return (DBusMessage *method_call);
79 | DBUS_EXPORT
80 | DBusMessage* dbus_message_new_signal (const char *path,
81 | const char *iface,
82 | const char *name);
83 | DBUS_EXPORT
84 | DBusMessage* dbus_message_new_error (DBusMessage *reply_to,
85 | const char *error_name,
86 | const char *error_message);
87 | DBUS_EXPORT
88 | DBusMessage* dbus_message_new_error_printf (DBusMessage *reply_to,
89 | const char *error_name,
90 | const char *error_format,
91 | ...);
92 |
93 | DBUS_EXPORT
94 | DBusMessage* dbus_message_copy (const DBusMessage *message);
95 |
96 | DBUS_EXPORT
97 | DBusMessage* dbus_message_ref (DBusMessage *message);
98 | DBUS_EXPORT
99 | void dbus_message_unref (DBusMessage *message);
100 | DBUS_EXPORT
101 | int dbus_message_get_type (DBusMessage *message);
102 | DBUS_EXPORT
103 | dbus_bool_t dbus_message_set_path (DBusMessage *message,
104 | const char *object_path);
105 | DBUS_EXPORT
106 | const char* dbus_message_get_path (DBusMessage *message);
107 | DBUS_EXPORT
108 | dbus_bool_t dbus_message_has_path (DBusMessage *message,
109 | const char *object_path);
110 | DBUS_EXPORT
111 | dbus_bool_t dbus_message_set_interface (DBusMessage *message,
112 | const char *iface);
113 | DBUS_EXPORT
114 | const char* dbus_message_get_interface (DBusMessage *message);
115 | DBUS_EXPORT
116 | dbus_bool_t dbus_message_has_interface (DBusMessage *message,
117 | const char *iface);
118 | DBUS_EXPORT
119 | dbus_bool_t dbus_message_set_member (DBusMessage *message,
120 | const char *member);
121 | DBUS_EXPORT
122 | const char* dbus_message_get_member (DBusMessage *message);
123 | DBUS_EXPORT
124 | dbus_bool_t dbus_message_has_member (DBusMessage *message,
125 | const char *member);
126 | DBUS_EXPORT
127 | dbus_bool_t dbus_message_set_error_name (DBusMessage *message,
128 | const char *name);
129 | DBUS_EXPORT
130 | const char* dbus_message_get_error_name (DBusMessage *message);
131 | DBUS_EXPORT
132 | dbus_bool_t dbus_message_set_destination (DBusMessage *message,
133 | const char *destination);
134 | DBUS_EXPORT
135 | const char* dbus_message_get_destination (DBusMessage *message);
136 | DBUS_EXPORT
137 | dbus_bool_t dbus_message_set_sender (DBusMessage *message,
138 | const char *sender);
139 | DBUS_EXPORT
140 | const char* dbus_message_get_sender (DBusMessage *message);
141 | DBUS_EXPORT
142 | const char* dbus_message_get_signature (DBusMessage *message);
143 | DBUS_EXPORT
144 | void dbus_message_set_no_reply (DBusMessage *message,
145 | dbus_bool_t no_reply);
146 | DBUS_EXPORT
147 | dbus_bool_t dbus_message_get_no_reply (DBusMessage *message);
148 | DBUS_EXPORT
149 | dbus_bool_t dbus_message_is_method_call (DBusMessage *message,
150 | const char *iface,
151 | const char *method);
152 | DBUS_EXPORT
153 | dbus_bool_t dbus_message_is_signal (DBusMessage *message,
154 | const char *iface,
155 | const char *signal_name);
156 | DBUS_EXPORT
157 | dbus_bool_t dbus_message_is_error (DBusMessage *message,
158 | const char *error_name);
159 | DBUS_EXPORT
160 | dbus_bool_t dbus_message_has_destination (DBusMessage *message,
161 | const char *bus_name);
162 | DBUS_EXPORT
163 | dbus_bool_t dbus_message_has_sender (DBusMessage *message,
164 | const char *unique_bus_name);
165 | DBUS_EXPORT
166 | dbus_bool_t dbus_message_has_signature (DBusMessage *message,
167 | const char *signature);
168 | DBUS_EXPORT
169 | dbus_uint32_t dbus_message_get_serial (DBusMessage *message);
170 | DBUS_EXPORT
171 | void dbus_message_set_serial (DBusMessage *message,
172 | dbus_uint32_t serial);
173 | DBUS_EXPORT
174 | dbus_bool_t dbus_message_set_reply_serial (DBusMessage *message,
175 | dbus_uint32_t reply_serial);
176 | DBUS_EXPORT
177 | dbus_uint32_t dbus_message_get_reply_serial (DBusMessage *message);
178 |
179 | DBUS_EXPORT
180 | void dbus_message_set_auto_start (DBusMessage *message,
181 | dbus_bool_t auto_start);
182 | DBUS_EXPORT
183 | dbus_bool_t dbus_message_get_auto_start (DBusMessage *message);
184 |
185 | DBUS_EXPORT
186 | dbus_bool_t dbus_message_get_path_decomposed (DBusMessage *message,
187 | char ***path);
188 |
189 | DBUS_EXPORT
190 | dbus_bool_t dbus_message_append_args (DBusMessage *message,
191 | int first_arg_type,
192 | ...);
193 | //DBUS_EXPORT
194 | //dbus_bool_t dbus_message_append_args_valist (DBusMessage *message,
195 | // int first_arg_type,
196 | // va_list var_args);
197 | DBUS_EXPORT
198 | dbus_bool_t dbus_message_get_args (DBusMessage *message,
199 | DBusError *error,
200 | int first_arg_type,
201 | ...);
202 | //DBUS_EXPORT
203 | //dbus_bool_t dbus_message_get_args_valist (DBusMessage *message,
204 | // DBusError *error,
205 | // int first_arg_type,
206 | // va_list var_args);
207 |
208 | DBUS_EXPORT
209 | dbus_bool_t dbus_message_contains_unix_fds (DBusMessage *message);
210 |
211 | DBUS_EXPORT
212 | dbus_bool_t dbus_message_iter_init (DBusMessage *message,
213 | DBusMessageIter *iter);
214 | DBUS_EXPORT
215 | dbus_bool_t dbus_message_iter_has_next (DBusMessageIter *iter);
216 | DBUS_EXPORT
217 | dbus_bool_t dbus_message_iter_next (DBusMessageIter *iter);
218 | DBUS_EXPORT
219 | char* dbus_message_iter_get_signature (DBusMessageIter *iter);
220 | DBUS_EXPORT
221 | int dbus_message_iter_get_arg_type (DBusMessageIter *iter);
222 | DBUS_EXPORT
223 | int dbus_message_iter_get_element_type (DBusMessageIter *iter);
224 | DBUS_EXPORT
225 | void dbus_message_iter_recurse (DBusMessageIter *iter,
226 | DBusMessageIter *sub);
227 | DBUS_EXPORT
228 | void dbus_message_iter_get_basic (DBusMessageIter *iter,
229 | void *value);
230 | #ifndef DBUS_DISABLE_DEPRECATED
231 | /* This function returns the wire protocol size of the array in bytes,
232 | * you do not want to know that probably
233 | */
234 | DBUS_EXPORT
235 | DBUS_DEPRECATED int dbus_message_iter_get_array_len (DBusMessageIter *iter);
236 | #endif
237 | DBUS_EXPORT
238 | void dbus_message_iter_get_fixed_array (DBusMessageIter *iter,
239 | void *value,
240 | int *n_elements);
241 |
242 |
243 | DBUS_EXPORT
244 | void dbus_message_iter_init_append (DBusMessage *message,
245 | DBusMessageIter *iter);
246 | DBUS_EXPORT
247 | dbus_bool_t dbus_message_iter_append_basic (DBusMessageIter *iter,
248 | int type,
249 | const void *value);
250 | DBUS_EXPORT
251 | dbus_bool_t dbus_message_iter_append_fixed_array (DBusMessageIter *iter,
252 | int element_type,
253 | const void *value,
254 | int n_elements);
255 | DBUS_EXPORT
256 | dbus_bool_t dbus_message_iter_open_container (DBusMessageIter *iter,
257 | int type,
258 | const char *contained_signature,
259 | DBusMessageIter *sub);
260 | DBUS_EXPORT
261 | dbus_bool_t dbus_message_iter_close_container (DBusMessageIter *iter,
262 | DBusMessageIter *sub);
263 | DBUS_EXPORT
264 | void dbus_message_iter_abandon_container (DBusMessageIter *iter,
265 | DBusMessageIter *sub);
266 |
267 | DBUS_EXPORT
268 | void dbus_message_lock (DBusMessage *message);
269 |
270 | DBUS_EXPORT
271 | dbus_bool_t dbus_set_error_from_message (DBusError *error,
272 | DBusMessage *message);
273 |
274 |
275 | DBUS_EXPORT
276 | dbus_bool_t dbus_message_allocate_data_slot (dbus_int32_t *slot_p);
277 | DBUS_EXPORT
278 | void dbus_message_free_data_slot (dbus_int32_t *slot_p);
279 | DBUS_EXPORT
280 | dbus_bool_t dbus_message_set_data (DBusMessage *message,
281 | dbus_int32_t slot,
282 | void *data,
283 | DBusFreeFunction free_data_func);
284 | DBUS_EXPORT
285 | void* dbus_message_get_data (DBusMessage *message,
286 | dbus_int32_t slot);
287 |
288 | DBUS_EXPORT
289 | int dbus_message_type_from_string (const char *type_str);
290 | DBUS_EXPORT
291 | const char* dbus_message_type_to_string (int type);
292 |
293 | DBUS_EXPORT
294 | dbus_bool_t dbus_message_marshal (DBusMessage *msg,
295 | char **marshalled_data_p,
296 | int *len_p);
297 | DBUS_EXPORT
298 | DBusMessage* dbus_message_demarshal (const char *str,
299 | int len,
300 | DBusError *error);
301 |
302 | DBUS_EXPORT
303 | int dbus_message_demarshal_bytes_needed (const char *str,
304 | int len);
305 |
306 | /** @} */
307 |
308 | DBUS_END_DECLS
309 |
310 | #endif /* DBUS_MESSAGE_H */
311 |
--------------------------------------------------------------------------------
/include/dbus/dbus-protocol.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-protocol.h D-Bus protocol constants
3 | *
4 | * Copyright (C) 2002, 2003 CodeFactory AB
5 | * Copyright (C) 2004, 2005 Red Hat, Inc.
6 | *
7 | * Licensed under the Academic Free License version 2.1
8 | *
9 | * This program is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation; either version 2 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * This program is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with this program; if not, write to the Free Software
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 | *
23 | */
24 |
25 | #ifndef DBUS_PROTOCOL_H
26 | #define DBUS_PROTOCOL_H
27 |
28 | /* Don't include anything in here from anywhere else. It's
29 | * intended for use by any random library.
30 | */
31 |
32 | #ifdef __cplusplus
33 | extern "C" {
34 | #if 0
35 | } /* avoids confusing emacs indentation */
36 | #endif
37 | #endif
38 |
39 | /* Normally docs are in .c files, but there isn't a .c file for this. */
40 | /**
41 | * @defgroup DBusProtocol Protocol constants
42 | * @ingroup DBus
43 | *
44 | * @brief Defines constants which are part of the D-Bus protocol
45 | *
46 | * This header is intended for use by any library, not only libdbus.
47 | *
48 | * @{
49 | */
50 |
51 |
52 | /* Message byte order */
53 | #define DBUS_LITTLE_ENDIAN ('l') /**< Code marking LSB-first byte order in the wire protocol. */
54 | #define DBUS_BIG_ENDIAN ('B') /**< Code marking MSB-first byte order in the wire protocol. */
55 |
56 | /** Protocol version. */
57 | #define DBUS_MAJOR_PROTOCOL_VERSION 1
58 |
59 | /** Type code that is never equal to a legitimate type code */
60 | #define DBUS_TYPE_INVALID ((int) '\0')
61 | /** #DBUS_TYPE_INVALID as a string literal instead of a int literal */
62 | #define DBUS_TYPE_INVALID_AS_STRING "\0"
63 |
64 | /* Primitive types */
65 | /** Type code marking an 8-bit unsigned integer */
66 | #define DBUS_TYPE_BYTE ((int) 'y')
67 | /** #DBUS_TYPE_BYTE as a string literal instead of a int literal */
68 | #define DBUS_TYPE_BYTE_AS_STRING "y"
69 | /** Type code marking a boolean */
70 | #define DBUS_TYPE_BOOLEAN ((int) 'b')
71 | /** #DBUS_TYPE_BOOLEAN as a string literal instead of a int literal */
72 | #define DBUS_TYPE_BOOLEAN_AS_STRING "b"
73 | /** Type code marking a 16-bit signed integer */
74 | #define DBUS_TYPE_INT16 ((int) 'n')
75 | /** #DBUS_TYPE_INT16 as a string literal instead of a int literal */
76 | #define DBUS_TYPE_INT16_AS_STRING "n"
77 | /** Type code marking a 16-bit unsigned integer */
78 | #define DBUS_TYPE_UINT16 ((int) 'q')
79 | /** #DBUS_TYPE_UINT16 as a string literal instead of a int literal */
80 | #define DBUS_TYPE_UINT16_AS_STRING "q"
81 | /** Type code marking a 32-bit signed integer */
82 | #define DBUS_TYPE_INT32 ((int) 'i')
83 | /** #DBUS_TYPE_INT32 as a string literal instead of a int literal */
84 | #define DBUS_TYPE_INT32_AS_STRING "i"
85 | /** Type code marking a 32-bit unsigned integer */
86 | #define DBUS_TYPE_UINT32 ((int) 'u')
87 | /** #DBUS_TYPE_UINT32 as a string literal instead of a int literal */
88 | #define DBUS_TYPE_UINT32_AS_STRING "u"
89 | /** Type code marking a 64-bit signed integer */
90 | #define DBUS_TYPE_INT64 ((int) 'x')
91 | /** #DBUS_TYPE_INT64 as a string literal instead of a int literal */
92 | #define DBUS_TYPE_INT64_AS_STRING "x"
93 | /** Type code marking a 64-bit unsigned integer */
94 | #define DBUS_TYPE_UINT64 ((int) 't')
95 | /** #DBUS_TYPE_UINT64 as a string literal instead of a int literal */
96 | #define DBUS_TYPE_UINT64_AS_STRING "t"
97 | /** Type code marking an 8-byte double in IEEE 754 format */
98 | #define DBUS_TYPE_DOUBLE ((int) 'd')
99 | /** #DBUS_TYPE_DOUBLE as a string literal instead of a int literal */
100 | #define DBUS_TYPE_DOUBLE_AS_STRING "d"
101 | /** Type code marking a UTF-8 encoded, nul-terminated Unicode string */
102 | #define DBUS_TYPE_STRING ((int) 's')
103 | /** #DBUS_TYPE_STRING as a string literal instead of a int literal */
104 | #define DBUS_TYPE_STRING_AS_STRING "s"
105 | /** Type code marking a D-Bus object path */
106 | #define DBUS_TYPE_OBJECT_PATH ((int) 'o')
107 | /** #DBUS_TYPE_OBJECT_PATH as a string literal instead of a int literal */
108 | #define DBUS_TYPE_OBJECT_PATH_AS_STRING "o"
109 | /** Type code marking a D-Bus type signature */
110 | #define DBUS_TYPE_SIGNATURE ((int) 'g')
111 | /** #DBUS_TYPE_SIGNATURE as a string literal instead of a int literal */
112 | #define DBUS_TYPE_SIGNATURE_AS_STRING "g"
113 | /** Type code marking a unix file descriptor */
114 | #define DBUS_TYPE_UNIX_FD ((int) 'h')
115 | /** #DBUS_TYPE_UNIX_FD as a string literal instead of a int literal */
116 | #define DBUS_TYPE_UNIX_FD_AS_STRING "h"
117 |
118 | /* Compound types */
119 | /** Type code marking a D-Bus array type */
120 | #define DBUS_TYPE_ARRAY ((int) 'a')
121 | /** #DBUS_TYPE_ARRAY as a string literal instead of a int literal */
122 | #define DBUS_TYPE_ARRAY_AS_STRING "a"
123 | /** Type code marking a D-Bus variant type */
124 | #define DBUS_TYPE_VARIANT ((int) 'v')
125 | /** #DBUS_TYPE_VARIANT as a string literal instead of a int literal */
126 | #define DBUS_TYPE_VARIANT_AS_STRING "v"
127 |
128 | /** STRUCT and DICT_ENTRY are sort of special since their codes can't
129 | * appear in a type string, instead
130 | * DBUS_STRUCT_BEGIN_CHAR/DBUS_DICT_ENTRY_BEGIN_CHAR have to appear
131 | */
132 | /** Type code used to represent a struct; however, this type code does not appear
133 | * in type signatures, instead #DBUS_STRUCT_BEGIN_CHAR and #DBUS_STRUCT_END_CHAR will
134 | * appear in a signature.
135 | */
136 | #define DBUS_TYPE_STRUCT ((int) 'r')
137 | /** #DBUS_TYPE_STRUCT as a string literal instead of a int literal */
138 | #define DBUS_TYPE_STRUCT_AS_STRING "r"
139 | /** Type code used to represent a dict entry; however, this type code does not appear
140 | * in type signatures, instead #DBUS_DICT_ENTRY_BEGIN_CHAR and #DBUS_DICT_ENTRY_END_CHAR will
141 | * appear in a signature.
142 | */
143 | #define DBUS_TYPE_DICT_ENTRY ((int) 'e')
144 | /** #DBUS_TYPE_DICT_ENTRY as a string literal instead of a int literal */
145 | #define DBUS_TYPE_DICT_ENTRY_AS_STRING "e"
146 |
147 | /** Does not include #DBUS_TYPE_INVALID, #DBUS_STRUCT_BEGIN_CHAR, #DBUS_STRUCT_END_CHAR,
148 | * #DBUS_DICT_ENTRY_BEGIN_CHAR, or #DBUS_DICT_ENTRY_END_CHAR - i.e. it is the number of
149 | * valid types, not the number of distinct characters that may appear in a type signature.
150 | */
151 | #define DBUS_NUMBER_OF_TYPES (16)
152 |
153 | /* characters other than typecodes that appear in type signatures */
154 |
155 | /** Code marking the start of a struct type in a type signature */
156 | #define DBUS_STRUCT_BEGIN_CHAR ((int) '(')
157 | /** #DBUS_STRUCT_BEGIN_CHAR as a string literal instead of a int literal */
158 | #define DBUS_STRUCT_BEGIN_CHAR_AS_STRING "("
159 | /** Code marking the end of a struct type in a type signature */
160 | #define DBUS_STRUCT_END_CHAR ((int) ')')
161 | /** #DBUS_STRUCT_END_CHAR a string literal instead of a int literal */
162 | #define DBUS_STRUCT_END_CHAR_AS_STRING ")"
163 | /** Code marking the start of a dict entry type in a type signature */
164 | #define DBUS_DICT_ENTRY_BEGIN_CHAR ((int) '{')
165 | /** #DBUS_DICT_ENTRY_BEGIN_CHAR as a string literal instead of a int literal */
166 | #define DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING "{"
167 | /** Code marking the end of a dict entry type in a type signature */
168 | #define DBUS_DICT_ENTRY_END_CHAR ((int) '}')
169 | /** #DBUS_DICT_ENTRY_END_CHAR as a string literal instead of a int literal */
170 | #define DBUS_DICT_ENTRY_END_CHAR_AS_STRING "}"
171 |
172 | /** Max length in bytes of a bus name, interface, or member (not object
173 | * path, paths are unlimited). This is limited because lots of stuff
174 | * is O(n) in this number, plus it would be obnoxious to type in a
175 | * paragraph-long method name so most likely something like that would
176 | * be an exploit.
177 | */
178 | #define DBUS_MAXIMUM_NAME_LENGTH 255
179 |
180 | /** This one is 255 so it fits in a byte */
181 | #define DBUS_MAXIMUM_SIGNATURE_LENGTH 255
182 |
183 | /** Max length of a match rule string; to keep people from hosing the
184 | * daemon with some huge rule
185 | */
186 | #define DBUS_MAXIMUM_MATCH_RULE_LENGTH 1024
187 |
188 | /** Max arg number you can match on in a match rule, e.g.
189 | * arg0='hello' is OK, arg3489720987='hello' is not
190 | */
191 | #define DBUS_MAXIMUM_MATCH_RULE_ARG_NUMBER 63
192 |
193 | /** Max length of a marshaled array in bytes (64M, 2^26) We use signed
194 | * int for lengths so must be INT_MAX or less. We need something a
195 | * bit smaller than INT_MAX because the array is inside a message with
196 | * header info, etc. so an INT_MAX array wouldn't allow the message
197 | * overhead. The 64M number is an attempt at a larger number than
198 | * we'd reasonably ever use, but small enough that your bus would chew
199 | * through it fairly quickly without locking up forever. If you have
200 | * data that's likely to be larger than this, you should probably be
201 | * sending it in multiple incremental messages anyhow.
202 | */
203 | #define DBUS_MAXIMUM_ARRAY_LENGTH (67108864)
204 | /** Number of bits you need in an unsigned to store the max array size */
205 | #define DBUS_MAXIMUM_ARRAY_LENGTH_BITS 26
206 |
207 | /** The maximum total message size including header and body; similar
208 | * rationale to max array size.
209 | */
210 | #define DBUS_MAXIMUM_MESSAGE_LENGTH (DBUS_MAXIMUM_ARRAY_LENGTH * 2)
211 | /** Number of bits you need in an unsigned to store the max message size */
212 | #define DBUS_MAXIMUM_MESSAGE_LENGTH_BITS 27
213 |
214 | /** The maximum total number of unix fds in a message. Similar
215 | * rationale as DBUS_MAXIMUM_MESSAGE_LENGTH. However we divide by four
216 | * given that one fd is an int and hence at least 32 bits.
217 | */
218 | #define DBUS_MAXIMUM_MESSAGE_UNIX_FDS (DBUS_MAXIMUM_MESSAGE_LENGTH/4)
219 | /** Number of bits you need in an unsigned to store the max message unix fds */
220 | #define DBUS_MAXIMUM_MESSAGE_UNIX_FDS_BITS (DBUS_MAXIMUM_MESSAGE_LENGTH_BITS-2)
221 |
222 | /** Depth of recursion in the type tree. This is automatically limited
223 | * to DBUS_MAXIMUM_SIGNATURE_LENGTH since you could only have an array
224 | * of array of array of ... that fit in the max signature. But that's
225 | * probably a bit too large.
226 | */
227 | #define DBUS_MAXIMUM_TYPE_RECURSION_DEPTH 32
228 |
229 | /* Types of message */
230 |
231 | /** This value is never a valid message type, see dbus_message_get_type() */
232 | #define DBUS_MESSAGE_TYPE_INVALID 0
233 | /** Message type of a method call message, see dbus_message_get_type() */
234 | #define DBUS_MESSAGE_TYPE_METHOD_CALL 1
235 | /** Message type of a method return message, see dbus_message_get_type() */
236 | #define DBUS_MESSAGE_TYPE_METHOD_RETURN 2
237 | /** Message type of an error reply message, see dbus_message_get_type() */
238 | #define DBUS_MESSAGE_TYPE_ERROR 3
239 | /** Message type of a signal message, see dbus_message_get_type() */
240 | #define DBUS_MESSAGE_TYPE_SIGNAL 4
241 |
242 | #define DBUS_NUM_MESSAGE_TYPES 5
243 |
244 | /* Header flags */
245 |
246 | /** If set, this flag means that the sender of a message does not care about getting
247 | * a reply, so the recipient need not send one. See dbus_message_set_no_reply().
248 | */
249 | #define DBUS_HEADER_FLAG_NO_REPLY_EXPECTED 0x1
250 | /**
251 | * If set, this flag means that even if the message bus knows how to start an owner for
252 | * the destination bus name (see dbus_message_set_destination()), it should not
253 | * do so. If this flag is not set, the bus may launch a program to process the
254 | * message.
255 | */
256 | #define DBUS_HEADER_FLAG_NO_AUTO_START 0x2
257 |
258 | /* Header fields */
259 |
260 | /** Not equal to any valid header field code */
261 | #define DBUS_HEADER_FIELD_INVALID 0
262 | /** Header field code for the path - the path is the object emitting a signal or the object receiving a method call.
263 | * See dbus_message_set_path().
264 | */
265 | #define DBUS_HEADER_FIELD_PATH 1
266 | /** Header field code for the interface containing a member (method or signal).
267 | * See dbus_message_set_interface().
268 | */
269 | #define DBUS_HEADER_FIELD_INTERFACE 2
270 | /** Header field code for a member (method or signal). See dbus_message_set_member(). */
271 | #define DBUS_HEADER_FIELD_MEMBER 3
272 | /** Header field code for an error name (found in #DBUS_MESSAGE_TYPE_ERROR messages).
273 | * See dbus_message_set_error_name().
274 | */
275 | #define DBUS_HEADER_FIELD_ERROR_NAME 4
276 | /** Header field code for a reply serial, used to match a #DBUS_MESSAGE_TYPE_METHOD_RETURN message with the
277 | * message that it's a reply to. See dbus_message_set_reply_serial().
278 | */
279 | #define DBUS_HEADER_FIELD_REPLY_SERIAL 5
280 | /**
281 | * Header field code for the destination bus name of a message. See dbus_message_set_destination().
282 | */
283 | #define DBUS_HEADER_FIELD_DESTINATION 6
284 | /**
285 | * Header field code for the sender of a message; usually initialized by the message bus.
286 | * See dbus_message_set_sender().
287 | */
288 | #define DBUS_HEADER_FIELD_SENDER 7
289 | /**
290 | * Header field code for the type signature of a message.
291 | */
292 | #define DBUS_HEADER_FIELD_SIGNATURE 8
293 | /**
294 | * Header field code for the number of unix file descriptors associated
295 | * with this message.
296 | */
297 | #define DBUS_HEADER_FIELD_UNIX_FDS 9
298 |
299 |
300 | /**
301 | * Value of the highest-numbered header field code, can be used to determine
302 | * the size of an array indexed by header field code. Remember though
303 | * that unknown codes must be ignored, so check for that before
304 | * indexing the array.
305 | */
306 | #define DBUS_HEADER_FIELD_LAST DBUS_HEADER_FIELD_UNIX_FDS
307 |
308 | /** Header format is defined as a signature:
309 | * byte byte order
310 | * byte message type ID
311 | * byte flags
312 | * byte protocol version
313 | * uint32 body length
314 | * uint32 serial
315 | * array of struct (byte,variant) (field name, value)
316 | *
317 | * The length of the header can be computed as the
318 | * fixed size of the initial data, plus the length of
319 | * the array at the end, plus padding to an 8-boundary.
320 | */
321 | #define DBUS_HEADER_SIGNATURE \
322 | DBUS_TYPE_BYTE_AS_STRING \
323 | DBUS_TYPE_BYTE_AS_STRING \
324 | DBUS_TYPE_BYTE_AS_STRING \
325 | DBUS_TYPE_BYTE_AS_STRING \
326 | DBUS_TYPE_UINT32_AS_STRING \
327 | DBUS_TYPE_UINT32_AS_STRING \
328 | DBUS_TYPE_ARRAY_AS_STRING \
329 | DBUS_STRUCT_BEGIN_CHAR_AS_STRING \
330 | DBUS_TYPE_BYTE_AS_STRING \
331 | DBUS_TYPE_VARIANT_AS_STRING \
332 | DBUS_STRUCT_END_CHAR_AS_STRING
333 |
334 |
335 | /**
336 | * The smallest header size that can occur. (It won't be valid due to
337 | * missing required header fields.) This is 4 bytes, two uint32, an
338 | * array length. This isn't any kind of resource limit, just the
339 | * necessary/logical outcome of the header signature.
340 | */
341 | #define DBUS_MINIMUM_HEADER_SIZE 16
342 |
343 | /* Errors */
344 | /* WARNING these get autoconverted to an enum in dbus-glib.h. Thus,
345 | * if you change the order it breaks the ABI. Keep them in order.
346 | * Also, don't change the formatting since that will break the sed
347 | * script.
348 | */
349 | /** A generic error; "something went wrong" - see the error message for more. */
350 | #define DBUS_ERROR_FAILED "org.freedesktop.DBus.Error.Failed"
351 | /** There was not enough memory to complete an operation. */
352 | #define DBUS_ERROR_NO_MEMORY "org.freedesktop.DBus.Error.NoMemory"
353 | /** The bus doesn't know how to launch a service to supply the bus name you wanted. */
354 | #define DBUS_ERROR_SERVICE_UNKNOWN "org.freedesktop.DBus.Error.ServiceUnknown"
355 | /** The bus name you referenced doesn't exist (i.e. no application owns it). */
356 | #define DBUS_ERROR_NAME_HAS_NO_OWNER "org.freedesktop.DBus.Error.NameHasNoOwner"
357 | /** No reply to a message expecting one, usually means a timeout occurred. */
358 | #define DBUS_ERROR_NO_REPLY "org.freedesktop.DBus.Error.NoReply"
359 | /** Something went wrong reading or writing to a socket, for example. */
360 | #define DBUS_ERROR_IO_ERROR "org.freedesktop.DBus.Error.IOError"
361 | /** A D-Bus bus address was malformed. */
362 | #define DBUS_ERROR_BAD_ADDRESS "org.freedesktop.DBus.Error.BadAddress"
363 | /** Requested operation isn't supported (like ENOSYS on UNIX). */
364 | #define DBUS_ERROR_NOT_SUPPORTED "org.freedesktop.DBus.Error.NotSupported"
365 | /** Some limited resource is exhausted. */
366 | #define DBUS_ERROR_LIMITS_EXCEEDED "org.freedesktop.DBus.Error.LimitsExceeded"
367 | /** Security restrictions don't allow doing what you're trying to do. */
368 | #define DBUS_ERROR_ACCESS_DENIED "org.freedesktop.DBus.Error.AccessDenied"
369 | /** Authentication didn't work. */
370 | #define DBUS_ERROR_AUTH_FAILED "org.freedesktop.DBus.Error.AuthFailed"
371 | /** Unable to connect to server (probably caused by ECONNREFUSED on a socket). */
372 | #define DBUS_ERROR_NO_SERVER "org.freedesktop.DBus.Error.NoServer"
373 | /** Certain timeout errors, possibly ETIMEDOUT on a socket.
374 | * Note that #DBUS_ERROR_NO_REPLY is used for message reply timeouts.
375 | * @warning this is confusingly-named given that #DBUS_ERROR_TIMED_OUT also exists. We can't fix
376 | * it for compatibility reasons so just be careful.
377 | */
378 | #define DBUS_ERROR_TIMEOUT "org.freedesktop.DBus.Error.Timeout"
379 | /** No network access (probably ENETUNREACH on a socket). */
380 | #define DBUS_ERROR_NO_NETWORK "org.freedesktop.DBus.Error.NoNetwork"
381 | /** Can't bind a socket since its address is in use (i.e. EADDRINUSE). */
382 | #define DBUS_ERROR_ADDRESS_IN_USE "org.freedesktop.DBus.Error.AddressInUse"
383 | /** The connection is disconnected and you're trying to use it. */
384 | #define DBUS_ERROR_DISCONNECTED "org.freedesktop.DBus.Error.Disconnected"
385 | /** Invalid arguments passed to a method call. */
386 | #define DBUS_ERROR_INVALID_ARGS "org.freedesktop.DBus.Error.InvalidArgs"
387 | /** Missing file. */
388 | #define DBUS_ERROR_FILE_NOT_FOUND "org.freedesktop.DBus.Error.FileNotFound"
389 | /** Existing file and the operation you're using does not silently overwrite. */
390 | #define DBUS_ERROR_FILE_EXISTS "org.freedesktop.DBus.Error.FileExists"
391 | /** Method name you invoked isn't known by the object you invoked it on. */
392 | #define DBUS_ERROR_UNKNOWN_METHOD "org.freedesktop.DBus.Error.UnknownMethod"
393 | /** Object you invoked a method on isn't known. */
394 | #define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
395 | /** Interface you invoked a method on isn't known by the object. */
396 | #define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
397 | /** Property you tried to access isn't known by the object. */
398 | #define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
399 | /** Property you tried to set is read-only. */
400 | #define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
401 | /** Certain timeout errors, e.g. while starting a service.
402 | * @warning this is confusingly-named given that #DBUS_ERROR_TIMEOUT also exists. We can't fix
403 | * it for compatibility reasons so just be careful.
404 | */
405 | #define DBUS_ERROR_TIMED_OUT "org.freedesktop.DBus.Error.TimedOut"
406 | /** Tried to remove or modify a match rule that didn't exist. */
407 | #define DBUS_ERROR_MATCH_RULE_NOT_FOUND "org.freedesktop.DBus.Error.MatchRuleNotFound"
408 | /** The match rule isn't syntactically valid. */
409 | #define DBUS_ERROR_MATCH_RULE_INVALID "org.freedesktop.DBus.Error.MatchRuleInvalid"
410 | /** While starting a new process, the exec() call failed. */
411 | #define DBUS_ERROR_SPAWN_EXEC_FAILED "org.freedesktop.DBus.Error.Spawn.ExecFailed"
412 | /** While starting a new process, the fork() call failed. */
413 | #define DBUS_ERROR_SPAWN_FORK_FAILED "org.freedesktop.DBus.Error.Spawn.ForkFailed"
414 | /** While starting a new process, the child exited with a status code. */
415 | #define DBUS_ERROR_SPAWN_CHILD_EXITED "org.freedesktop.DBus.Error.Spawn.ChildExited"
416 | /** While starting a new process, the child exited on a signal. */
417 | #define DBUS_ERROR_SPAWN_CHILD_SIGNALED "org.freedesktop.DBus.Error.Spawn.ChildSignaled"
418 | /** While starting a new process, something went wrong. */
419 | #define DBUS_ERROR_SPAWN_FAILED "org.freedesktop.DBus.Error.Spawn.Failed"
420 | /** We failed to setup the environment correctly. */
421 | #define DBUS_ERROR_SPAWN_SETUP_FAILED "org.freedesktop.DBus.Error.Spawn.FailedToSetup"
422 | /** We failed to setup the config parser correctly. */
423 | #define DBUS_ERROR_SPAWN_CONFIG_INVALID "org.freedesktop.DBus.Error.Spawn.ConfigInvalid"
424 | /** Bus name was not valid. */
425 | #define DBUS_ERROR_SPAWN_SERVICE_INVALID "org.freedesktop.DBus.Error.Spawn.ServiceNotValid"
426 | /** Service file not found in system-services directory. */
427 | #define DBUS_ERROR_SPAWN_SERVICE_NOT_FOUND "org.freedesktop.DBus.Error.Spawn.ServiceNotFound"
428 | /** Permissions are incorrect on the setuid helper. */
429 | #define DBUS_ERROR_SPAWN_PERMISSIONS_INVALID "org.freedesktop.DBus.Error.Spawn.PermissionsInvalid"
430 | /** Service file invalid (Name, User or Exec missing). */
431 | #define DBUS_ERROR_SPAWN_FILE_INVALID "org.freedesktop.DBus.Error.Spawn.FileInvalid"
432 | /** Tried to get a UNIX process ID and it wasn't available. */
433 | #define DBUS_ERROR_SPAWN_NO_MEMORY "org.freedesktop.DBus.Error.Spawn.NoMemory"
434 | /** Tried to get a UNIX process ID and it wasn't available. */
435 | #define DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN "org.freedesktop.DBus.Error.UnixProcessIdUnknown"
436 | /** A type signature is not valid. */
437 | #define DBUS_ERROR_INVALID_SIGNATURE "org.freedesktop.DBus.Error.InvalidSignature"
438 | /** A file contains invalid syntax or is otherwise broken. */
439 | #define DBUS_ERROR_INVALID_FILE_CONTENT "org.freedesktop.DBus.Error.InvalidFileContent"
440 | /** Asked for SELinux security context and it wasn't available. */
441 | #define DBUS_ERROR_SELINUX_SECURITY_CONTEXT_UNKNOWN "org.freedesktop.DBus.Error.SELinuxSecurityContextUnknown"
442 | /** Asked for AppArmor security context and it wasn't available. */
443 | #define DBUS_ERROR_APPARMOR_SECURITY_CONTEXT_UNKNOWN "org.freedesktop.DBus.Error.AppArmorSecurityContextUnknown"
444 | /** Asked for ADT audit data and it wasn't available. */
445 | #define DBUS_ERROR_ADT_AUDIT_DATA_UNKNOWN "org.freedesktop.DBus.Error.AdtAuditDataUnknown"
446 | /** There's already an object with the requested object path. */
447 | #define DBUS_ERROR_OBJECT_PATH_IN_USE "org.freedesktop.DBus.Error.ObjectPathInUse"
448 | /** The message meta data does not match the payload. e.g. expected
449 | number of file descriptors were not sent over the socket this message was received on. */
450 | #define DBUS_ERROR_INCONSISTENT_MESSAGE "org.freedesktop.DBus.Error.InconsistentMessage"
451 |
452 | /* XML introspection format */
453 |
454 | /** XML namespace of the introspection format version 1.0 */
455 | #define DBUS_INTROSPECT_1_0_XML_NAMESPACE "http://www.freedesktop.org/standards/dbus"
456 | /** XML public identifier of the introspection format version 1.0 */
457 | #define DBUS_INTROSPECT_1_0_XML_PUBLIC_IDENTIFIER "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
458 | /** XML system identifier of the introspection format version 1.0 */
459 | #define DBUS_INTROSPECT_1_0_XML_SYSTEM_IDENTIFIER "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"
460 | /** XML document type declaration of the introspection format version 1.0 */
461 | #define DBUS_INTROSPECT_1_0_XML_DOCTYPE_DECL_NODE "\n"
462 |
463 | /** @} */
464 |
465 | #ifdef __cplusplus
466 | #if 0
467 | { /* avoids confusing emacs indentation */
468 | #endif
469 | }
470 | #endif
471 |
472 | #endif /* DBUS_PROTOCOL_H */
473 |
--------------------------------------------------------------------------------
/include/dbus/dbus-connection.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2 | /* dbus-connection.h DBusConnection object
3 | *
4 | * Copyright (C) 2002, 2003 Red Hat Inc.
5 | *
6 | * Licensed under the Academic Free License version 2.1
7 | *
8 | * This program is free software; you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation; either version 2 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * This program is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with this program; if not, write to the Free Software
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 | *
22 | */
23 | #if !defined (DBUS_INSIDE_DBUS_H) && !defined (DBUS_COMPILATION)
24 | #error "Only can be included directly, this file may disappear or change contents."
25 | #endif
26 |
27 | #ifndef DBUS_CONNECTION_H
28 | #define DBUS_CONNECTION_H
29 |
30 | #include
31 | #include
32 | #include
33 | #include
34 |
35 | DBUS_BEGIN_DECLS
36 |
37 | /**
38 | * @addtogroup DBusConnection
39 | * @{
40 | */
41 |
42 | /* documented in dbus-watch.c */
43 | struct DBusWatch;
44 | typedef struct DBusWatch DBusWatch;
45 | /* documented in dbus-timeout.c */
46 | struct DBusTimeout;
47 | typedef struct DBusTimeout DBusTimeout;
48 | /** Opaque type representing preallocated resources so a message can be sent without further memory allocation. */
49 | struct DBusPreallocatedSend;
50 | typedef struct DBusPreallocatedSend DBusPreallocatedSend;
51 | /** Opaque type representing a method call that has not yet received a reply. */
52 | struct DBusPendingCall;
53 | typedef struct DBusPendingCall DBusPendingCall;
54 | /** Opaque type representing a connection to a remote application and associated incoming/outgoing message queues. */
55 | struct DBusConnection;
56 | typedef struct DBusConnection DBusConnection;
57 | /** Set of functions that must be implemented to handle messages sent to a particular object path. */
58 | typedef struct DBusObjectPathVTable DBusObjectPathVTable;
59 |
60 | /**
61 | * Indicates the status of a #DBusWatch.
62 | */
63 | typedef enum
64 | {
65 | DBUS_WATCH_READABLE = 1 << 0, /**< As in POLLIN */
66 | DBUS_WATCH_WRITABLE = 1 << 1, /**< As in POLLOUT */
67 | DBUS_WATCH_ERROR = 1 << 2, /**< As in POLLERR (can't watch for
68 | * this, but can be present in
69 | * current state passed to
70 | * dbus_watch_handle()).
71 | */
72 | DBUS_WATCH_HANGUP = 1 << 3 /**< As in POLLHUP (can't watch for
73 | * it, but can be present in current
74 | * state passed to
75 | * dbus_watch_handle()).
76 | */
77 | /* Internal to libdbus, there is also _DBUS_WATCH_NVAL in dbus-watch.h */
78 | } DBusWatchFlags;
79 |
80 | /**
81 | * Indicates the status of incoming data on a #DBusConnection. This determines whether
82 | * dbus_connection_dispatch() needs to be called.
83 | */
84 | typedef enum
85 | {
86 | DBUS_DISPATCH_DATA_REMAINS, /**< There is more data to potentially convert to messages. */
87 | DBUS_DISPATCH_COMPLETE, /**< All currently available data has been processed. */
88 | DBUS_DISPATCH_NEED_MEMORY /**< More memory is needed to continue. */
89 | } DBusDispatchStatus;
90 |
91 | /** Called when libdbus needs a new watch to be monitored by the main
92 | * loop. Returns #FALSE if it lacks enough memory to add the
93 | * watch. Set by dbus_connection_set_watch_functions() or
94 | * dbus_server_set_watch_functions().
95 | */
96 | typedef dbus_bool_t (* DBusAddWatchFunction) (DBusWatch *watch,
97 | void *data);
98 | /** Called when dbus_watch_get_enabled() may return a different value
99 | * than it did before. Set by dbus_connection_set_watch_functions()
100 | * or dbus_server_set_watch_functions().
101 | */
102 | typedef void (* DBusWatchToggledFunction) (DBusWatch *watch,
103 | void *data);
104 | /** Called when libdbus no longer needs a watch to be monitored by the
105 | * main loop. Set by dbus_connection_set_watch_functions() or
106 | * dbus_server_set_watch_functions().
107 | */
108 | typedef void (* DBusRemoveWatchFunction) (DBusWatch *watch,
109 | void *data);
110 | /** Called when libdbus needs a new timeout to be monitored by the main
111 | * loop. Returns #FALSE if it lacks enough memory to add the
112 | * watch. Set by dbus_connection_set_timeout_functions() or
113 | * dbus_server_set_timeout_functions().
114 | */
115 | typedef dbus_bool_t (* DBusAddTimeoutFunction) (DBusTimeout *timeout,
116 | void *data);
117 | /** Called when dbus_timeout_get_enabled() may return a different
118 | * value than it did before.
119 | * Set by dbus_connection_set_timeout_functions() or
120 | * dbus_server_set_timeout_functions().
121 | */
122 | typedef void (* DBusTimeoutToggledFunction) (DBusTimeout *timeout,
123 | void *data);
124 | /** Called when libdbus no longer needs a timeout to be monitored by the
125 | * main loop. Set by dbus_connection_set_timeout_functions() or
126 | * dbus_server_set_timeout_functions().
127 | */
128 | typedef void (* DBusRemoveTimeoutFunction) (DBusTimeout *timeout,
129 | void *data);
130 | /** Called when the return value of dbus_connection_get_dispatch_status()
131 | * may have changed. Set with dbus_connection_set_dispatch_status_function().
132 | */
133 | typedef void (* DBusDispatchStatusFunction) (DBusConnection *connection,
134 | DBusDispatchStatus new_status,
135 | void *data);
136 | /**
137 | * Called when the main loop's thread should be notified that there's now work
138 | * to do. Set with dbus_connection_set_wakeup_main_function().
139 | */
140 | typedef void (* DBusWakeupMainFunction) (void *data);
141 |
142 | /**
143 | * Called during authentication to check whether the given UNIX user
144 | * ID is allowed to connect, if the client tried to auth as a UNIX
145 | * user ID. Normally on Windows this would never happen. Set with
146 | * dbus_connection_set_unix_user_function().
147 | */
148 | typedef dbus_bool_t (* DBusAllowUnixUserFunction) (DBusConnection *connection,
149 | unsigned long uid,
150 | void *data);
151 |
152 | /**
153 | * Called during authentication to check whether the given Windows user
154 | * ID is allowed to connect, if the client tried to auth as a Windows
155 | * user ID. Normally on UNIX this would never happen. Set with
156 | * dbus_connection_set_windows_user_function().
157 | */
158 | typedef dbus_bool_t (* DBusAllowWindowsUserFunction) (DBusConnection *connection,
159 | const char *user_sid,
160 | void *data);
161 |
162 |
163 | /**
164 | * Called when a pending call now has a reply available. Set with
165 | * dbus_pending_call_set_notify().
166 | */
167 | typedef void (* DBusPendingCallNotifyFunction) (DBusPendingCall *pending,
168 | void *user_data);
169 |
170 | /**
171 | * Called when a message needs to be handled. The result indicates whether or
172 | * not more handlers should be run. Set with dbus_connection_add_filter().
173 | */
174 | typedef DBusHandlerResult (* DBusHandleMessageFunction) (DBusConnection *connection,
175 | DBusMessage *message,
176 | void *user_data);
177 | DBUS_EXPORT
178 | DBusConnection* dbus_connection_open (const char *address,
179 | DBusError *error);
180 | DBUS_EXPORT
181 | DBusConnection* dbus_connection_open_private (const char *address,
182 | DBusError *error);
183 | DBUS_EXPORT
184 | DBusConnection* dbus_connection_ref (DBusConnection *connection);
185 | DBUS_EXPORT
186 | void dbus_connection_unref (DBusConnection *connection);
187 | DBUS_EXPORT
188 | void dbus_connection_close (DBusConnection *connection);
189 | DBUS_EXPORT
190 | dbus_bool_t dbus_connection_get_is_connected (DBusConnection *connection);
191 | DBUS_EXPORT
192 | dbus_bool_t dbus_connection_get_is_authenticated (DBusConnection *connection);
193 | DBUS_EXPORT
194 | dbus_bool_t dbus_connection_get_is_anonymous (DBusConnection *connection);
195 | DBUS_EXPORT
196 | char* dbus_connection_get_server_id (DBusConnection *connection);
197 | DBUS_EXPORT
198 | dbus_bool_t dbus_connection_can_send_type (DBusConnection *connection,
199 | int type);
200 |
201 | DBUS_EXPORT
202 | void dbus_connection_set_exit_on_disconnect (DBusConnection *connection,
203 | dbus_bool_t exit_on_disconnect);
204 | DBUS_EXPORT
205 | void dbus_connection_flush (DBusConnection *connection);
206 | DBUS_EXPORT
207 | dbus_bool_t dbus_connection_read_write_dispatch (DBusConnection *connection,
208 | int timeout_milliseconds);
209 | DBUS_EXPORT
210 | dbus_bool_t dbus_connection_read_write (DBusConnection *connection,
211 | int timeout_milliseconds);
212 | DBUS_EXPORT
213 | DBusMessage* dbus_connection_borrow_message (DBusConnection *connection);
214 | DBUS_EXPORT
215 | void dbus_connection_return_message (DBusConnection *connection,
216 | DBusMessage *message);
217 | DBUS_EXPORT
218 | void dbus_connection_steal_borrowed_message (DBusConnection *connection,
219 | DBusMessage *message);
220 | DBUS_EXPORT
221 | DBusMessage* dbus_connection_pop_message (DBusConnection *connection);
222 | DBUS_EXPORT
223 | DBusDispatchStatus dbus_connection_get_dispatch_status (DBusConnection *connection);
224 | DBUS_EXPORT
225 | DBusDispatchStatus dbus_connection_dispatch (DBusConnection *connection);
226 | DBUS_EXPORT
227 | dbus_bool_t dbus_connection_has_messages_to_send (DBusConnection *connection);
228 | DBUS_EXPORT
229 | dbus_bool_t dbus_connection_send (DBusConnection *connection,
230 | DBusMessage *message,
231 | dbus_uint32_t *client_serial);
232 | DBUS_EXPORT
233 | dbus_bool_t dbus_connection_send_with_reply (DBusConnection *connection,
234 | DBusMessage *message,
235 | DBusPendingCall **pending_return,
236 | int timeout_milliseconds);
237 | DBUS_EXPORT
238 | DBusMessage * dbus_connection_send_with_reply_and_block (DBusConnection *connection,
239 | DBusMessage *message,
240 | int timeout_milliseconds,
241 | DBusError *error);
242 | DBUS_EXPORT
243 | dbus_bool_t dbus_connection_set_watch_functions (DBusConnection *connection,
244 | DBusAddWatchFunction add_function,
245 | DBusRemoveWatchFunction remove_function,
246 | DBusWatchToggledFunction toggled_function,
247 | void *data,
248 | DBusFreeFunction free_data_function);
249 | DBUS_EXPORT
250 | dbus_bool_t dbus_connection_set_timeout_functions (DBusConnection *connection,
251 | DBusAddTimeoutFunction add_function,
252 | DBusRemoveTimeoutFunction remove_function,
253 | DBusTimeoutToggledFunction toggled_function,
254 | void *data,
255 | DBusFreeFunction free_data_function);
256 | DBUS_EXPORT
257 | void dbus_connection_set_wakeup_main_function (DBusConnection *connection,
258 | DBusWakeupMainFunction wakeup_main_function,
259 | void *data,
260 | DBusFreeFunction free_data_function);
261 | DBUS_EXPORT
262 | void dbus_connection_set_dispatch_status_function (DBusConnection *connection,
263 | DBusDispatchStatusFunction function,
264 | void *data,
265 | DBusFreeFunction free_data_function);
266 | DBUS_EXPORT
267 | dbus_bool_t dbus_connection_get_unix_user (DBusConnection *connection,
268 | unsigned long *uid);
269 | DBUS_EXPORT
270 | dbus_bool_t dbus_connection_get_unix_process_id (DBusConnection *connection,
271 | unsigned long *pid);
272 | DBUS_EXPORT
273 | dbus_bool_t dbus_connection_get_adt_audit_session_data (DBusConnection *connection,
274 | void **data,
275 | dbus_int32_t *data_size);
276 | DBUS_EXPORT
277 | void dbus_connection_set_unix_user_function (DBusConnection *connection,
278 | DBusAllowUnixUserFunction function,
279 | void *data,
280 | DBusFreeFunction free_data_function);
281 | DBUS_EXPORT
282 | dbus_bool_t dbus_connection_get_windows_user (DBusConnection *connection,
283 | char **windows_sid_p);
284 | DBUS_EXPORT
285 | void dbus_connection_set_windows_user_function (DBusConnection *connection,
286 | DBusAllowWindowsUserFunction function,
287 | void *data,
288 | DBusFreeFunction free_data_function);
289 | DBUS_EXPORT
290 | void dbus_connection_set_allow_anonymous (DBusConnection *connection,
291 | dbus_bool_t value);
292 | DBUS_EXPORT
293 | void dbus_connection_set_route_peer_messages (DBusConnection *connection,
294 | dbus_bool_t value);
295 |
296 |
297 | /* Filters */
298 |
299 | DBUS_EXPORT
300 | dbus_bool_t dbus_connection_add_filter (DBusConnection *connection,
301 | DBusHandleMessageFunction function,
302 | void *user_data,
303 | DBusFreeFunction free_data_function);
304 | DBUS_EXPORT
305 | void dbus_connection_remove_filter (DBusConnection *connection,
306 | DBusHandleMessageFunction function,
307 | void *user_data);
308 |
309 |
310 | /* Other */
311 | DBUS_EXPORT
312 | dbus_bool_t dbus_connection_allocate_data_slot (dbus_int32_t *slot_p);
313 | DBUS_EXPORT
314 | void dbus_connection_free_data_slot (dbus_int32_t *slot_p);
315 | DBUS_EXPORT
316 | dbus_bool_t dbus_connection_set_data (DBusConnection *connection,
317 | dbus_int32_t slot,
318 | void *data,
319 | DBusFreeFunction free_data_func);
320 | DBUS_EXPORT
321 | void* dbus_connection_get_data (DBusConnection *connection,
322 | dbus_int32_t slot);
323 |
324 | DBUS_EXPORT
325 | void dbus_connection_set_change_sigpipe (dbus_bool_t will_modify_sigpipe);
326 |
327 | DBUS_EXPORT
328 | void dbus_connection_set_max_message_size (DBusConnection *connection,
329 | long size);
330 | DBUS_EXPORT
331 | long dbus_connection_get_max_message_size (DBusConnection *connection);
332 | DBUS_EXPORT
333 | void dbus_connection_set_max_received_size (DBusConnection *connection,
334 | long size);
335 | DBUS_EXPORT
336 | long dbus_connection_get_max_received_size (DBusConnection *connection);
337 |
338 | DBUS_EXPORT
339 | void dbus_connection_set_max_message_unix_fds (DBusConnection *connection,
340 | long n);
341 | DBUS_EXPORT
342 | long dbus_connection_get_max_message_unix_fds (DBusConnection *connection);
343 | DBUS_EXPORT
344 | void dbus_connection_set_max_received_unix_fds(DBusConnection *connection,
345 | long n);
346 | DBUS_EXPORT
347 | long dbus_connection_get_max_received_unix_fds(DBusConnection *connection);
348 |
349 | DBUS_EXPORT
350 | long dbus_connection_get_outgoing_size (DBusConnection *connection);
351 | DBUS_EXPORT
352 | long dbus_connection_get_outgoing_unix_fds (DBusConnection *connection);
353 |
354 | DBUS_EXPORT
355 | DBusPreallocatedSend* dbus_connection_preallocate_send (DBusConnection *connection);
356 | DBUS_EXPORT
357 | void dbus_connection_free_preallocated_send (DBusConnection *connection,
358 | DBusPreallocatedSend *preallocated);
359 | DBUS_EXPORT
360 | void dbus_connection_send_preallocated (DBusConnection *connection,
361 | DBusPreallocatedSend *preallocated,
362 | DBusMessage *message,
363 | dbus_uint32_t *client_serial);
364 |
365 |
366 | /* Object tree functionality */
367 |
368 | /**
369 | * Called when a #DBusObjectPathVTable is unregistered (or its connection is freed).
370 | * Found in #DBusObjectPathVTable.
371 | */
372 | typedef void (* DBusObjectPathUnregisterFunction) (DBusConnection *connection,
373 | void *user_data);
374 | /**
375 | * Called when a message is sent to a registered object path. Found in
376 | * #DBusObjectPathVTable which is registered with dbus_connection_register_object_path()
377 | * or dbus_connection_register_fallback().
378 | */
379 | typedef DBusHandlerResult (* DBusObjectPathMessageFunction) (DBusConnection *connection,
380 | DBusMessage *message,
381 | void *user_data);
382 |
383 | /**
384 | * Virtual table that must be implemented to handle a portion of the
385 | * object path hierarchy. Attach the vtable to a particular path using
386 | * dbus_connection_register_object_path() or
387 | * dbus_connection_register_fallback().
388 | */
389 | struct DBusObjectPathVTable
390 | {
391 | DBusObjectPathUnregisterFunction unregister_function; /**< Function to unregister this handler */
392 | DBusObjectPathMessageFunction message_function; /**< Function to handle messages */
393 |
394 | void (* dbus_internal_pad1) (void *); /**< Reserved for future expansion */
395 | void (* dbus_internal_pad2) (void *); /**< Reserved for future expansion */
396 | void (* dbus_internal_pad3) (void *); /**< Reserved for future expansion */
397 | void (* dbus_internal_pad4) (void *); /**< Reserved for future expansion */
398 | };
399 |
400 | DBUS_EXPORT
401 | dbus_bool_t dbus_connection_try_register_object_path (DBusConnection *connection,
402 | const char *path,
403 | const DBusObjectPathVTable *vtable,
404 | void *user_data,
405 | DBusError *error);
406 |
407 | DBUS_EXPORT
408 | dbus_bool_t dbus_connection_register_object_path (DBusConnection *connection,
409 | const char *path,
410 | const DBusObjectPathVTable *vtable,
411 | void *user_data);
412 |
413 | DBUS_EXPORT
414 | dbus_bool_t dbus_connection_try_register_fallback (DBusConnection *connection,
415 | const char *path,
416 | const DBusObjectPathVTable *vtable,
417 | void *user_data,
418 | DBusError *error);
419 |
420 | DBUS_EXPORT
421 | dbus_bool_t dbus_connection_register_fallback (DBusConnection *connection,
422 | const char *path,
423 | const DBusObjectPathVTable *vtable,
424 | void *user_data);
425 | DBUS_EXPORT
426 | dbus_bool_t dbus_connection_unregister_object_path (DBusConnection *connection,
427 | const char *path);
428 |
429 | DBUS_EXPORT
430 | dbus_bool_t dbus_connection_get_object_path_data (DBusConnection *connection,
431 | const char *path,
432 | void **data_p);
433 |
434 | DBUS_EXPORT
435 | dbus_bool_t dbus_connection_list_registered (DBusConnection *connection,
436 | const char *parent_path,
437 | char ***child_entries);
438 |
439 | DBUS_EXPORT
440 | dbus_bool_t dbus_connection_get_unix_fd (DBusConnection *connection,
441 | int *fd);
442 | DBUS_EXPORT
443 | dbus_bool_t dbus_connection_get_socket (DBusConnection *connection,
444 | int *fd);
445 |
446 | /** @} */
447 |
448 |
449 | /**
450 | * @addtogroup DBusWatch
451 | * @{
452 | */
453 |
454 | #ifndef DBUS_DISABLE_DEPRECATED
455 | DBUS_EXPORT
456 | DBUS_DEPRECATED int dbus_watch_get_fd (DBusWatch *watch);
457 | #endif
458 |
459 | DBUS_EXPORT
460 | int dbus_watch_get_unix_fd (DBusWatch *watch);
461 | DBUS_EXPORT
462 | int dbus_watch_get_socket (DBusWatch *watch);
463 | DBUS_EXPORT
464 | unsigned int dbus_watch_get_flags (DBusWatch *watch);
465 | DBUS_EXPORT
466 | void* dbus_watch_get_data (DBusWatch *watch);
467 | DBUS_EXPORT
468 | void dbus_watch_set_data (DBusWatch *watch,
469 | void *data,
470 | DBusFreeFunction free_data_function);
471 | DBUS_EXPORT
472 | dbus_bool_t dbus_watch_handle (DBusWatch *watch,
473 | unsigned int flags);
474 | DBUS_EXPORT
475 | dbus_bool_t dbus_watch_get_enabled (DBusWatch *watch);
476 |
477 | /** @} */
478 |
479 | /**
480 | * @addtogroup DBusTimeout
481 | * @{
482 | */
483 |
484 | DBUS_EXPORT
485 | int dbus_timeout_get_interval (DBusTimeout *timeout);
486 | DBUS_EXPORT
487 | void* dbus_timeout_get_data (DBusTimeout *timeout);
488 | DBUS_EXPORT
489 | void dbus_timeout_set_data (DBusTimeout *timeout,
490 | void *data,
491 | DBusFreeFunction free_data_function);
492 | DBUS_EXPORT
493 | dbus_bool_t dbus_timeout_handle (DBusTimeout *timeout);
494 | DBUS_EXPORT
495 | dbus_bool_t dbus_timeout_get_enabled (DBusTimeout *timeout);
496 |
497 | /** @} */
498 |
499 | DBUS_END_DECLS
500 |
501 | #endif /* DBUS_CONNECTION_H */
502 |
--------------------------------------------------------------------------------