diff options
author | Alexander Orlenko <zxteam@gmail.com> | 2010-08-09 16:01:57 +1100 |
---|---|---|
committer | Alexander Orlenko <zxteam@gmail.com> | 2010-08-09 16:01:57 +1100 |
commit | 2ebd9e865dcb3fd0e5c0007c25636ee754d4813a (patch) | |
tree | 513aeb9cf933fb89bef286929c16d328dcaadb70 | |
parent | da8f4e34ae3c1bbff5d46a8a44cf42c6f12c3221 (diff) | |
download | bluez-tools-2ebd9e865dcb3fd0e5c0007c25636ee754d4813a.tar.gz |
Refactoring of code
Removed ODS API
Some impl of bt-obex
53 files changed, 766 insertions, 3965 deletions
diff --git a/TODO.txt b/TODO.txt deleted file mode 100644 index 766cdf3..0000000 --- a/TODO.txt +++ /dev/null @@ -1,4 +0,0 @@ -Interfaces: -- How to use RequestSession() && ReleaseSession() in org.bluez.Adapter intf ? - -bt-monitor: diff --git a/contrib/gen-dbus-gobject.pl b/contrib/gen-dbus-gobject.pl index ae66cf5..fa86326 100755 --- a/contrib/gen-dbus-gobject.pl +++ b/contrib/gen-dbus-gobject.pl @@ -327,8 +327,8 @@ sub generate_source { #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -433,6 +433,9 @@ static void {\$object}_init({\$Object} *self) { self->priv = {\$OBJECT}_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + {IF_ASYNC_CALLS} /* Async calls init */ {PRIV_ASYNC_CALLS_INIT} diff --git a/contrib/generate-bluez-gobjects.sh b/contrib/generate-bluez-gobjects.sh index dcd86ad..f133699 100755 --- a/contrib/generate-bluez-gobjects.sh +++ b/contrib/generate-bluez-gobjects.sh @@ -34,4 +34,3 @@ API_VERSION=4.69 # serial-api.txt ./gen-dbus-gobject.pl -header bluez-api-${API_VERSION}-fixed/serial-api.txt > ../src/lib/bluez/serial.h ./gen-dbus-gobject.pl -source bluez-api-${API_VERSION}-fixed/serial-api.txt > ../src/lib/bluez/serial.c - diff --git a/contrib/generate-obexd-gobjects.sh b/contrib/generate-obexd-gobjects.sh index 3ef3f50..7310094 100755 --- a/contrib/generate-obexd-gobjects.sh +++ b/contrib/generate-obexd-gobjects.sh @@ -26,4 +26,3 @@ API_VERSION=0.30 ./gen-dbus-gobject.pl -header obexd-api-${API_VERSION}-fixed/obexd-api.txt 3 > ../src/lib/obexd/obexsession.h ./gen-dbus-gobject.pl -source obexd-api-${API_VERSION}-fixed/obexd-api.txt 3 > ../src/lib/obexd/obexsession.c - diff --git a/contrib/generate-ods-gobjects.sh b/contrib/generate-ods-gobjects.sh deleted file mode 100755 index 28c6d3b..0000000 --- a/contrib/generate-ods-gobjects.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -# ODS (obex-data-server) API - -API_VERSION=0.4.5 - -./gen-dbus-gobject.pl -header ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt > ../src/lib/ods/obexmanager.h -./gen-dbus-gobject.pl -source ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt > ../src/lib/ods/obexmanager.c - -./gen-dbus-gobject.pl -header ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt 2 > ../src/lib/ods/obexserver.h -./gen-dbus-gobject.pl -source ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt 2 > ../src/lib/ods/obexserver.c - -./gen-dbus-gobject.pl -header ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt 3 > ../src/lib/ods/obexsession.h -./gen-dbus-gobject.pl -source ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt 3 > ../src/lib/ods/obexsession.c - -./gen-dbus-gobject.pl -header ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt 4 > ../src/lib/ods/obexserver_session.h -./gen-dbus-gobject.pl -source ods-api-${API_VERSION}-fixed/obex-data-server-api-${API_VERSION}-fixed.txt 4 > ../src/lib/ods/obexserver_session.c - diff --git a/contrib/obexd-api-0.30-fixed/agent.xml b/contrib/obexd-api-0.30-fixed/agent.xml new file mode 100644 index 0000000..bb089dd --- /dev/null +++ b/contrib/obexd-api-0.30-fixed/agent.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="UTF-8"?> +<node name="/ObexAgent"> + <interface name="org.openobex.Agent"> + <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="obexagent"/> + + <method name="Authorize"> + <arg type="o" name="transfer" direction="in"/> + <arg type="s" name="bt_address" direction="in"/> + <arg type="s" name="name" direction="in"/> + <arg type="s" name="type" direction="in"/> + <arg type="i" name="length" direction="in"/> + <arg type="i" name="time" direction="in"/> + <arg type="s" direction="out"/> + </method> + <method name="Cancel"/> + + <method name="Release"/> + <method name="Request"> + <arg type="o" name="transfer" direction="in"/> + <arg type="s" direction="out"/> + </method> + <method name="Progress"> + <arg type="o" name="transfer" direction="in"/> + <arg type="t" name="transferred" direction="in"/> + </method> + <method name="Complete"> + <arg type="o" name="transfer" direction="in"/> + </method> + <method name="Error"> + <arg type="o" name="transfer" direction="in"/> + <arg type="s" name="message" direction="in"/> + </method> + + </interface> +</node> diff --git a/contrib/ods-api-0.4.5-fixed/obex-data-server-api-0.4.5-fixed.txt b/contrib/ods-api-0.4.5-fixed/obex-data-server-api-0.4.5-fixed.txt deleted file mode 100644 index 9555770..0000000 --- a/contrib/ods-api-0.4.5-fixed/obex-data-server-api-0.4.5-fixed.txt +++ /dev/null @@ -1,858 +0,0 @@ -ODS API description -******************** - -Manager hierarchy -=============================== - -Service org.openobex -Interface org.openobex.Manager -Object path /org/openobex -Object name OBEXManager - -Methods object CreateBluetoothSession(string target_address, string source_address, string pattern) - - Creates a Bluetooth OBEX session and returns the new session object - of type org.openobex.Session. Session is automatically connected. - The target_address represents the remote Bluetooth device, - source_address specifies which Bluetooth adapter to use - (to use default adapter, use "00:00:00:00:00:00") and - the pattern specifies the OBEX service it connects to, - or the OBEX service using a fixed Bluetooth channel. - Pattern can be a UUID-128 identifying the service or - place holder as "opp" (for Object Push) or "ftp" (for FTP). - In case you want to use a fixed channel, UUID has to be - like: UUID:CHANNEL where UUID is a valid UUID or service - place holder like before, and CHANNEL is an integer - representing a valid RFCOMM channel. Session object can - only be used when SessionConnected signal is emitted. - If connection fails (remote device refuses connection, link dies, etc.), - SessionConnectError signal is emitted instead. To cancel - connecting use CancelSessionConnect method. - - Returns object path for the created session. - - Possible errors: org.openobex.Error.InvalidArguments - org.openobex.Error.TransportNotAvailable - - object CreateBluetoothImagingSession(string target_address, string source_addres, string bip_feature) {skiped} - - Create Bluetooth OBEX session using BIP profile and returns new - session object of type org.openobex.Session. target_address - represents the remote Bluetooth device, source_address specifies - which Bluetooth adapter to use ("00:00:00:00:00:00" for default - adapter). bip_feature specifies imaging feature to use - ("imagepush" or "remotedisplay"). In case you want to use a fixed - RFCOMM channel, bip_feature has to be like FEATURE:CHANNEL where - CHANNEL is an integer representing a valid RFCOMM channel. Session - object can only be used when SessionConnected signal is emitted. - If connection fails, SessionConnectError signal is emitted instead. - To cancel connecting use CancelSessionConnect method. - - Returns object path for the created session. - - Possible errors: org.openobex.Error.InvalidArguments - org.openobex.Error.TransportNotAvailable - - object CreateUsbSession(integer interface_number, string profile) {skipped} - - Creates a USB OBEX session and returns the new session object - of type org.openobex.Session. Session is automatically connected. - To find out about available USB OBEX interfaces, use GetUsbInterfacesNum - and GetUsbInterfaceInfo. profile specifies profile to be used for - session (FTP profile is commonly used for USB OBEX sessions). - Session object can only be used when SessionConnected signal is emitted. - If connection fails (remote device refuses connection, link dies, etc.), - SessionConnectError signal is emitted instead. - Do not use CancelSessionConnect with USB sessions (connection is - established instantly). - - Returns object path for the created session. - - Possible errors: org.openobex.Error.InvalidArguments - org.openobex.Error.TransportNotAvailable - - object CreateTtySession(string tty_dev, string profile) {skipped} - - Creates OBEX session using TTY device and returns the new session - object of type org.openobex.Session. Session is automatically - connected. - tty_dev specifies TTY device node. - pattern specifies the profile to be used for session which may be - either "ftp" for OBEX FTP server, "opp" for OBEX Object Push server - or "bip" for OBEX Basic Imaging server. - Session object can only be used when SessionConnected signal is emitted. - If connection fails (remote device refuses connection, link dies, etc.), - SessionConnectError signal is emitted instead. - Do not use CancelSessionConnect with TTY sessions (connection is - established instantly). - - Returns object path for the created session. - - Possible errors: org.openobex.Error.InvalidArguments - - integer GetUsbInterfacesNum() {skipped} - - Returns the number of available USB OBEX interfaces - - Possible errors: none - - dict{s,s} GetUsbInterfaceInfo(integer interface_number) {skipped} - - Returns info about specified USB OBEX interface: - "Manufacturer" : Manufacturer of the device - "Product" : Product name of the device - "Serial" : Serial number of the device - "Configuration" : USB configuration that this interface belongs to - "ControlInterface" : description of the OBEX control interface, typically - reveals the functionality of the interface - "DataInterfaceIdle" : description of the OBEX data idle interface, typically empty - "DataInterfaceActive" : description of the OBEX data active interface, typically empty - - If specified interface number is too large, returns empty structure. - - Possible errors: none - - boolean CancelSessionConnect(object session_object) - - Cancells session connection. If Session is being connected, - connection will be cancelled and SessionConnectError signal - with org.openobex.Cancelled error will be emitted. If session - is already connected or invalid session is supplied, this function - will do nothing and FALSE will be returned. - - Returns TRUE if cancelled successfully, FALSE otherwise. - - Possible errors: none - - object CreateBluetoothServer(string source_address, string pattern, boolean require_pairing) - - Gets Server object for specified bluetooth source address. - source_address can be Bluetooth address of any adapter or just - "00:00:00:00:00:00" for default adapter. - pattern specifies the type of server to create which may be - either "ftp" for OBEX FTP server, "opp" for OBEX Object Push server - or "bip" for OBEX Basic Imaging server. - require_pairing specifies whether client device should be paired - before allowing any operations (recommended values: True for FTP, - False for OPP). - - Returns object path for the created server. - - Possible errors: org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.TransportNotAvailable - - object CreateTtyServer(string tty_dev, string pattern) {skipped} - - Gets Server object for specified TTY device (e.g. /dev/ttyUSB0). - This kind of server can be used on embedded devices to serve files via USB OBEX. - tty_dev specifies TTY device node. - pattern specifies the type of server which may be - either "ftp" for OBEX FTP server, "opp" for OBEX Object Push server - or "bip" for OBEX Basic Imaging server. - - Return object path for the created server. - - Possible errors: org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - - dict{s,s} GetSessionInfo(object session_object) - - Returns info about specified session: - "BluetoothTargetAddress" : Target device Bluetooth address (only for Bluetooth sessions); - "BluetoothSourceAddress" : Source Bluetooth address (hci device used) (only for Bluetooth sessions); - "BluetoothChannel" : RFCOMM channel used for session (only for Bluetooth sessions); - "UsbInterfaceNumber" : USB interface number (only for USB sessions); - "TTYDevice" : TTY device which is used (only for TTY sessions); - If specified session does not exist, returns empty structure. - session_object specifies DBus path of Session object. - - Possible errors: none - - dict{s,s} GetServerInfo(object server_object) - - Returns info about specified server: - "BluetoothSourceAddress" : Bluetooth source address (only for Bluetooth servers); - "RequirePairing" : if connecting to server triggers pairing (only for Bluetooth servers); - "TTYDevice" : TTY device which is used (only for TTY servers); - If specified session does not exist, returns empty structure. - server_object specifies DBus path of Server object. - - Possible errors: none - - array{string} GetSessionList() - - Returns list of open sessions. Array contains DBus paths of sessions. - - Possible errors: none - - array{string} GetServerList() - - Returns list of open servers. Array contains DBus paths of servers. - - Possible errors: none - - string GetVersion() - - Returns obex-data-server version and obex-data-server API version. - Returned string is formated like that: "<ods_ver>:<ods_api_ver>". - API version is an integer. When API incompatible with older one is - released, this number is increased by one. As of ods version 0.4 - API version is 1. Example of returned string: "0.4:1". - - Possible errors: none - -Signals SessionConnected(object path) - - Emitted when Session is connected to target device. - - SessionConnectError(object path, string error_name, string error_message) - - Emitted when Session connection fails. Session object must not be - used after that. - - SessionClosed(object path) - - Emitted when Session is closed and no longer valid. - -Server hierarchy -=============================== - -Service org.openobex -Interface org.openobex.Server -Object path /org/openobex/server{0,1,2...} -Object name OBEXServer - -Methods void Start(string path, boolean allow_write, boolean auto_accept) - - Starts OBEX Object Push / FTP server (begins - listening for connections). Started signal is emitted after - the server is started. If error occurs, ErrorOccurred signal is emitted - instead. Once the server is started, it emits SessionCreated signal - for every newly connected client. - - If this is Object Push server, path defines where all received files - will be saved. In case of FTP server path is the top-level folder which - will be served. allow_write specifies whether write operations - will be allowed (put and delete). In most cases, allow_write should be - set to True. - auto_accept specifies whether incoming files should be always accepted - (recommended values: True for FTP, False for OPP). If auto_accept is - set to False, either Accept() or Reject() has to be called - every time after you receive TransferStarted signal in ServerSession - object. If Accept() or Reject() is not called in 15 seconds after - TransferStarted signal, timeout will happen and the incoming file will - be automatically rejected. It is important to listen for Cancelled - signal on ServerSession object when auto_accept is False because - you can receive Cancelled signal while waiting for user to accept or - reject incoming file. This would effectively mean that timeout happened - and the incoming file was rejected. - - Possible errors: org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.Started - - void Stop() - - Stops the server. All client connections will be closed and - operations will be cancelled. Stopped signal is emitted - after the server is stopped. - - Possible errors: org.openobex.Error.NotAuthorized - org.openobex.Error.NotStarted - - void Close() - - Closes the server. If server is not stopped, all client connections - will be closed, operations will be cancelled. Server object will - be destroyed after that. Closed signal is emitted immediately - when this method is invoked. - - Possible errors: org.openobex.Error.NotAuthorized - - boolean IsStarted() - - Returns true if server is started, false otherwise. - - Possible errors: none - - void SetOption(string name, variant value) - - Sets server options. Supported options: - "Limit" : maximum server sessions that server will accept - (0 for no limit). Default is 0. Value type is uint16. - "RequireImagingThumbnails" : whether to require clients to send - thumbnails for uploaded images (specific to BIP servers). - Default is False. Value type is boolean. - - Possible errors: org.openobex.Error.InvalidArguments - - dict{s,s} GetServerSessionInfo(object session_object) - - Returns info about specified server session: - "BluetoothAddress" : Client device Bluetooth address; - If specified server session does not exist, returns empty structure. - session_object specifies DBus path of ServerSession object. - - Possible errors: none - - array{string} GetServerSessionList() - - Returns list of open server sessions. Array contains DBus paths - of server sessions. - - Possible errors: none - -Signals Started() - - This signal informs that the server was started. - - Stopped() - - This signal informs that the server was stopped and all operations - were ceased. - - Closed() - - This signal informs that the server was closed and it's object is - no longer valid. - - ErrorOccurred(string error_name, string error_message) - - This signal informs that error occurred while starting or stopping - the server. - - SessionCreated(object session_object) - - Signal informs that client connected to server and new ServerSession - object was created. Returns path of ServerSession object. - - SessionRemoved(object session_object) - - Signal informs that client disconnected from server. Returns - path of ServerSession object that was closed. - -Session hierarchy -=============================== - -Service org.openobex -Interface org.openobex.Session -Object path /org/openobex/session{0,1,2...} -Object name OBEXSession - -Methods void Disconnect() - - Disconnects from remote device by sending OBEX disconnect command. - Disconnected signal is emitted once disconnected. Normally, - "Close" should be called immediately after Session is disconnected. - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.NotAuthorized - org.openobex.Error.OutOfMemory - - void Close() - - Closes the session (the actual connection to remote device is closed). - Session object is finalized and can not be used anymore. - Closed signal is emitted once closed. - - Possible errors: org.openobex.Error.Failed - org.openobex.Error.NotAuthorized - - void ChangeCurrentFolder(string path) - - Changes current path on a remote device to the specified one. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.OutOfMemory - - void ChangeCurrentFolderBackward() - - Changes current path on a remote device one level up. If current - folder is root, path is not changed. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.OutOfMemory - - void ChangeCurrentFolderToRoot() - - Changes current path on a remote device to root. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.OutOfMemory - - string GetCurrentPath() - - Returns current path on a remote device. - - Possible errors: none - - void CopyRemoteFile(string remote_filename, string local_path) - - Starts receiving a specified file from a remote device. - remote_filename specifies the file to receive on a remote device. - local_path is the path where received file will be saved. - TransferStarted signal is emitted when transfer starts. If error - occurs during operation, ErrorOccurred signal is emitted instead. - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.NotFound - org.openobex.Error.OutOfMemory - - void CopyRemoteFileByType(string type, string local_path) - - Starts receiving default object of specified type from a remote - device. type specifies OBEX type to receive. local_path is the path - where received file will be saved. TransferStarted signal is emitted - when transfer starts. If error occurs during operation, - ErrorOccurred signal is emitted instead. - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.NotFound - org.openobex.Error.OutOfMemory - - void CreateFolder(string folder_name) - - Creates a folder on a remote device with a specified - name. This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Busy - org.openobex.Error.Failed - org.openobex.Error.InvalidArguments - org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.OutOfMemory - - string RetrieveFolderListing() - - Retrieves the list of files in the current folder. - The list is XML formatted string. See OBEX specification for - info about the format. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: none? - - string GetCapability() - - Retrieves the FTP capability object. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: none? - - void SendFile(string local_path) - - Starts sending a specified file to a remote device. - local_path specifies the path to file that will be sent. - TransferStarted signal is emitted when transfer starts. If error - occurs during operation, ErrorOccurred signal is emitted. - - Possible errors: org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.Busy - org.openobex.Error.InvalidArguments - org.openobex.Error.OutOfMemory - org.openobex.Error.NotFound - !! org.openobex.Error.Failed - - void SendFileExt(string local_path, string remote_filename, string type) - - Starts sending a specified file to a remote device. It's possible - to specify different filename (remote_filename) than that of local - file. When remote_filename is empty, original filename is used. - type specifies particular OBEX type to send file as. type can be - empty. When type is used, remote_filename must be empty. - TransferStarted signal is emitted when transfer starts. If error - occurs during operation, ErrorOccurred signal is emitted. - - Possible errors: org.openobex.Error.NotAuthorized - org.openobex.Error.NotConnected - org.openobex.Error.Busy - org.openobex.Error.InvalidArguments - org.openobex.Error.OutOfMemory - org.openobex.Error.NotFound - !! org.openobex.Error.Failed - - void DeleteRemoteFile(string remote_filename) - - Deletes specified file on remote device. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Failed - - void RemoteCopy(string remote_source, string remote_destination) - - FTP profile - - Initiates remote copy operation (data is copied from one location - to the other in remote device). remote_source specifies a file - or folder to be copied (this file or folder has to exist in current - directory). remote_destination specifies path where to copy data. - This path can be relative to current folder or relative to root - folder. Both slash ('/') and backslash ('\') symbols can be used in - path. Example source/destination pairs : - 'File.txt' : 'Folder/OtherFolder/NewFile.txt' - 'Folder' : '/Folder/OtherFolder/NewFolder' (relative to root folder) - 'Folder' : 'Folder\NewFolder' - Note that ods does not check remote_destination argument validity. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - ! This method is not included in official FTP profile specification, - therefore not many devices support it. - - Possible errors: none? - - void RemoteMove(string remote_source, string remote_destination) - - FTP profile - - Initiates remote move operation (data is moved from one location - to the other in remote device). See RemoteCopy method for how the - arguments should be used. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - ! This method is not included in official FTP profile specification, - therefore not many devices support it. - - Possible errors: none? - - string GetImagingCapabilities() {skipped} - - BIP profile, all features - - Retrieves imaging capabilities object ("x-bt/img-capabilities"). - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: none? - - void GetImageInfo(string local_path, out uint16 width, out uint16 height, out string encoding) {skipped} - - BIP profile utility function - - Returns image info for specified locally stored image. Returns - width, height and encoding. Can be used to determine how image - should be resized to match remote device preferred image format - specified in imaging capabilities object. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.InvalidArguments - org.openobex.Error.NotSupported - org.openobex.Error.Failed - - void PutImage(string local_path) {skipped} - - BIP profile, ImagePush and RemoteDisplay features - - Pushes image to remote device. local_path specifies image filename. - TransferStarted signal is emitted when transfer starts. If error - occurs during operation, ErrorOccurred signal is emitted. When - transfer finishes successfully, ImageHandleReceived signal is - emitted (ImageHandleReceived signal returns image handle for pushed - image to be used in further operations). - - Possible errors: none? - - void PutImageResized(string local_path, uint16 width, uint16 height, string encoding, string transformation) {skipped} - - BIP profile, ImagePush and RemoteDisplay features - - Pushes resized/encoded image to remote device. Client application - should parse ImagingCapabilities object prior to this to acquire - image formats supported by remote device. local_path specifies - original image filename. width and height specify new dimensions. - encoding specifies image format ("JPEG", "PNG", etc.). If encoding - is empty, original encoding will be preserved. See ImageMagick - supported formats list for available values. transformation - defines how image should be resized. Possible transformations are - "stretch" (stretches image to new dimensions), "crop" (crops image) - or "fill" (in case dimensions are bigger than original, image is filled - with white backround). If specified dimensions match the original - dimensions, no resizing will be done. If invalid transformation value - is used, "stretch" will be used by default. - TransferStarted signal is emitted when transfer starts. If error - occurs during operation, ErrorOccurred signal is emitted. When - transfer finishes successfully, ImageHandleReceived signal is - emitted (ImageHandleReceived signal returns image handle for pushed - image to be used in further operations). - - Possible errors: none? - - void PutLinkedAttachment(string image_handle, string local_path, string content_type, string charset) {skipped} - - BIP profile, ImagePush feature - - Pushes attachment linked to previously pushed image. image_handle - specifies handle of previously pushed image, local_path is path - to file to be sent. content_type specifies attachment's MIME - content type, e.g. "text/plain". content_type is optional and can - be empty. charset specifies charset in which attachment is encoded. - charset is also optional and can be empty. Progress of transfer - is reported using TransferStarted, TransferProgress, ErrorOccurred - and TransferCompleted signals. - - Possible errors: none? - - void RemoteDisplaySelectImage(string image_handle) {skipped} - - BIP profile, RemoteDisplay feature - - Selects previously pushed image (using PutImage or PutImageResized - methods). image_handle specifies image handle corresponding to - previously pushed image (returned by ImageHandleReceived signal). - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Failed - - void RemoteDisplayShowCurrentImage() {skipped} - - BIP profile, RemoteDisplay feature - - Triggers remote device to show currently selected image. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Failed - - void RemoteDisplayShowNextImage() {skipped} - - BIP profile, RemoteDisplay feature - - Triggers remote device to show next image. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Failed - - void RemoteDisplayShowPreviousImage() {skipped} - - BIP profile, RemoteDisplay feature - - Triggers remote device to show previous image. - This method only returns after operation is finished. - This means that if method returned without any error, - operation is complete (this is in contrast with how file - transfers work). - - Possible errors: org.openobex.Error.Failed - - dict{s,s} GetTransferInfo() - - Returns info about the ongoing transfer: - "LocalPath" : full local path; - "RemoteFilename" : filename; - "Size" : total bytes being transferred; - "Time" : last modification time of file being sent; - "OBEXCommand" : either "GET" or "PUT"; - - Possible errors: none - - boolean IsBusy() - - Returns true if there is an operation in progress, false otherwise. - - Possible errors: none - - void Cancel() - - Cancels any operation that is in progress. - - Possible errors: org.openobex.Error.Failed - -Signals Cancelled() - - This signal informs that the current transfer was cancelled either by - client or by server. - - Disconnected() - - This signal informs that the session was disconnected. - - Closed() - - This signal informs that the session was terminated and that it's object - is no longer valid. - - TransferStarted(string filename, string local_path, uint64 total_bytes) - - This signal informs that transfer was started. - - total_bytes is the number of total bytes that are being sent (0 - if total bytes are unknown). filename specifies the filename (without - path) of file being sent or null if it is unknown. local_path specifies - where the file is stored locally. - - TransferProgress(uint64 bytes_transferred) - - This signal is emitted constantly during the transfer. - bytes_transferred specifies how many bytes were already transferred. - - TransferCompleted() - - This signal informs that transfer was completed. - - ErrorOccurred(string error_name, string error_message) - - This signal informs that error occurred while performing some operation. - - ImageHandleReceived(string image_handle, boolean thumbnail_requested) {skipped} - - This signal returns image handle for pushed image (using PutImage or - PutImageResized). thumbnail_requested specifies whether Imaging - Responder requested client to send thumbnail. If thumbnail was - requested, TransferStarted/TransferProgress/TransferCompleted - signals will be emitted when transferring thumbnail. - -ServerSession hierarchy -=============================== - -Service org.openobex -Interface org.openobex.ServerSession -Object path /org/openobex/serversession{0,1,2...} -Object name OBEXServerSession - -Methods void Accept() - - Accepts incoming file (use this when auto_accept is set to False for - corresponding Server object). If auto_accept is True, this function will - do nothing. Call this method just after receiving TransferStarted signal. - If there is no transfer in progress or if current transfer is not - an incoming transfer, error will be returned. If you do not call - Accept() or Reject() in 15 seconds after TransferStarted signal, - incoming file will be automatically rejected and you will receive - Cancelled signal. - - Possible errors: org.openobex.Error.Failed - - void Reject() - - Rejects incoming file (use this when auto_accept is set to False for - corresponding Server object). If auto_accept is True, this function will - do nothing. Call this method just after receiving TransferStarted signal. - If there is no transfer in progress or if current transfer is not - an incoming transfer, error will be returned. If you do not call - Accept() or Reject() in 15 seconds after TransferStarted signal, - incoming file will be automatically rejected and you will receive - Cancelled signal. - - Possible errors: org.openobex.Error.Failed - - void Disconnect() - - Disconnects from remote device. - ServerSession object is finalized and can not be used anymore. - Disconnected signal is emitted once disconnected. - - Possible errors: none? - - dict{s,s} GetTransferInfo() - - Returns all info about the ongoing transfer (filename, local path, - total bytes). - - Possible errors: none - - void Cancel() - - Cancels any operation that is in progress. - - Possible errors: org.openobex.Error.Failed - -Signals Cancelled() - - This signal informs that the current transfer was cancelled either by - client or by server. - - Disconnected() - - This signal informs that the ServerSession was disconnected. - ServerSession object is finalized and can not be used anymore. - - TransferStarted(string filename, string local_path, uint64 total_bytes) - - This signal informs that transfer was started. - - total_bytes is the number of total bytes that are being sent (0 - if total bytes are unknown). filename specifies the filename (without - path) of file being sent or null if it is unknown. local_path specifies - where the file is stored locally. - - TransferProgress(uint64 bytes_transferred) - - This signal is emitted constantly during the transfer. - bytes_transferred specifies how many bytes were already transferred. - - TransferCompleted() - - This signal informs that transfer was completed. - - ErrorOccurred(string error_name, string error_message) - - This signal informs that error occurred while performing some operation. - - RemoteDisplayRequested(string filename) {skipped} - - This signal is used for Imaging sessions that use Remote Display - feature. Signal informs that remote device requested display of - previously uploaded image. filename specifies the filename of image - to be displayed. diff --git a/doc/bluez-tools.txt b/doc/bluez-tools.txt deleted file mode 100644 index 37179a8..0000000 --- a/doc/bluez-tools.txt +++ /dev/null @@ -1,177 +0,0 @@ -blueZ-tools: -A set of tools to manage bluetooth devices and services. - -1) blueZ-agent (btagent/btagentlib) -Bluetooth agent/lib, that implements org.bluez.Agent/org.openobex.Agent interfaces; -Tasks: - - request pincode/passkey for an authentication from user (bluetooth v2.0) - - display passkey to user (bluetooth v2.1) - - request confirmation from user, that a passkey for an authentication is valid (bluetooth v2.1) - - authorize a connection/service request - - cancel request if request failed/reply was not returned - - confirm mode change of adapter - - register/unregister self for an selected adapter - OBEX: - - accept/reject a bluetooth object push request - -btagent is an external tool, that manage incoming? connections. -command line arguments: -./btagent [help|--help|-h] [adapter#id] - adapter#id - register agent for an given adapter - help - show help and exit - -If no adapter#id is given, than agent register self to a default adapter; -Agentlib is used as embedded agent to manage outgoing? connections; - -2) blueZ-monitor (btmon) -Bluetooth monitor, that displays some events (ie signals); -Tasks: - Adaper signals: - - adapter added/removed (GLOBAL) - - default adapter changed (GLOBAL) - - adapter property changed - Device(remote) signals: - - device added/removed (ie created/removed) - - device property changed - - disconnection to a remote device has been requested - - node created/removed (TODO) - Input service signals: - - input device connected/disconnected - Network service signals: - - network device connected/disconnected (also displays interface name) - Audio service signals (generic, org.bluez.Audio interface): - - audio device connected/disconnected/connection state changed - Others: - - AVRCP service monitoring? (TODO) - OBEX: - - FTP OBEX connection has been accepted/disconnected - - object push operation starts - - object has been received - -command line arguments: -./btmon [help|--help|-h] [adapter#id] - adapter#id - show events only for an given adapter - help - show help and exit - -If no adapter#id is given, that display events from all adapters and devices; -GLOBAL events are displayed for all; - -Also, if needed - monitor can listen for an error messages and display it; - -3) blueZ-tool (bttool) -Bluetooth tool to manage devices and services; -Tasks: - Adapter managment: - - list all available adapters - - get/set properties - - discover remote devices - Device managment: - - list of added devices - - add remote device and initiate pairing - - remove device - - get/set properties - - discover services - - disconnect from device - - list/create/remove node(s) (TODO) - Services managment: - - list connected services - - connect/disconnect to/from an input device - - connect/disconnect to/from a serial device - - connect/disconnect to/from a network device (TODO: can be moved to btnetwork) - - connect/disconnect to/from an audio device (TODO: can be moved to btaudio) - -command line arguments: -./bttool [help|--help|-h] [list|--list|-l] [ [adapter#id] commands [params] ] - help - show help and exit - list - list all available adapters - - [adapter#id] ... (use an given adapter or default if does not defined) - Adapter commands: - prop[erties] [name] [value] - list/get/set property(es) - disc[over] - discover available remote devices - - dev[ice] addr|name? ... - Device commands: - list - list of added devices - conn[ect] - add remote device and initiate pairing - rem[ove] - remove device - discon[nect] - disconnect from device - prop[erties] [name] [value] - list/get/set property(es) - disc[over] - discover services - - serv[ice] ... - Services comands: - list - list connected services - disc[over] - discover services (alias) - in[put] conn[ect]|discon[ect] - connect/disconnect to/from an input device - ser[ial] ... - conn[ect] uuid|profile|channel - connect to a serial device - discon[nect] device - disconnect from a serial device - net[work] ... - conn[ect] gn|panu|nap - connect to a network device - discon[nect] - disconnect from a network device - au[dio] conn[ect]|discon[ect] - connect/disconnect to/from an audio device - -If no options are given - show help page; - -Examples of usage: - a) Discover remote devices - bttool disc - b) Connect to a remote device and initiate pairing - bttool dev xx:xx:xx:xx:xx:xx conn - c) Discover remote services - bttool dev xx:xx:xx:xx:xx:xx disc - or - bttool dev xx:xx:xx:xx:xx:xx serv disc - d) Connect to an input device - bttool dev xx:xx:xx:xx:xx:xx serv in conn - e) Change adapter mode/properties - bttool prop Discoverable off - bttool prop DiscoverableTimeout 1h - f) List added devices - bttool dev list - g) List all connected services - bttool dev xx:xx:xx:xx:xx:xx serv list - -4) blueZ-audio (btaudio) - -(TODO) - -5) blueZ-network (btnetwork) - -(TODO) - -6) blueZ-obex (btobex) -Bluetooth utility, that implements OBEX protocol; -Tasks: - - Send files via object push request - - Provide ftp access to remote device - -command line arguments: -./btobex [--help|-h|help] [adapter#id] dev[ice] addr|name? send|ftp [file1..fileN] - help - show help and exit - adapter#id - use an given adapter or default if does not defined - - dev[ice] addr|name? ... - Commands: - ftp - open FTP session - send file1..fileN - send file(s) - -FTP session example: -./btobex dev xx:xx:xx:xx:xx:xx ftp -> help -Available commands: -cd <name> Change directory -mkdir <name> Make directory -ls List files in current directory -put <src> [<dst>] Copy the src file (from local filesystem) to the dst file (on remote device) -get <src> [<dst>] Copy the src file (from remote device) to the dst file (on local filesystem) -cp <src> <dst> Copy file -mv <src> <dst> Move file -rm <name> Deletes the specified file/folder -quit End sessions -> quit - - ---------- -* (TODO) These features will be available in future versions diff --git a/doc/bttools-v3_pub.txt b/doc/bttools-v3_pub.txt deleted file mode 100644 index 07ce88e..0000000 --- a/doc/bttools-v3_pub.txt +++ /dev/null @@ -1,166 +0,0 @@ - bttools project ------------------------------------------------------------------------------------------- -Abstract: - Sometimes we need to work with bluetooth devices without having a X server. Also, -many peoples prefer to perform most operations in the console, even from a full DE. The -idea of this project - write a set of console utilities to work with the bluetooth devices. -The main advantage - X server is not needed, no bindings to the DE/WM. The main goal - to -implement the maximum functionality for a simple and easy work with the devices. ------------------------------------------------------------------------------------------- - -Base set of utilities: ------------------------ - - bttool-agent - - bttool-monitor - - bttool-utility - ----------------------------------------------- -1) bttool-agent (btagent/btagentlib) -Bluetooth agent/agentlib, to manage incoming and outgoing requests and connections; - -Tasks: - - request pincode/passkey for an authentication from user (bluetooth v2.0) - - display passkey to user (bluetooth v2.1 only) - - request confirmation from user, that a passkey for an authentication is valid (bluetooth v2.1 only) - - authorize a connection/service request - - cancel request if request failed/reply was not returned - - confirm mode change of adapter - - register/unregister self for an selected adapter - -btagent is an external tool, that manage incoming connections. -command line arguments: -./btagent [help|--help|-h] [adapter#id] - adapter#id - register agent for an given adapter - help - show help and exit - -If no adapter#id is given, than agent register self to a default adapter; -Agentlib is used as embedded agent to manage outgoing connections in bttool-utility; - ----------------------------------------------- -2) bttool-monitor (btmon) -Bluetooth monitor, that displays some events (and possible - an errors); - -Tasks (events to display): - Adaper events: - - adapter added/removed (GLOBAL) - - default adapter changed (GLOBAL) - - adapter property changed - Device events: - - device added/removed (ie created/removed) - - device property changed - - disconnection to a remote device has been requested - Input service events: - - input device connected/disconnected - Network service events: - - network device connected/disconnected (also displays interface name) - Audio service events (generic): - - audio device connected/disconnected/connection state changed - -command line arguments: -./btmon [help|--help|-h] [adapter#id] - adapter#id - show events only for an given adapter - help - show help and exit - -If no adapter#id is given, that display events from all adapters and devices; -GLOBAL events are displayed for all; - -Also, monitor can listen for an error messages from bttool-agent/bttool-utility and display they; - ----------------------------------------------- -3) bttool-utility (bttool) -Main bluetooth tool to manage devices and services; - -Tasks: - Adapter managment: - - list all available adapters - - get/set properties - - discover remote devices - Device managment: - - list of added devices - - add remote device and initiate pairing - - remove device - - get/set properties - - discover services - - disconnect from device - Services managment: - - list connected services - - connect/disconnect to/from an input device - - connect/disconnect to/from a serial device - - connect/disconnect to/from a network device - - connect/disconnect to/from an audio device - -command line arguments: -./bttool [help|--help|-h] [list|--list|-l] [ [adapter#id] commands [params] ] - help - show help and exit - list - list all available adapters - - [adapter#id] ... (use an given adapter or default if does not defined) - Adapter commands: - prop[erties] [name] [value] - list/get/set property(es) - disc[over] - discover available remote devices - - dev[ice] addr|name? ... - Device commands: - list - list of added devices - conn[ect] - add remote device and initiate pairing - rem[ove] - remove device - discon[nect] - disconnect from device - prop[erties] [name] [value] - list/get/set property(es) - disc[over] - discover services - - serv[ice] ... - Services comands: - list - list connected services - disc[over] - discover services (alias) - in[put] conn[ect]|discon[ect] - connect/disconnect to/from an input device - ser[ial] ... - conn[ect] uuid|profile|channel - connect to a serial device - discon[nect] device - disconnect from a serial device - net[work] ... - conn[ect] gn|panu|nap - connect to a network device - discon[nect] - disconnect from a network device - au[dio] conn[ect]|discon[ect] - connect/disconnect to/from an audio device - -If no options are given - show help page; - -This utility will support full and short syntax. - -Examples of usage: - a) Discover remote devices - ./bttool disc (short) - ./bttool discover (full) - - b) Connect to a remote device and initiate pairing - ./bttool dev xx:xx:xx:xx:xx:xx conn (short) - ./bttool device xx:xx:xx:xx:xx connect (full) - - c) Discover remote services - ./bttool dev xx:xx:xx:xx:xx:xx disc (short) - ./bttool device xx:xx:xx:xx:xx:xx discover (full) - OR - ./bttool dev xx:xx:xx:xx:xx:xx serv disc (short) - ./bttool device xx:xx:xx:xx:xx:xx service(s) discover (full) - - d) Connect to an input device - ./bttool dev xx:xx:xx:xx:xx:xx serv in conn (short) - ./bttool device xx:xx:xx:xx:xx:xx service input connect (full) - - e) Change adapter mode/properties - ./bttool prop Discoverable off (short) - ./bttool prop DiscoverableTimeout 1h (short) - ./bttool property Discoverable off (full) - - f) List added devices - ./bttool dev list (short) - ./bttool device(s) list (full) - - g) List all connected services - ./bttool dev xx:xx:xx:xx:xx:xx serv list (short) - ./bttool device xx:xx:xx:xx:xx:xx service(s) list (full) - ---------- -* adapter#id also can be: hci0, 0, 00:11:22:33:44:55, ?MyCoolAdapter? -** device xx:xx:xx:xx:xx:xx can be: 11:22:33:44:55:66, ?CoolRemoteDevice? - -IMPORTANT: This is a base document (ie demo), all other features, such as OBEX support, bash-completion, etc - will be described later. diff --git a/src/Makefile.am b/src/Makefile.am index 5ba6fed..b0442f3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,27 +30,22 @@ obexd_sources = lib/obexd/obexagent.c lib/obexd/obexagent.h \ lib/obexd/obexsession.c lib/obexd/obexsession.h \ lib/obexd/obextransfer.c lib/obexd/obextransfer.h -ods_sources = lib/ods/obexmanager.c lib/ods/obexmanager.h \ - lib/ods/obexserver.c lib/ods/obexserver.h \ - lib/ods/obexserver_session.c lib/ods/obexserver_session.h \ - lib/ods/obexsession.c lib/ods/obexsession.h - lib_sources = lib/marshallers.c lib/marshallers.h \ lib/dbus-common.c lib/dbus-common.h \ lib/helpers.c lib/helpers.h \ lib/sdp.c lib/sdp.h \ - lib/bluez-api.h lib/obexd-api.h lib/ods-api.h + lib/bluez-api.h lib/obexd-api.h bin_PROGRAMS = bt-monitor bt-adapter bt-agent bt-device bt-input bt-audio bt-network bt-serial bt-obex -bt_monitor_SOURCES = $(lib_sources) $(bluez_sources) bt-monitor.c -bt_adapter_SOURCES = ${lib_sources} $(bluez_sources) bt-adapter.c -bt_agent_SOURCES = $(lib_sources) $(bluez_sources) bt-agent.c -bt_device_SOURCES = $(lib_sources) $(bluez_sources) bt-device.c -bt_input_SOURCES = $(lib_sources) $(bluez_sources) bt-input.c -bt_audio_SOURCES = $(lib_sources) $(bluez_sources) bt-audio.c -bt_network_SOURCES = $(lib_sources) $(bluez_sources) bt-network.c -bt_serial_SOURCES = $(lib_sources) $(bluez_sources) bt-serial.c -bt_obex_SOURCES = $(lib_sources) $(bluez_sources) $(ods_sources) bt-obex.c +bt_monitor_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-monitor.c +bt_adapter_SOURCES = ${lib_sources} $(bluez_sources) $(obexd_sources) bt-adapter.c +bt_agent_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-agent.c +bt_device_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-device.c +bt_input_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-input.c +bt_audio_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-audio.c +bt_network_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-network.c +bt_serial_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-serial.c +bt_obex_SOURCES = $(lib_sources) $(bluez_sources) $(obexd_sources) bt-obex.c CLEANFILES = Makefile.in \ lib/marshallers.c lib/marshallers.h diff --git a/src/bt-adapter.c b/src/bt-adapter.c index e34cb3d..f6404ea 100644 --- a/src/bt-adapter.c +++ b/src/bt-adapter.c @@ -29,7 +29,9 @@ #include <string.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" static void adapter_device_found(Adapter *adapter, const gchar *address, GHashTable *values, gpointer data) { @@ -64,7 +66,7 @@ static void adapter_device_disappeared(Adapter *adapter, const gchar *address, g g_print("Device disappeared: %s (%s)\n", g_value_get_string(g_hash_table_lookup(found_devices, address)), address); } -*/ + */ static void adapter_property_changed(Adapter *adapter, const gchar *name, const GValue *value, gpointer data) { @@ -99,6 +101,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new("- a bluetooth adapter manager"); g_option_context_add_main_entries(context, entries, NULL); @@ -132,8 +135,15 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } diff --git a/src/bt-agent.c b/src/bt-agent.c index 3af0f5b..0f655d9 100644 --- a/src/bt-agent.c +++ b/src/bt-agent.c @@ -30,7 +30,9 @@ #include <signal.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" static gboolean need_unregister = TRUE; static GMainLoop *mainloop = NULL; @@ -65,6 +67,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new(" - a bluetooth agent"); g_option_context_add_main_entries(context, entries, NULL); @@ -82,8 +85,15 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } @@ -96,7 +106,7 @@ int main(int argc, char *argv[]) Agent *agent = g_object_new(AGENT_TYPE, NULL); - adapter_register_agent(adapter, DBUS_AGENT_PATH, "DisplayYesNo", &error); + adapter_register_agent(adapter, AGENT_DBUS_PATH, "DisplayYesNo", &error); exit_if_error(error); g_signal_connect(agent, "AgentReleased", G_CALLBACK(agent_released), mainloop); @@ -111,7 +121,7 @@ int main(int argc, char *argv[]) g_main_loop_run(mainloop); if (need_unregister) { - adapter_unregister_agent(adapter, DBUS_AGENT_PATH, &error); + adapter_unregister_agent(adapter, AGENT_DBUS_PATH, &error); exit_if_error(error); /* Waiting for AgentReleased signal */ diff --git a/src/bt-audio.c b/src/bt-audio.c index 2bc555e..067135d 100644 --- a/src/bt-audio.c +++ b/src/bt-audio.c @@ -29,7 +29,9 @@ #include <string.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" static void audio_property_changed(Audio *audio, const gchar *name, const GValue *value, gpointer data) { @@ -66,6 +68,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new("- a bluetooth generic audio manager"); g_option_context_add_main_entries(context, entries, NULL); @@ -86,8 +89,15 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } @@ -97,7 +107,7 @@ int main(int argc, char *argv[]) Device *device = find_device(adapter, connect_arg != NULL ? connect_arg : disconnect_arg, &error); exit_if_error(error); - if (!intf_is_supported(device_get_dbus_object_path(device), AUDIO_INTF)) { + if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), AUDIO_DBUS_INTERFACE)) { g_printerr("Audio service is not supported by this device\n"); exit(EXIT_FAILURE); } diff --git a/src/bt-device.c b/src/bt-device.c index abc2dd6..b15aa5b 100644 --- a/src/bt-device.c +++ b/src/bt-device.c @@ -29,7 +29,10 @@ #include <string.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/sdp.h" +#include "lib/bluez-api.h" enum { REC, @@ -45,6 +48,7 @@ enum { static int xml_t[LAST_E] = {0, 0, 0, 0, -1, -1}; +/* Main arguments */ static gchar *adapter_arg = NULL; static gboolean list_arg = FALSE; static gchar *connect_arg = NULL; @@ -248,6 +252,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new("- a bluetooth device manager"); g_option_context_add_main_entries(context, entries, NULL); @@ -255,13 +260,15 @@ int main(int argc, char *argv[]) g_option_context_set_description(context, "Services Options:\n" " -s, --services <name|mac> [<pattern>]\n" - " Where `pattern` is an optional specific UUID\n\n" + " Where `pattern` is an optional specific UUID to search\n\n" "Set Options:\n" " --set <name|mac> <property> <value>\n" - " Where `property` is one of:\n" - " Alias\n" - " Trusted\n" - " Blocked\n\n" + " Where\n" + " `name|mac` is a device name or MAC\n" + " `property` is one of:\n" + " Alias\n" + " Trusted\n" + " Blocked\n\n" //"Report bugs to <"PACKAGE_BUGREPORT">." "Project home page <"PACKAGE_URL">." ); @@ -277,7 +284,7 @@ int main(int argc, char *argv[]) g_print("%s: Invalid arguments for --services\n", g_get_prgname()); g_print("Try `%s --help` for more information.\n", g_get_prgname()); exit(EXIT_FAILURE); - } else if (set_arg && (argc != 4 || strlen(argv[1]) == 0 || strlen(argv[2]) ==0 || strlen(argv[3]) == 0)) { + } else if (set_arg && (argc != 4 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0 || strlen(argv[3]) == 0)) { g_print("%s: Invalid arguments for --set\n", g_get_prgname()); g_print("Try `%s --help` for more information.\n", g_get_prgname()); exit(EXIT_FAILURE); @@ -285,8 +292,15 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } @@ -314,7 +328,7 @@ int main(int argc, char *argv[]) Agent *agent = g_object_new(AGENT_TYPE, NULL); GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); - adapter_create_paired_device_begin(adapter, create_paired_device_done, mainloop, connect_arg, DBUS_AGENT_PATH, "DisplayYesNo"); + adapter_create_paired_device_begin(adapter, create_paired_device_done, mainloop, connect_arg, AGENT_DBUS_PATH, "DisplayYesNo"); g_main_loop_run(mainloop); gchar *created_device = adapter_create_paired_device_end(adapter, &error); exit_if_error(error); @@ -376,7 +390,7 @@ int main(int argc, char *argv[]) while (g_hash_table_iter_next(&iter, &key, &value)) { n++; if (n == 1) g_print("\n"); - g_print("[RECORD:%d]\n", (int)key); + g_print("[RECORD:%d]\n", (gint) key); GMarkupParser xml_parser = {xml_start_element, xml_end_element, NULL, NULL, NULL}; GMarkupParseContext *xml_parse_context = g_markup_parse_context_new(&xml_parser, 0, NULL, NULL); g_markup_parse_context_parse(xml_parse_context, value, strlen(value), &error); diff --git a/src/bt-input.c b/src/bt-input.c index 57bb471..1248791 100644 --- a/src/bt-input.c +++ b/src/bt-input.c @@ -29,7 +29,9 @@ #include <string.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" static void input_property_changed(Input *input, const gchar *name, const GValue *value, gpointer data) { @@ -63,6 +65,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new("- a bluetooth input manager"); g_option_context_add_main_entries(context, entries, NULL); @@ -83,8 +86,15 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } @@ -94,7 +104,7 @@ int main(int argc, char *argv[]) Device *device = find_device(adapter, connect_arg != NULL ? connect_arg : disconnect_arg, &error); exit_if_error(error); - if (!intf_is_supported(device_get_dbus_object_path(device), INPUT_INTF)) { + if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), INPUT_DBUS_INTERFACE)) { g_printerr("Input service is not supported by this device\n"); exit(EXIT_FAILURE); } diff --git a/src/bt-monitor.c b/src/bt-monitor.c index 8522a3e..2078e04 100644 --- a/src/bt-monitor.c +++ b/src/bt-monitor.c @@ -29,7 +29,9 @@ #include <string.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" static gchar *adapter_arg = NULL; @@ -103,7 +105,7 @@ static void adapter_device_created(Adapter *adapter, const gchar *device_path, g { //g_print("adapter_device_created()\n"); - if (intf_is_supported(device_path, DEVICE_INTF)) { + if (intf_supported(BLUEZ_DBUS_NAME, device_path, DEVICE_DBUS_INTERFACE)) { Device *device = g_object_new(DEVICE_TYPE, "DBusObjectPath", device_path, NULL); g_print("[Adapter: %s (%s)] Device created: %s (%s)\n", adapter_get_name(adapter), adapter_get_address(adapter), device_get_alias(device), device_get_address(device)); capture_device(device); @@ -393,17 +395,17 @@ static void reload_device_services(Device *device) } // Capturing signals from available services - if (intf_is_supported(device_get_dbus_object_path(device), AUDIO_INTF)) { + if (intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), AUDIO_DBUS_INTERFACE)) { Audio *audio = g_object_new(AUDIO_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL); g_signal_connect(audio, "PropertyChanged", G_CALLBACK(audio_property_changed), device); t2 = g_slist_append(t2, audio); } - if (intf_is_supported(device_get_dbus_object_path(device), INPUT_INTF)) { + if (intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), INPUT_DBUS_INTERFACE)) { Input *input = g_object_new(INPUT_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL); g_signal_connect(input, "PropertyChanged", G_CALLBACK(input_property_changed), device); t2 = g_slist_append(t2, input); } - if (intf_is_supported(device_get_dbus_object_path(device), NETWORK_INTF)) { + if (intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), NETWORK_DBUS_INTERFACE)) { Network *network = g_object_new(NETWORK_TYPE, "DBusObjectPath", device_get_dbus_object_path(device), NULL); g_signal_connect(network, "PropertyChanged", G_CALLBACK(network_property_changed), device); t2 = g_slist_append(t2, network); @@ -423,6 +425,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new("- a bluetooth monitor"); g_option_context_add_main_entries(context, entries, NULL); @@ -440,8 +443,15 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } diff --git a/src/bt-network.c b/src/bt-network.c index 21a9fb1..4128da6 100644 --- a/src/bt-network.c +++ b/src/bt-network.c @@ -27,15 +27,26 @@ #include <stdlib.h> #include <string.h> +#include <signal.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" + +static GMainLoop *mainloop = NULL; + +static void sigterm_handler(int sig) +{ + g_message("%s received", sig == SIGTERM ? "SIGTERM" : "SIGINT"); + g_main_loop_quit(mainloop); +} static void network_property_changed(Network *network, const gchar *name, const GValue *value, gpointer data) { g_assert(data != NULL); GMainLoop *mainloop = data; - + if (g_strcmp0(name, "Connected") == 0) { if (g_value_get_boolean(value) == TRUE) { g_print("Network service is connected\n"); @@ -49,18 +60,17 @@ static void network_property_changed(Network *network, const gchar *name, const static gchar *adapter_arg = NULL; static gboolean connect_arg = FALSE; static gchar *connect_device_arg = NULL; -static gchar *connect_service_arg = NULL; +static gchar *connect_uuid_arg = NULL; static gchar *disconnect_arg = NULL; -static gboolean service_arg = FALSE; -static gchar *service_name_arg = NULL; -static gchar *service_property_arg = NULL; -static gchar *service_value_arg = NULL; +static gboolean server_arg = FALSE; +static gchar *server_uuid_arg = NULL; +static gchar *server_brige_arg = NULL; static GOptionEntry entries[] = { {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter name or MAC", "<name|mac>"}, {"connect", 'c', 0, G_OPTION_ARG_NONE, &connect_arg, "Connect to a network device", NULL}, {"disconnect", 'd', 0, G_OPTION_ARG_STRING, &disconnect_arg, "Disconnect from a network device", "<name|mac>"}, - {"service", 's', 0, G_OPTION_ARG_NONE, &service_arg, "Manage GN/PANU/NAP services", NULL}, + {"server", 's', 0, G_OPTION_ARG_NONE, &server_arg, "Start GN/PANU/NAP server", NULL}, {NULL} }; @@ -70,23 +80,21 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new("- a bluetooth network manager"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_summary(context, "Version "PACKAGE_VERSION); g_option_context_set_description(context, "Connect Options:\n" - " -c, --connect <name|mac> <pattern>\n" - " Where `pattern` is:\n" - " UUID 128 bit string\n" - " Profile short name: gn, panu or nap\n" - " UUID hexadecimal number\n\n" - "Service Options:\n" - " -s, --service <gn|panu|nap> [<property> <value>]\n" - " Where `property` is one of:\n" - " Name\n" - " Enabled\n" - " By default - show status\n\n" + " -c, --connect <name|mac> <uuid>\n" + " Where\n" + " `name|mac` is a device name or MAC\n" + " `uuid` is:\n" + " Profile short name: gn, panu or nap\n\n" + "Server Options:\n" + " -s, --server <gn|panu|nap> <brige>\n" + " Every new connection to this server will be added the `bridge` interface\n\n" //"Report bugs to <"PACKAGE_BUGREPORT">." "Project home page <"PACKAGE_URL">." ); @@ -95,23 +103,30 @@ int main(int argc, char *argv[]) g_print("%s: %s\n", g_get_prgname(), error->message); g_print("Try `%s --help` for more information.\n", g_get_prgname()); exit(EXIT_FAILURE); - } else if (!connect_arg && (!disconnect_arg || strlen(disconnect_arg) == 0) && !service_arg) { + } else if (!connect_arg && (!disconnect_arg || strlen(disconnect_arg) == 0) && !server_arg) { g_print("%s", g_option_context_get_help(context, FALSE, NULL)); exit(EXIT_FAILURE); } else if (connect_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) { g_print("%s: Invalid arguments for --connect\n", g_get_prgname()); g_print("Try `%s --help` for more information.\n", g_get_prgname()); exit(EXIT_FAILURE); - } else if (service_arg && (argc != 2 || strlen(argv[1]) == 0) && (argc != 4 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0 || strlen(argv[3]) == 0)) { - g_print("%s: Invalid arguments for --service\n", g_get_prgname()); + } else if (server_arg && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) { + g_print("%s: Invalid arguments for --server\n", g_get_prgname()); g_print("Try `%s --help` for more information.\n", g_get_prgname()); exit(EXIT_FAILURE); } g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } @@ -121,13 +136,13 @@ int main(int argc, char *argv[]) if (connect_arg || disconnect_arg) { if (connect_arg) { connect_device_arg = argv[1]; - connect_service_arg = argv[2]; + connect_uuid_arg = argv[2]; } Device *device = find_device(adapter, connect_device_arg != NULL ? connect_device_arg : disconnect_arg, &error); exit_if_error(error); - if (!intf_is_supported(device_get_dbus_object_path(device), NETWORK_INTF)) { + if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), NETWORK_DBUS_INTERFACE)) { g_printerr("Network service is not supported by this device\n"); exit(EXIT_FAILURE); } @@ -141,7 +156,7 @@ int main(int argc, char *argv[]) if (network_get_connected(network) == TRUE) { g_print("Network service is already connected\n"); } else { - gchar *intf = network_connect(network, connect_service_arg, &error); + gchar *intf = network_connect(network, connect_uuid_arg, &error); exit_if_error(error); g_main_loop_run(mainloop); g_free(intf); @@ -161,135 +176,47 @@ int main(int argc, char *argv[]) g_object_unref(network); g_object_unref(device); g_main_loop_unref(mainloop); - } else if (service_arg) { - GValue v = {0,}; - - service_name_arg = argv[1]; - if (argc == 4) { - service_property_arg = argv[2]; - service_value_arg = argv[3]; - - if (g_strcmp0(service_property_arg, "Name") == 0) { - g_value_init(&v, G_TYPE_STRING); - g_value_set_string(&v, service_value_arg); - } else if (g_strcmp0(service_property_arg, "Enabled") == 0) { - g_value_init(&v, G_TYPE_BOOLEAN); - - if (g_strcmp0(service_value_arg, "0") == 0 || g_ascii_strcasecmp(service_value_arg, "FALSE") == 0 || g_ascii_strcasecmp(service_value_arg, "OFF") == 0) { - g_value_set_boolean(&v, FALSE); - } else if (g_strcmp0(service_value_arg, "1") == 0 || g_ascii_strcasecmp(service_value_arg, "TRUE") == 0 || g_ascii_strcasecmp(service_value_arg, "ON") == 0) { - g_value_set_boolean(&v, TRUE); - } else { - g_print("%s: Invalid boolean value: %s\n", g_get_prgname(), service_value_arg); - g_print("Try `%s --help` for more information.\n", g_get_prgname()); - exit(EXIT_FAILURE); - } - } else { - g_print("%s: Invalid property: %s\n", g_get_prgname(), service_property_arg); - g_print("Try `%s --help` for more information.\n", g_get_prgname()); - exit(EXIT_FAILURE); - } - } - - if (g_ascii_strcasecmp(service_name_arg, "GN") == 0) { - if (!intf_is_supported(adapter_get_dbus_object_path(adapter), NETWORK_HUB_INTF)) { - g_printerr("GN service is not supported by this adapter\n"); - exit(EXIT_FAILURE); - } + } else if (server_arg) { + server_uuid_arg = argv[1]; + server_brige_arg = argv[2]; - NetworkHub *hub = g_object_new(NETWORK_HUB_TYPE, "DBusObjectPath", adapter_get_dbus_object_path(adapter), NULL); + if (g_ascii_strcasecmp(server_uuid_arg, "gn") != 0 && g_ascii_strcasecmp(server_uuid_arg, "panu") != 0 && g_ascii_strcasecmp(server_uuid_arg, "nap") != 0) { + g_print("%s: Invalid server UUID: %s\n", g_get_prgname(), server_uuid_arg); + g_print("Try `%s --help` for more information.\n", g_get_prgname()); + exit(EXIT_FAILURE); + } - if (service_property_arg == NULL) { - g_print("[Service: GN]\n"); - g_print(" Name: %s\n", network_hub_get_name(hub)); - g_print(" Enabled: %d\n", network_hub_get_enabled(hub)); - g_print(" UUID: %s (%s)\n", uuid2name(network_hub_get_uuid(hub)), network_hub_get_uuid(hub)); - } else { - GHashTable *props = network_hub_get_properties(hub, &error); - exit_if_error(error); - GValue *old_value = g_hash_table_lookup(props, service_property_arg); - g_assert(old_value != NULL); - if (G_VALUE_HOLDS_STRING(old_value)) { - g_print("%s: %s -> %s\n", service_property_arg, g_value_get_string(old_value), g_value_get_string(&v)); - } else if (G_VALUE_HOLDS_BOOLEAN(old_value)) { - g_print("%s: %d -> %d\n", service_property_arg, g_value_get_boolean(old_value), g_value_get_boolean(&v)); - } - g_hash_table_unref(props); - - network_hub_set_property(hub, service_property_arg, &v, &error); - exit_if_error(error); - } + if (!intf_supported(BLUEZ_DBUS_NAME, adapter_get_dbus_object_path(adapter), NETWORK_SERVER_DBUS_INTERFACE)) { + g_printerr("Network server is not supported by this adapter\n"); + exit(EXIT_FAILURE); + } - g_object_unref(hub); - } else if (g_ascii_strcasecmp(service_name_arg, "PANU") == 0) { - if (!intf_is_supported(adapter_get_dbus_object_path(adapter), NETWORK_PEER_INTF)) { - g_printerr("PANU service is not supported by this adapter\n"); - exit(EXIT_FAILURE); - } + gchar *server_uuid_upper = g_ascii_strup(server_uuid_arg, -1); - NetworkPeer *peer = g_object_new(NETWORK_PEER_TYPE, "DBusObjectPath", adapter_get_dbus_object_path(adapter), NULL); + NetworkServer *network_server = g_object_new(NETWORK_SERVER_TYPE, "DBusObjectPath", adapter_get_dbus_object_path(adapter), NULL); - if (service_property_arg == NULL) { - g_print("[Service: PANU]\n"); - g_print(" Name: %s\n", network_peer_get_name(peer)); - g_print(" Enabled: %d\n", network_peer_get_enabled(peer)); - g_print(" UUID: %s (%s)\n", uuid2name(network_peer_get_uuid(peer)), network_peer_get_uuid(peer)); - } else { - GHashTable *props = network_peer_get_properties(peer, &error); - exit_if_error(error); - GValue *old_value = g_hash_table_lookup(props, service_property_arg); - g_assert(old_value != NULL); - if (G_VALUE_HOLDS_STRING(old_value)) { - g_print("%s: %s -> %s\n", service_property_arg, g_value_get_string(old_value), g_value_get_string(&v)); - } else if (G_VALUE_HOLDS_BOOLEAN(old_value)) { - g_print("%s: %d -> %d\n", service_property_arg, g_value_get_boolean(old_value), g_value_get_boolean(&v)); - } - g_hash_table_unref(props); - - network_peer_set_property(peer, service_property_arg, &v, &error); - exit_if_error(error); - } + network_server_register(network_server, server_uuid_arg, server_brige_arg, &error); + exit_if_error(error); + g_print("%s server registered\n", server_uuid_upper); - g_object_unref(peer); - } else if (g_ascii_strcasecmp(service_name_arg, "NAP") == 0) { - if (!intf_is_supported(adapter_get_dbus_object_path(adapter), NETWORK_ROUTER_INTF)) { - g_printerr("NAP service is not supported by this adapter\n"); - exit(EXIT_FAILURE); - } + mainloop = g_main_loop_new(NULL, FALSE); - NetworkRouter *router = g_object_new(NETWORK_ROUTER_TYPE, "DBusObjectPath", adapter_get_dbus_object_path(adapter), NULL); + /* Add SIGTERM && SIGINT handlers */ + struct sigaction sa; + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = sigterm_handler; + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGINT, &sa, NULL); - if (service_property_arg == NULL) { - g_print("[Service: NAP]\n"); - g_print(" Name: %s\n", network_router_get_name(router)); - g_print(" Enabled: %d\n", network_router_get_enabled(router)); - g_print(" UUID: %s (%s)\n", uuid2name(network_router_get_uuid(router)), network_router_get_uuid(router)); - } else { - GHashTable *props = network_router_get_properties(router, &error); - exit_if_error(error); - GValue *old_value = g_hash_table_lookup(props, service_property_arg); - g_assert(old_value != NULL); - if (G_VALUE_HOLDS_STRING(old_value)) { - g_print("%s: %s -> %s\n", service_property_arg, g_value_get_string(old_value), g_value_get_string(&v)); - } else if (G_VALUE_HOLDS_BOOLEAN(old_value)) { - g_print("%s: %d -> %d\n", service_property_arg, g_value_get_boolean(old_value), g_value_get_boolean(&v)); - } - g_hash_table_unref(props); - - network_router_set_property(router, service_property_arg, &v, &error); - exit_if_error(error); - } + g_main_loop_run(mainloop); - g_object_unref(router); - } else { - g_print("%s: Invalid service name: %s\n", g_get_prgname(), service_name_arg); - g_print("Try `%s --help` for more information.\n", g_get_prgname()); - exit(EXIT_FAILURE); - } + network_server_unregister(network_server, server_uuid_arg, &error); + exit_if_error(error); + g_print("%s server unregistered\n", server_uuid_upper); - if (argc == 4) { - g_value_unset(&v); - } + g_free(server_uuid_upper); + g_main_loop_unref(mainloop); + g_object_unref(network_server); } g_object_unref(adapter); diff --git a/src/bt-obex.c b/src/bt-obex.c index bed079f..c4d9787 100644 --- a/src/bt-obex.c +++ b/src/bt-obex.c @@ -33,295 +33,85 @@ #include <errno.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" +#include "lib/obexd-api.h" -typedef struct { - OBEXServer *serv; - OBEXServerSession *sess; - gchar *sess_id; +GHashTable *server_transfers = NULL; +GMainLoop *mainloop = NULL; - /* Client address */ - gchar *client_name; - gchar *client_addr; - - /* Transfer info */ - gchar *filename; - gchar *local_path; - guint64 size; - guint pp; // per sent -} sess_transf_s; - -static gchar *server_type = NULL; -static GHashTable *server_sessions = NULL; - -/* Main arguments */ -static gchar *adapter_arg = NULL; -static gboolean server_arg = FALSE; -static gchar *server_type_arg = NULL; -static gchar *server_path_arg = NULL; -static gboolean opp_arg = FALSE; -static gchar *opp_device_arg = NULL; -static gchar *opp_file_arg = NULL; -static gchar *ftp_arg = NULL; - -/* Sessions signals defs */ -static void obexserver_session_cancelled(OBEXServerSession *session, gpointer data); -static void obexserver_session_disconnected(OBEXServerSession *session, gpointer data); -static void obexserver_session_transfer_started(OBEXServerSession *session, const gchar *filename, const gchar *local_path, guint64 total_bytes, gpointer data); -static void obexserver_session_transfer_progress(OBEXServerSession *session, guint64 bytes_transferred, gpointer data); -static void obexserver_session_transfer_completed(OBEXServerSession *session, gpointer data); -static void obexserver_session_error_occurred(OBEXServerSession *session, const gchar *error_name, const gchar *error_message, gpointer data); - -static void obexsession_cancelled(OBEXSession *session, gpointer data); -static void obexsession_disconnected(OBEXSession *session, gpointer data); -static void obexsession_closed(OBEXSession *session, gpointer data); -static void obexsession_transfer_started(OBEXSession *session, const gchar *filename, const gchar *local_path, guint64 total_bytes, gpointer data); -static void obexsession_transfer_progress(OBEXSession *session, guint64 bytes_transferred, gpointer data); -static void obexsession_transfer_completed(OBEXSession *session, gpointer data); -static void obexsession_error_occurred(OBEXSession *session, const gchar *error_name, const gchar *error_message, gpointer data); - -/* - * OBEXManager signals - */ -static void obexmanager_session_connected(OBEXManager *manager, const gchar *path, gpointer data) -{ - g_print("[OBEXManager] Session connected: %s\n", path); -} - -static void obexmanager_session_connect_error(OBEXManager *manager, const gchar *path, const gchar *error_name, const gchar *error_message, gpointer data) +/* OBEXTransfer signals */ +static void obextransfer_progress(OBEXTransfer *transfer, gint total, gint transfered, gpointer data) { - g_print("[OBEXManager] Session connect error: %s:%s\n", path, error_name, error_message); -} - -static void obexmanager_session_closed(OBEXManager *manager, const gchar *path, gpointer data) -{ - g_print("[OBEXManager] Session closed: %s\n", path); -} - -/* - * OBEXServer signals - */ -static void obexserver_started(OBEXServer *server, gpointer data) -{ - g_print("[%sServer] Started\n", server_type); -} - -static void obexserver_stopped(OBEXServer *server, gpointer data) -{ - g_print("[%sServer] Stopped\n", server_type); -} - -static void obexserver_closed(OBEXServer *server, gpointer data) -{ - g_print("[%sServer] Closed\n", server_type); -} - -static void obexserver_error_occurred(OBEXServer *server, const gchar *error_name, const gchar *error_message, gpointer data) -{ - g_print("[%sServer] %s:%s\n", server_type, error_name, error_message); -} - -static void obexserver_session_created(OBEXServer *server, const gchar *path, gpointer data) -{ - OBEXServerSession *session = g_object_new(OBEXSERVER_SESSION_TYPE, "DBusObjectPath", path, NULL); - g_signal_connect(session, "Cancelled", G_CALLBACK(obexserver_session_cancelled), NULL); - g_signal_connect(session, "Disconnected", G_CALLBACK(obexserver_session_disconnected), NULL); - g_signal_connect(session, "TransferStarted", G_CALLBACK(obexserver_session_transfer_started), NULL); - g_signal_connect(session, "TransferProgress", G_CALLBACK(obexserver_session_transfer_progress), NULL); - g_signal_connect(session, "TransferCompleted", G_CALLBACK(obexserver_session_transfer_completed), NULL); - g_signal_connect(session, "ErrorOccurred", G_CALLBACK(obexserver_session_error_occurred), NULL); - - sess_transf_s *t = g_new0(sess_transf_s, 1); - t->serv = server; - t->sess = session; - t->sess_id = g_path_get_basename(path); - - g_print("[%sServer] Session created: %s\n", server_type, t->sess_id); - - /* Get remote address & name (if possible) */ - GError *error = NULL; - GHashTable *sess_info = obexserver_get_server_session_info(server, path, &error); - exit_if_error(error); - t->client_addr = g_strdup(g_hash_table_lookup(sess_info, "BluetoothAddress")); - g_hash_table_unref(sess_info); - - Adapter *adapter_t = find_adapter(adapter_arg, &error); - exit_if_error(error); - Device *device_t = find_device(adapter_t, t->client_addr, &error); - exit_if_error(error); - if (device_t) - t->client_name = g_strdup(device_get_name(device_t)); - g_object_unref(device_t); - g_object_unref(adapter_t); - - g_hash_table_insert(server_sessions, g_strdup(path), t); - - if (t->client_name) - g_print("[%sServer] Client: %s (%s)\n", server_type, t->client_name, t->client_addr); - else - g_print("[%sServer] Client: %s\n", server_type, t->client_addr); -} - -static void obexserver_session_removed(OBEXServer *server, const gchar *path, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, path); - g_assert(t != NULL); - - g_print("[%sServer] Session removed: %s\n", server_type, t->sess_id); - - /* Transfer free (if exists) */ - g_free(t->filename); - g_free(t->local_path); - t->size = 0; - t->pp = 0; - - /* Session data free */ - g_free(t->sess_id); - g_free(t->client_addr); - g_free(t->client_name); - g_object_unref(t->sess); - g_free(t); - - g_hash_table_remove(server_sessions, path); -} - -/* - * OBEXServerSession signals - */ -static void obexserver_session_cancelled(OBEXServerSession *session, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, obexserver_session_get_dbus_object_path(session)); - g_assert(t != NULL); - - g_print("[%s] Cancelled\n", t->sess_id); -} - -static void obexserver_session_disconnected(OBEXServerSession *session, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, obexserver_session_get_dbus_object_path(session)); - g_assert(t != NULL); - - g_print("[%s] Disconnected\n", t->sess_id); -} - -static void obexserver_session_transfer_started(OBEXServerSession *session, const gchar *filename, const gchar *local_path, guint64 total_bytes, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, obexserver_session_get_dbus_object_path(session)); - g_assert(t != NULL); - - GError *error = NULL; - - g_print("[%s] Transfer started:\n", t->sess_id); - g_print(" Filename: %s\n", filename); - g_print(" Save path: %s\n", local_path); - g_print(" Size: %llu bytes\n", total_bytes); - - gchar yn[4] = {0,}; - g_print("Accept (yes/no)? "); - errno = 0; - if (scanf("%3s", yn) == EOF && errno) { - g_warning("%s\n", strerror(errno)); - } - if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) { - obexserver_session_accept(session, &error); - exit_if_error(error); - } else { - obexserver_session_reject(session, &error); - exit_if_error(error); - return; - } - - t->filename = g_strdup(filename); - t->local_path = g_strdup(local_path); - t->size = total_bytes; - t->pp = 0; -} - -static void obexserver_session_transfer_progress(OBEXServerSession *session, guint64 bytes_transferred, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, obexserver_session_get_dbus_object_path(session)); - g_assert(t != NULL); - - t->pp = (bytes_transferred / (gfloat) t->size)*100; + guint pp = (transfered / (gfloat) total)*100; static gboolean update_progress = FALSE; if (!update_progress) { - g_print("[%s] Transfer progress: %3u%%", t->sess_id, t->pp); + g_print("[OBEXTransfer] Progress: %3u%%", pp); update_progress = TRUE; } else { - g_print("\b\b\b\b%3u%%", t->pp); + g_print("\b\b\b\b%3u%%", pp); } - if (t->pp == 100) g_print("\n"); -} - -static void obexserver_session_transfer_completed(OBEXServerSession *session, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, obexserver_session_get_dbus_object_path(session)); - g_assert(t != NULL); - - g_print("[%s] Transfer completed\n", t->sess_id); - - g_free(t->filename); - t->filename = NULL; - g_free(t->local_path); - t->local_path = NULL; - t->size = 0; - t->pp = 0; -} - -static void obexserver_session_error_occurred(OBEXServerSession *session, const gchar *error_name, const gchar *error_message, gpointer data) -{ - sess_transf_s *t = g_hash_table_lookup(server_sessions, obexserver_session_get_dbus_object_path(session)); - g_assert(t != NULL); - - /* If an error occurred during transfer */ - if (t->pp > 0 && t->pp < 100) g_print("\n"); - - g_print("[%s] %s:%s\n", t->sess_id, error_name, error_message); -} - -/* - * OBEXSession signals - */ -static void obexsession_cancelled(OBEXSession *session, gpointer data) -{ - -} - -static void obexsession_disconnected(OBEXSession *session, gpointer data) -{ - + if (pp == 100) { + g_print("\n"); + update_progress = FALSE; + } } -static void obexsession_closed(OBEXSession *session, gpointer data) +/* OBEXManager signals */ +static void obexmanager_session_created(OBEXManager *manager, const gchar *session_path, gpointer data) { - + g_print("[OBEXManager] FTP session opened\n"); } -static void obexsession_transfer_started(OBEXSession *session, const gchar *filename, const gchar *local_path, guint64 total_bytes, gpointer data) +static void obexmanager_session_removed(OBEXManager *manager, const gchar *session_path, gpointer data) { - + g_print("[OBEXManager] FTP session closed\n", session_path); } -static void obexsession_transfer_progress(OBEXSession *session, guint64 bytes_transferred, gpointer data) +static void obexmanager_transfer_started(OBEXManager *manager, const gchar *transfer_path, gpointer data) { + g_print("[OBEXManager] Transfer started\n", transfer_path); + OBEXTransfer *t = g_object_new(OBEXTRANSFER_TYPE, "DBusObjectPath", transfer_path, NULL); + g_signal_connect(t, "Progress", G_CALLBACK(obextransfer_progress), NULL); + g_hash_table_insert(server_transfers, transfer_path, t); } -static void obexsession_transfer_completed(OBEXSession *session, gpointer data) +static void obexmanager_transfer_completed(OBEXManager *manager, const gchar *transfer_path, gboolean success, gpointer data) { - + OBEXTransfer *t = g_hash_table_lookup(server_transfers, transfer_path); + if (t) { + g_print("[OBEXManager] Transfer %s\n", success == TRUE ? "succeeded" : "failed"); + g_object_unref(t); + g_hash_table_remove(server_transfers, transfer_path); + } else { + // Bug ? + } } -static void obexsession_error_occurred(OBEXSession *session, const gchar *error_name, const gchar *error_message, gpointer data) +/* Async callback for SendFiles() */ +/*static void send_files_done(gpointer data) { + g_assert(data != NULL); + GMainLoop *mainloop = data; + g_main_loop_quit(mainloop); +}*/ -} +/* Main arguments */ +static gchar *adapter_arg = NULL; +static gboolean server_arg = FALSE; +static gchar *server_path_arg = NULL; +static gboolean opp_arg = FALSE; +static gchar *opp_device_arg = NULL; +static gchar *opp_file_arg = NULL; +static gchar *ftp_arg = NULL; static GOptionEntry entries[] = { {"adapter", 'a', 0, G_OPTION_ARG_STRING, &adapter_arg, "Adapter name or MAC", "<name|mac>"}, - {"server", 's', 0, G_OPTION_ARG_NONE, &server_arg, "Start OPP/FTP server", NULL}, + {"server", 's', 0, G_OPTION_ARG_NONE, &server_arg, "Register self at OBEX server", NULL}, {"opp", 'p', 0, G_OPTION_ARG_NONE, &opp_arg, "Send file to remote device", NULL}, {"ftp", 'f', 0, G_OPTION_ARG_STRING, &ftp_arg, "Start FTP session with remote device", "<name|mac>"}, {NULL} @@ -333,14 +123,15 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new(" - a bluetooth OBEX client/server"); g_option_context_add_main_entries(context, entries, NULL); g_option_context_set_summary(context, "Version "PACKAGE_VERSION); g_option_context_set_description(context, "Server Options:\n" - " -s, --server <opp|ftp> [<path>]\n" - " Start OPP/FTP server and use given `path` as root directory\n" + " -s, --server [<path>]\n" + " Register self at OBEX server and use given `path` as OPP save directory\n" " If `path` does not specified - use current directory\n\n" "OPP Options:\n" " -p, --opp <name|mac> <file>\n" @@ -356,7 +147,7 @@ int main(int argc, char *argv[]) } else if (!server_arg && !opp_arg && (!ftp_arg || strlen(ftp_arg) == 0)) { g_print("%s", g_option_context_get_help(context, FALSE, NULL)); exit(EXIT_FAILURE); - } else if (server_arg && (argc != 2 || strlen(argv[1]) == 0) && (argc != 3 || strlen(argv[1]) == 0 || strlen(argv[2]) == 0)) { + } else if (server_arg && argc != 1 && (argc != 2 || strlen(argv[1]) == 0)) { g_print("%s: Invalid arguments for --server\n", g_get_prgname()); g_print("Try `%s --help` for more information.\n", g_get_prgname()); exit(EXIT_FAILURE); @@ -368,30 +159,33 @@ int main(int argc, char *argv[]) g_option_context_free(context); - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); exit(EXIT_FAILURE); } - if (!intf_is_supported(BLUEZ_DBUS_OBEXMANAGER_PATH, OBEXMANAGER_INTF)) { - g_printerr("%s: OBEX service does not found\n", g_get_prgname()); - g_printerr("Did you forget to run obex-data-server?\n"); + if (!dbus_session_connect(&error)) { + g_printerr("Couldn't connect to dbus session bus: %s\n", error->message); exit(EXIT_FAILURE); } - Adapter *adapter = find_adapter(adapter_arg, &error); - exit_if_error(error); + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); + exit(EXIT_FAILURE); + } - OBEXManager *manager = g_object_new(OBEXMANAGER_TYPE, NULL); - g_signal_connect(manager, "SessionConnected", G_CALLBACK(obexmanager_session_connected), NULL); - g_signal_connect(manager, "SessionConnectError", G_CALLBACK(obexmanager_session_connect_error), NULL); - g_signal_connect(manager, "SessionClosed", G_CALLBACK(obexmanager_session_closed), NULL); + /* Check, that obexd daemon is running */ + if (!intf_supported(OBEXD_DBUS_NAME, OBEXMANAGER_DBUS_PATH, OBEXMANAGER_DBUS_INTERFACE)) { + g_printerr("%s: OBEXD service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run obexd?\n"); + exit(EXIT_FAILURE); + } if (server_arg) { - server_sessions = g_hash_table_new(g_str_hash, g_str_equal); - server_type_arg = argv[1]; - if (argc == 3) { - server_path_arg = argv[2]; + if (argc == 2) { + server_path_arg = argv[1]; } /* Check that `path` is valid */ @@ -411,60 +205,175 @@ int main(int argc, char *argv[]) root_dir = g_strdup(server_path_arg); } - gboolean require_pairing = TRUE; - gboolean auto_accept = FALSE; - - if (g_strcmp0(server_type_arg, "opp") == 0) { - require_pairing = FALSE; - auto_accept = FALSE; - server_type = "OPP"; - } else if (g_strcmp0(server_type_arg, "ftp") == 0) { - require_pairing = TRUE; - auto_accept = TRUE; - server_type = "FTP"; - } else { - g_print("%s: Invalid server type: %s\n", g_get_prgname(), server_type_arg); - g_print("Try `%s --help` for more information.\n", g_get_prgname()); - exit(EXIT_FAILURE); - } + server_transfers = g_hash_table_new(g_str_hash, g_str_equal); - gchar *serv_path = obexmanager_create_bluetooth_server(manager, adapter_get_address(adapter), server_type_arg, require_pairing, &error); - exit_if_error(error); + OBEXManager *manager = g_object_new(OBEXMANAGER_TYPE, NULL); + g_signal_connect(manager, "SessionCreated", G_CALLBACK(obexmanager_session_created), NULL); + g_signal_connect(manager, "SessionRemoved", G_CALLBACK(obexmanager_session_removed), NULL); + g_signal_connect(manager, "TransferStarted", G_CALLBACK(obexmanager_transfer_started), NULL); + g_signal_connect(manager, "TransferCompleted", G_CALLBACK(obexmanager_transfer_completed), NULL); - OBEXServer *serv = g_object_new(OBEXSERVER_TYPE, "DBusObjectPath", serv_path, NULL); - g_signal_connect(serv, "Started", G_CALLBACK(obexserver_started), NULL); - g_signal_connect(serv, "Stopped", G_CALLBACK(obexserver_stopped), NULL); - g_signal_connect(serv, "Closed", G_CALLBACK(obexserver_closed), NULL); - g_signal_connect(serv, "ErrorOccurred", G_CALLBACK(obexserver_error_occurred), NULL); - g_signal_connect(serv, "SessionCreated", G_CALLBACK(obexserver_session_created), NULL); - g_signal_connect(serv, "SessionRemoved", G_CALLBACK(obexserver_session_removed), NULL); + OBEXAgent *agent = g_object_new(OBEXAGENT_TYPE, "RootFolder", root_dir, NULL); - gboolean is_started = obexserver_is_started(serv, &error); - exit_if_error(error); - if (is_started) { - g_printerr("%s: Server is already started\n", g_get_prgname()); - exit(EXIT_FAILURE); - } + g_free(root_dir); - obexserver_start(serv, root_dir, TRUE, auto_accept, &error); + obexmanager_register_agent(manager, OBEXAGENT_DBUS_PATH, &error); exit_if_error(error); - GMainLoop *mainloop = g_main_loop_new(NULL, FALSE); + mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); /* Waiting for connections... */ + // TODO: Add SIGINT handler + g_main_loop_unref(mainloop); - g_object_unref(serv); - g_free(serv_path); - g_free(root_dir); - g_hash_table_unref(server_sessions); + + /* Stop active transfers */ + GHashTableIter iter; + gpointer key, value; + g_hash_table_iter_init(&iter, server_transfers); + while (g_hash_table_iter_next(&iter, &key, &value)) { + OBEXTransfer *t = OBEXTRANSFER(value); + obextransfer_cancel(t, NULL); + g_object_unref(t); + g_hash_table_iter_remove(&iter); + } + g_hash_table_unref(server_transfers); + + obexmanager_unregister_agent(manager, OBEXAGENT_DBUS_PATH, &error); + g_object_unref(agent); + g_object_unref(manager); } else if (opp_arg) { + opp_device_arg = argv[1]; + opp_file_arg = argv[2]; + + /* Check that `file` is valid and readable */ + { + struct stat buf; + if (stat(opp_file_arg, &buf) != 0) { + g_printerr("%s: %s\n", g_get_prgname(), strerror(errno)); + exit(EXIT_FAILURE); + } + if (!S_ISREG(buf.st_mode)) { + g_printerr("%s: Invalid file: %s\n", g_get_prgname(), opp_file_arg); + exit(EXIT_FAILURE); + } + } + gchar * files_to_send[] = {NULL, NULL}; + if (!g_path_is_absolute(opp_file_arg)) { + gchar *current_dir = g_get_current_dir(); + files_to_send[0] = g_build_filename(current_dir, opp_file_arg, NULL); + g_free(current_dir); + } else { + files_to_send[0] = g_strdup(opp_file_arg); + } + + /* Get source address (address of adapter) */ + Adapter *adapter = find_adapter(adapter_arg, &error); + exit_if_error(error); + gchar *src_address = g_strdup(adapter_get_address(adapter)); + + /* Get destination address (address of remote device) */ + Device *device = find_device(adapter, opp_device_arg, &error); + exit_if_error(error); + gchar *dst_address = g_strdup(device == NULL ? opp_device_arg : device_get_address(device)); + + g_object_unref(device); + g_object_unref(adapter); + + /* Build arguments */ + GHashTable *device_dict = g_hash_table_new(g_str_hash, g_str_equal); + GValue source = {0}; + GValue destination = {0}; + g_value_init(&source, G_TYPE_STRING); + g_value_init(&destination, G_TYPE_STRING); + g_value_set_string(&source, src_address); + g_value_set_string(&destination, dst_address); + g_hash_table_insert(device_dict, "Source", &source); + g_hash_table_insert(device_dict, "Destination", &destination); + + OBEXClient *client = g_object_new(OBEXCLIENT_TYPE, NULL); + OBEXAgent *agent = g_object_new(OBEXAGENT_TYPE, NULL); + + mainloop = g_main_loop_new(NULL, FALSE); + + /* Sending file(s) */ + obexclient_send_files_begin(client, send_files_done, mainloop, device_dict, files_to_send, OBEXAGENT_DBUS_PATH); + g_main_loop_run(mainloop); + + /* Sending files process here ?? */ + + // TODO: Add SIGINT handler ?? + + g_main_loop_unref(mainloop); + + obexclient_send_files_end(client, &error); + exit_if_error(error); + + g_object_unref(agent); + g_object_unref(client); + + g_value_unset(&source); + g_value_unset(&destination); + g_hash_table_unref(device_dict); + + g_free(src_address); + g_free(dst_address); + g_strfreev(files_to_send); + } else if (ftp_arg) { + /* Get source address (address of adapter) */ + Adapter *adapter = find_adapter(adapter_arg, &error); + exit_if_error(error); + gchar *src_address = g_strdup(adapter_get_address(adapter)); + + /* Get destination address (address of remote device) */ + Device *device = find_device(adapter, ftp_arg, &error); + exit_if_error(error); + gchar *dst_address = g_strdup(device == NULL ? ftp_arg : device_get_address(device)); + + g_object_unref(device); + g_object_unref(adapter); + + /* Build arguments */ + GHashTable *device_dict = g_hash_table_new(g_str_hash, g_str_equal); + GValue source = {0}; + GValue destination = {0}; + GValue target = {0}; + g_value_init(&source, G_TYPE_STRING); + g_value_init(&destination, G_TYPE_STRING); + g_value_init(&target, G_TYPE_STRING); + g_value_set_string(&source, src_address); + g_value_set_string(&destination, dst_address); + g_value_set_string(&target, "FTP"); + g_hash_table_insert(device_dict, "Source", &source); + g_hash_table_insert(device_dict, "Destination", &destination); + g_hash_table_insert(device_dict, "Target", &target); + + OBEXClient *client = g_object_new(OBEXCLIENT_TYPE, NULL); + OBEXAgent *agent = g_object_new(OBEXAGENT_TYPE, NULL); + + /* Create FTP session */ + gchar *session_path = obexclient_create_session(client, device_dict, &error); + exit_if_error(error); + + OBEXClientFileTransfer *ftp_session = g_object_new(OBEXCLIENT_FILE_TRANSFER_TYPE, "DBusObjectPath", session_path, NULL); + + g_print("FTP session opened\n"); + + while (TRUE) { + g_print("> "); + gchar cmd[128] = {0,}; + errno = 0; + if (scanf("%128s", cmd) == EOF && errno) { + g_warning("%s\n", strerror(errno)); + } + + g_print("cmd: %s\n", cmd); + } } - g_object_unref(manager); - g_object_unref(adapter); dbus_disconnect(); exit(EXIT_SUCCESS); diff --git a/src/bt-serial.c b/src/bt-serial.c index 2d2ed11..49a0f81 100644 --- a/src/bt-serial.c +++ b/src/bt-serial.c @@ -29,7 +29,9 @@ #include <string.h> #include <glib.h> -#include "lib/bluez-dbus.h" +#include "lib/dbus-common.h" +#include "lib/helpers.h" +#include "lib/bluez-api.h" static gchar *adapter_arg = NULL; static gboolean connect_arg = FALSE; @@ -52,6 +54,7 @@ int main(int argc, char *argv[]) GOptionContext *context; g_type_init(); + dbus_init(); context = g_option_context_new(" - a bluetooth serial manager"); g_option_context_add_main_entries(context, entries, NULL); @@ -59,14 +62,17 @@ int main(int argc, char *argv[]) g_option_context_set_description(context, "Connect Options:\n" " -c, --connect <name|mac> <pattern>\n" - " Where `pattern` is:\n" - " UUID 128 bit string\n" - " Profile short name, e.g: spp, dun\n" - " RFCOMM channel, 1-30\n\n" + " Where\n" + " `name|mac` is a device name or MAC\n" + " `pattern` is:\n" + " UUID 128 bit string\n" + " Profile short name, e.g: spp, dun\n" + " RFCOMM channel, 1-30\n\n" "Disconnect Options:\n" " -d, --disconnect <name|mac> <tty_device>\n" - " Where `tty_device` is:\n" - " RFCOMM TTY device that has been connected\n\n" + " Where\n" + " `name|mac` is a device name or MAC\n" + " `tty_device` is a RFCOMM TTY device that has been connected\n\n" //"Report bugs to <"PACKAGE_BUGREPORT">." "Project home page <"PACKAGE_URL">." ); @@ -98,8 +104,15 @@ int main(int argc, char *argv[]) disconnect_tty_device_arg = argv[2]; } - if (!dbus_connect(&error)) { - g_printerr("Couldn't connect to dbus: %s\n", error->message); + if (!dbus_system_connect(&error)) { + g_printerr("Couldn't connect to dbus system bus: %s\n", error->message); + exit(EXIT_FAILURE); + } + + /* Check, that bluetooth daemon is running */ + if (!intf_supported(BLUEZ_DBUS_NAME, MANAGER_DBUS_PATH, MANAGER_DBUS_INTERFACE)) { + g_printerr("%s: BLUEZ service does not found\n", g_get_prgname()); + g_printerr("Did you forget to run bluetoothd?\n"); exit(EXIT_FAILURE); } @@ -109,7 +122,7 @@ int main(int argc, char *argv[]) Device *device = find_device(adapter, connect_device_arg != NULL ? connect_device_arg : disconnect_device_arg, &error); exit_if_error(error); - if (!intf_is_supported(device_get_dbus_object_path(device), SERIAL_INTF)) { + if (!intf_supported(BLUEZ_DBUS_NAME, device_get_dbus_object_path(device), SERIAL_DBUS_INTERFACE)) { g_printerr("Serial service is not supported by this device\n"); exit(EXIT_FAILURE); } diff --git a/src/lib/bluez/adapter.c b/src/lib/bluez/adapter.c index d0140aa..b6cfd0e 100644 --- a/src/lib/bluez/adapter.c +++ b/src/lib/bluez/adapter.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -230,6 +230,9 @@ static void adapter_init(Adapter *self) { self->priv = ADAPTER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + /* Async calls init */ self->priv->create_paired_device_call = NULL; diff --git a/src/lib/bluez/agent.c b/src/lib/bluez/agent.c index e150521..04dbd03 100644 --- a/src/lib/bluez/agent.c +++ b/src/lib/bluez/agent.c @@ -87,10 +87,9 @@ static void agent_init(Agent *self) { self->priv = AGENT_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(system_conn != NULL); dbus_g_connection_register_g_object(system_conn, AGENT_DBUS_PATH, G_OBJECT(self)); - g_print("Agent registered\n"); } diff --git a/src/lib/bluez/audio.c b/src/lib/bluez/audio.c index d4abcbf..6c6c0d5 100644 --- a/src/lib/bluez/audio.c +++ b/src/lib/bluez/audio.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -124,6 +124,9 @@ static void audio_init(Audio *self) { self->priv = AUDIO_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); } diff --git a/src/lib/bluez/device.c b/src/lib/bluez/device.c index 12c9017..587b804 100644 --- a/src/lib/bluez/device.c +++ b/src/lib/bluez/device.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -232,6 +232,9 @@ static void device_init(Device *self) { self->priv = DEVICE_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); } diff --git a/src/lib/bluez/input.c b/src/lib/bluez/input.c index cff4b71..09dbdfe 100644 --- a/src/lib/bluez/input.c +++ b/src/lib/bluez/input.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -124,6 +124,9 @@ static void input_init(Input *self) { self->priv = INPUT_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); } diff --git a/src/lib/bluez/manager.c b/src/lib/bluez/manager.c index df50ca3..7eea246 100644 --- a/src/lib/bluez/manager.c +++ b/src/lib/bluez/manager.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -149,6 +149,9 @@ static void manager_init(Manager *self) { self->priv = MANAGER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); GError *error = NULL; diff --git a/src/lib/bluez/network.c b/src/lib/bluez/network.c index b6e27e6..d6967f0 100644 --- a/src/lib/bluez/network.c +++ b/src/lib/bluez/network.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -137,6 +137,9 @@ static void network_init(Network *self) { self->priv = NETWORK_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); } diff --git a/src/lib/bluez/network_server.c b/src/lib/bluez/network_server.c index cccecd3..78ab124 100644 --- a/src/lib/bluez/network_server.c +++ b/src/lib/bluez/network_server.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -92,6 +92,9 @@ static void network_server_init(NetworkServer *self) { self->priv = NETWORK_SERVER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); } diff --git a/src/lib/bluez/serial.c b/src/lib/bluez/serial.c index 7cab666..8cd230a 100644 --- a/src/lib/bluez/serial.c +++ b/src/lib/bluez/serial.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -92,6 +92,9 @@ static void serial_init(Serial *self) { self->priv = SERIAL_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(system_conn != NULL); } diff --git a/src/lib/dbus-common.c b/src/lib/dbus-common.c index 1951131..91ee2c9 100644 --- a/src/lib/dbus-common.c +++ b/src/lib/dbus-common.c @@ -27,13 +27,14 @@ #include "bluez-api.h" #include "obexd-api.h" -#include "ods-api.h" #include "dbus-common.h" DBusGConnection *session_conn = NULL; DBusGConnection *system_conn = NULL; +static gboolean dbus_initialized = FALSE; + void dbus_init() { /* Marshallers registration @@ -41,19 +42,19 @@ void dbus_init() */ dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__INT_INT, G_TYPE_NONE, G_TYPE_INT, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_BOOLEAN, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__UINT64, G_TYPE_NONE, G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__BOXED_STRING_STRING, G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_object_register_marshaller(g_cclosure_bt_marshal_VOID__BOXED_BOOLEAN, G_TYPE_NONE, G_TYPE_VALUE, G_TYPE_BOOLEAN, G_TYPE_INVALID); /* Agents installation */ dbus_g_object_type_install_info(AGENT_TYPE, &dbus_glib_agent_object_info); dbus_g_object_type_install_info(OBEXAGENT_TYPE, &dbus_glib_obexagent_object_info); + + dbus_initialized = TRUE; } gboolean dbus_session_connect(GError **error) { + g_assert(dbus_initialized == TRUE); + session_conn = dbus_g_bus_get(DBUS_BUS_SESSION, error); if (!session_conn) { return FALSE; @@ -69,6 +70,8 @@ void dbus_session_disconnect() gboolean dbus_system_connect(GError **error) { + g_assert(dbus_initialized == TRUE); + system_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, error); if (!system_conn) { return FALSE; @@ -82,3 +85,11 @@ void dbus_system_disconnect() dbus_g_connection_unref(system_conn); } +void dbus_disconnect() +{ + if (system_conn) + dbus_g_connection_unref(system_conn); + if (session_conn) + dbus_g_connection_unref(session_conn); +} + diff --git a/src/lib/dbus-common.h b/src/lib/dbus-common.h index a6d979f..e0fcb9c 100644 --- a/src/lib/dbus-common.h +++ b/src/lib/dbus-common.h @@ -39,5 +39,6 @@ gboolean dbus_session_connect(GError **error); void dbus_session_disconnect(); gboolean dbus_system_connect(GError **error); void dbus_system_disconnect(); +void dbus_disconnect(); #endif /* __DBUS_COMMON_H */ diff --git a/src/lib/helpers.c b/src/lib/helpers.c index a310a97..7dc1b03 100644 --- a/src/lib/helpers.c +++ b/src/lib/helpers.c @@ -25,15 +25,13 @@ #include <config.h> #endif +#include <string.h> #include <glib.h> #include <dbus/dbus-glib.h> -#include <string.h> #include "dbus-common.h" #include "helpers.h" -#include "bluez-api.h" - /* UUID Name lookup table */ typedef struct { gchar *uuid; @@ -188,11 +186,8 @@ Adapter *find_adapter(const gchar *name, GError **error) Device *find_device(Adapter *adapter, const gchar *name, GError **error) { - g_assert(adapter != NULL); - g_assert(ADAPTER_IS(adapter)); - - g_assert(name); - g_assert(strlen(name) > 0); + g_assert(adapter != NULL && ADAPTER_IS(adapter)); + g_assert(name != NULL && strlen(name) > 0); gchar *device_path = NULL; Device *device = NULL; @@ -230,68 +225,25 @@ Device *find_device(Adapter *adapter, const gchar *name, GError **error) return device; } -gboolean intf_is_supported(const gchar *dbus_object_path, int intf_id) +gboolean intf_supported(const gchar *dbus_service_name, const gchar *dbus_object_path, const gchar *intf_name) { - g_assert(conn != NULL); - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - gboolean intf_supported = FALSE; - - gchar *check_intf_regex_str = NULL; - const gchar *dbus_service_name = NULL; - switch (intf_id) { - case DEVICE_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_DEVICE_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case AUDIO_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_AUDIO_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case INPUT_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_INPUT_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case NETWORK_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_NETWORK_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case NETWORK_HUB_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_NETWORK_HUB_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case NETWORK_PEER_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_NETWORK_PEER_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case NETWORK_ROUTER_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_NETWORK_ROUTER_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case SERIAL_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_SERIAL_INTERFACE, "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; - break; - case OBEXMANAGER_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_OBEXMANAGER_INTERFACE, "\">", NULL); - dbus_service_name = OBEX_DBUS_NAME; - break; - case OBEXSESSION_INRF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_OBEXSESSION_INTERFACE, "\">", NULL); - dbus_service_name = OBEX_DBUS_NAME; - break; - case OBEXSERVER_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_OBEXSERVER_INTERFACE, "\">", NULL); - dbus_service_name = OBEX_DBUS_NAME; - break; - case OBEXSERVER_SESSION_INTF: - check_intf_regex_str = g_strconcat("<interface name=\"", BLUEZ_DBUS_OBEXSERVER_SESSION_INTERFACE, "\">", NULL); - dbus_service_name = OBEX_DBUS_NAME; - break; - default: - check_intf_regex_str = g_strconcat("<interface name=\"", "undefined", "\">", NULL); - dbus_service_name = BLUEZ_DBUS_NAME; + g_assert(dbus_service_name != NULL && strlen(dbus_service_name) > 0); + g_assert(dbus_object_path != NULL && strlen(dbus_object_path) > 0); + g_assert(intf_name != NULL && strlen(intf_name) > 0); + + gboolean supported = FALSE; + DBusGConnection *conn = NULL; + + if (g_strcmp0(dbus_service_name, BLUEZ_DBUS_NAME) == 0) { + conn = system_conn; + } else if (g_strcmp0(dbus_service_name, OBEXD_DBUS_NAME) == 0) { + conn = session_conn; + } else { + return FALSE; } + g_assert(conn != NULL); + + gchar *check_intf_regex_str = g_strconcat("<interface name=\"", intf_name, "\">", NULL); /* Getting introspection XML */ DBusGProxy *introspection_g_proxy = dbus_g_proxy_new_for_name(conn, dbus_service_name, dbus_object_path, "org.freedesktop.DBus.Introspectable"); @@ -309,13 +261,13 @@ gboolean intf_is_supported(const gchar *dbus_object_path, int intf_id) g_assert(error == NULL); if (g_regex_match_simple(check_intf_regex_str, introspection_xml, 0, 0)) { - intf_supported = TRUE; + supported = TRUE; } g_free(check_intf_regex_str); g_free(introspection_xml); g_object_unref(introspection_g_proxy); - return intf_supported; + return supported; } diff --git a/src/lib/helpers.h b/src/lib/helpers.h index 5e1c573..c0b90f8 100644 --- a/src/lib/helpers.h +++ b/src/lib/helpers.h @@ -29,31 +29,12 @@ #include "bluez-api.h" #include "obexd-api.h" -#include "ods-api.h" -enum { - DEVICE_INTF, +/* DBus helpers */ +gboolean intf_supported(const gchar *dbus_service_name, const gchar *dbus_object_path, const gchar *intf_name); - /* BlueZ Interfaces */ - AUDIO_INTF, - INPUT_INTF, - NETWORK_INTF, - NETWORK_HUB_INTF, - NETWORK_PEER_INTF, - NETWORK_ROUTER_INTF, - SERIAL_INTF, - - /* OBEX Interfaces */ - OBEXMANAGER_INTF, - OBEXSESSION_INRF, - OBEXSERVER_INTF, - OBEXSERVER_SESSION_INTF, -}; - -/* Adapter helpers */ +/* BlueZ helpers */ Adapter *find_adapter(const gchar *name, GError **error); - -/* Device helpers */ Device *find_device(Adapter *adapter, const gchar *name, GError **error); /* Others helpers */ @@ -73,8 +54,5 @@ inline int xtoi(const gchar *str) const gchar *uuid2name(const gchar *uuid); const gchar *name2uuid(const gchar *name); -/* Interface helpers */ -gboolean intf_is_supported(const gchar *dbus_object_path, int intf_id); - #endif /* __HELPERS_H */ diff --git a/src/lib/marshallers.c b/src/lib/marshallers.c index 4fecca4..c88186e 100644 --- a/src/lib/marshallers.c +++ b/src/lib/marshallers.c @@ -375,7 +375,7 @@ g_cclosure_bt_marshal_VOID__INT_INT (GClosure *closure, data2); } -/* VOID:STRING,BOOLEAN (lib/marshallers.list:14) */ +/* VOID:STRING,BOOLEAN (lib/marshallers.list:16) */ void g_cclosure_bt_marshal_VOID__STRING_BOOLEAN (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -412,7 +412,44 @@ g_cclosure_bt_marshal_VOID__STRING_BOOLEAN (GClosure *closure, data2); } -/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:17) */ +/* VOID:BOXED,BOOLEAN (lib/marshallers.list:17) */ +void +g_cclosure_bt_marshal_VOID__BOXED_BOOLEAN (GClosure *closure, + GValue *return_value G_GNUC_UNUSED, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint G_GNUC_UNUSED, + gpointer marshal_data) +{ + typedef void (*GMarshalFunc_VOID__BOXED_BOOLEAN) (gpointer data1, + gpointer arg_1, + gboolean arg_2, + gpointer data2); + register GMarshalFunc_VOID__BOXED_BOOLEAN callback; + register GCClosure *cc = (GCClosure*) closure; + register gpointer data1, data2; + + g_return_if_fail (n_param_values == 3); + + if (G_CCLOSURE_SWAP_DATA (closure)) + { + data1 = closure->data; + data2 = g_value_peek_pointer (param_values + 0); + } + else + { + data1 = g_value_peek_pointer (param_values + 0); + data2 = closure->data; + } + callback = (GMarshalFunc_VOID__BOXED_BOOLEAN) (marshal_data ? marshal_data : cc->callback); + + callback (data1, + g_marshal_value_peek_boxed (param_values + 1), + g_marshal_value_peek_boolean (param_values + 2), + data2); +} + +/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:20) */ void g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -465,7 +502,7 @@ g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTE g_value_set_boolean (return_value, v_return); } -/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:20) */ +/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:23) */ void g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -508,7 +545,7 @@ g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER (GClosure *closure, g_value_set_boolean (return_value, v_return); } -/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:21) */ +/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:24) */ void g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER (GClosure *closure, GValue *return_value G_GNUC_UNUSED, @@ -549,192 +586,3 @@ g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER (GClosure *closure, g_value_set_boolean (return_value, v_return); } -/* VOID:STRING,STRING (lib/marshallers.list:25) */ -void -g_cclosure_bt_marshal_VOID__STRING_STRING (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 3); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__STRING_STRING) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - data2); -} - -/* VOID:UINT64 (lib/marshallers.list:26) */ -void -g_cclosure_bt_marshal_VOID__UINT64 (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__UINT64) (gpointer data1, - guint64 arg_1, - gpointer data2); - register GMarshalFunc_VOID__UINT64 callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 2); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__UINT64) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_uint64 (param_values + 1), - data2); -} - -/* VOID:STRING,STRING,UINT64 (lib/marshallers.list:27) */ -void -g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64 (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__STRING_STRING_UINT64) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - guint64 arg_3, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING_UINT64 callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 4); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__STRING_STRING_UINT64) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - g_marshal_value_peek_uint64 (param_values + 3), - data2); -} - -/* VOID:STRING,STRING,STRING (lib/marshallers.list:30) */ -void -g_cclosure_bt_marshal_VOID__STRING_STRING_STRING (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__STRING_STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_VOID__STRING_STRING_STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 4); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__STRING_STRING_STRING) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_string (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - g_marshal_value_peek_string (param_values + 3), - data2); -} - -/* VOID:BOXED,STRING,STRING (lib/marshallers.list:31) */ -void -g_cclosure_bt_marshal_VOID__BOXED_STRING_STRING (GClosure *closure, - GValue *return_value G_GNUC_UNUSED, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint G_GNUC_UNUSED, - gpointer marshal_data) -{ - typedef void (*GMarshalFunc_VOID__BOXED_STRING_STRING) (gpointer data1, - gpointer arg_1, - gpointer arg_2, - gpointer arg_3, - gpointer data2); - register GMarshalFunc_VOID__BOXED_STRING_STRING callback; - register GCClosure *cc = (GCClosure*) closure; - register gpointer data1, data2; - - g_return_if_fail (n_param_values == 4); - - if (G_CCLOSURE_SWAP_DATA (closure)) - { - data1 = closure->data; - data2 = g_value_peek_pointer (param_values + 0); - } - else - { - data1 = g_value_peek_pointer (param_values + 0); - data2 = closure->data; - } - callback = (GMarshalFunc_VOID__BOXED_STRING_STRING) (marshal_data ? marshal_data : cc->callback); - - callback (data1, - g_marshal_value_peek_boxed (param_values + 1), - g_marshal_value_peek_string (param_values + 2), - g_marshal_value_peek_string (param_values + 3), - data2); -} - diff --git a/src/lib/marshallers.h b/src/lib/marshallers.h index 3076e1c..510e605 100644 --- a/src/lib/marshallers.h +++ b/src/lib/marshallers.h @@ -70,7 +70,7 @@ extern void g_cclosure_bt_marshal_VOID__INT_INT (GClosure *closure, gpointer invocation_hint, gpointer marshal_data); -/* VOID:STRING,BOOLEAN (lib/marshallers.list:14) */ +/* VOID:STRING,BOOLEAN (lib/marshallers.list:16) */ extern void g_cclosure_bt_marshal_VOID__STRING_BOOLEAN (GClosure *closure, GValue *return_value, guint n_param_values, @@ -78,7 +78,15 @@ extern void g_cclosure_bt_marshal_VOID__STRING_BOOLEAN (GClosure *closure, gpointer invocation_hint, gpointer marshal_data); -/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:17) */ +/* VOID:BOXED,BOOLEAN (lib/marshallers.list:17) */ +extern void g_cclosure_bt_marshal_VOID__BOXED_BOOLEAN (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/* BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER (lib/marshallers.list:20) */ extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_POINTER_POINTER (GClosure *closure, GValue *return_value, guint n_param_values, @@ -86,7 +94,7 @@ extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_STRING_STRING_STRING_INT_INT_PO gpointer invocation_hint, gpointer marshal_data); -/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:20) */ +/* BOOLEAN:BOXED,UINT64,POINTER (lib/marshallers.list:23) */ extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER (GClosure *closure, GValue *return_value, guint n_param_values, @@ -94,7 +102,7 @@ extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_UINT64_POINTER (GClosure *c gpointer invocation_hint, gpointer marshal_data); -/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:21) */ +/* BOOLEAN:BOXED,POINTER (lib/marshallers.list:24) */ extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER (GClosure *closure, GValue *return_value, guint n_param_values, @@ -102,46 +110,6 @@ extern void g_cclosure_bt_marshal_BOOLEAN__BOXED_POINTER (GClosure *closure, gpointer invocation_hint, gpointer marshal_data); -/* VOID:STRING,STRING (lib/marshallers.list:25) */ -extern void g_cclosure_bt_marshal_VOID__STRING_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:UINT64 (lib/marshallers.list:26) */ -extern void g_cclosure_bt_marshal_VOID__UINT64 (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:STRING,STRING,UINT64 (lib/marshallers.list:27) */ -extern void g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64 (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:STRING,STRING,STRING (lib/marshallers.list:30) */ -extern void g_cclosure_bt_marshal_VOID__STRING_STRING_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - -/* VOID:BOXED,STRING,STRING (lib/marshallers.list:31) */ -extern void g_cclosure_bt_marshal_VOID__BOXED_STRING_STRING (GClosure *closure, - GValue *return_value, - guint n_param_values, - const GValue *param_values, - gpointer invocation_hint, - gpointer marshal_data); - G_END_DECLS #endif /* __g_cclosure_bt_marshal_MARSHAL_H__ */ diff --git a/src/lib/marshallers.list b/src/lib/marshallers.list index 21aed8c..87edb09 100644 --- a/src/lib/marshallers.list +++ b/src/lib/marshallers.list @@ -11,7 +11,10 @@ BOOLEAN:STRING,POINTER # [obexd] VOID:INT,INT + +# equals VOID:STRING,BOOLEAN +VOID:BOXED,BOOLEAN # Used by OBEXAgent BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER @@ -20,12 +23,3 @@ BOOLEAN:BOXED,STRING,STRING,STRING,INT,INT,POINTER,POINTER BOOLEAN:BOXED,UINT64,POINTER BOOLEAN:BOXED,POINTER #BOOLEAN:BOXED,STRING,POINTER - -# [ods] -VOID:STRING,STRING -VOID:UINT64 -VOID:STRING,STRING,UINT64 - -# equals -VOID:STRING,STRING,STRING -VOID:BOXED,STRING,STRING diff --git a/src/lib/obexd/obexagent.c b/src/lib/obexd/obexagent.c index cdf954c..dc98fba 100644 --- a/src/lib/obexd/obexagent.c +++ b/src/lib/obexd/obexagent.c @@ -31,6 +31,7 @@ #include <glib.h> #include "../dbus-common.h" +#include "../helpers.h" #include "obexclient_transfer.h" #include "obexagent.h" @@ -38,17 +39,44 @@ #define OBEXAGENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXAGENT_TYPE, OBEXAgentPrivate)) struct _OBEXAgentPrivate { + /* Unused */ DBusGProxy *proxy; + + /* Properties */ + gchar *root_folder; }; G_DEFINE_TYPE(OBEXAgent, obexagent, G_TYPE_OBJECT); +enum { + PROP_0, + + PROP_ROOT_FOLDER, /* readwrite, construct only */ +}; + +static void _obexagent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); +static void _obexagent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); + +enum { + OBEXAGENT_RELEASED, + + LAST_SIGNAL +}; + +static guint signals[LAST_SIGNAL] = {0}; + static void obexagent_dispose(GObject *gobject) { OBEXAgent *self = OBEXAGENT(gobject); dbus_g_connection_unregister_g_object(session_conn, gobject); + /* Proxy free */ + //g_object_unref(self->priv->proxy); + + /* Properties free */ + g_free(self->priv->root_folder); + /* Chain up to the parent class */ G_OBJECT_CLASS(obexagent_parent_class)->dispose(gobject); } @@ -60,34 +88,87 @@ static void obexagent_class_init(OBEXAgentClass *klass) gobject_class->dispose = obexagent_dispose; g_type_class_add_private(klass, sizeof(OBEXAgentPrivate)); + + /* Signals registation */ + signals[OBEXAGENT_RELEASED] = g_signal_new("AgentReleased", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + /* Properties registration */ + GParamSpec *pspec; + + gobject_class->get_property = _obexagent_get_property; + gobject_class->set_property = _obexagent_set_property; + + /* string RootFolder [readwrite, construct only] */ + pspec = g_param_spec_string("RootFolder", "root_folder", "Root folder location", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); + g_object_class_install_property(gobject_class, PROP_ROOT_FOLDER, pspec); } static void obexagent_init(OBEXAgent *self) { self->priv = OBEXAGENT_GET_PRIVATE(self); - g_assert(conn != NULL); + g_assert(session_conn != NULL); + + /* Properties init */ + self->priv->root_folder = NULL; dbus_g_connection_register_g_object(session_conn, OBEXAGENT_DBUS_PATH, G_OBJECT(self)); + g_print("OBEXAgent registered\n"); +} + +static void _obexagent_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) +{ + OBEXAgent *self = OBEXAGENT(object); - g_print("OBEX Agent registered\n"); + switch (property_id) { + case PROP_ROOT_FOLDER: + g_value_set_string(value, self->priv->root_folder); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + break; + } +} + +static void _obexagent_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) +{ + OBEXAgent *self = OBEXAGENT(object); + + switch (property_id) { + case PROP_ROOT_FOLDER: + self->priv->root_folder = g_value_dup_string(value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); + break; + } } /* Methods */ -/* Agent API */ +/* Server API */ gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *bt_address, const gchar *name, const gchar *type, gint length, gint time, gchar **ret, GError **error) { + g_assert(self->priv->root_folder != NULL && strlen(self->priv->root_folder)); + *ret = NULL; - g_print("[Bluetooth ObjectPush request]\n"); - OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print(" Transfer: %s (%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); - g_object_unref(transfer_obj); + g_print("[ObjectPush Request]\n"); g_print(" Address: %s\n", bt_address); g_print(" Name: %s\n", name); - g_print(" Type: %s\n", type); - g_print(" Length: %d\n", length); - g_print(" Time: %d\n", time); + if (type && strlen(type)) { + g_print(" Type: %s\n", type); + } + g_print(" Length: %d bytes\n", length); + /*if (time) { + g_print(" Time: %d\n", time); + }*/ gchar yn[4] = {0,}; g_print("Accept (yes/no)? "); @@ -96,7 +177,16 @@ gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar g_warning("%s\n", strerror(errno)); } if (g_strcmp0(yn, "y") == 0 || g_strcmp0(yn, "yes") == 0) { - *ret = g_strdup("/home/zak/obp.ext"); + if (!g_path_is_absolute(self->priv->root_folder)) { + gchar *current_dir = g_get_current_dir(); + gchar *end_path = g_build_filename(self->priv->root_folder, name, NULL); + *ret = g_build_filename(current_dir, end_path, NULL); + g_free(current_dir); + g_free(end_path); + } else { + *ret = g_build_filename(self->priv->root_folder, name, NULL); + } + return TRUE; } else { // TODO: Fix error code @@ -104,8 +194,6 @@ gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *error = g_error_new(g_quark_from_static_string("org.openobex.Error.Rejected"), 0, "File transfer rejected"); return FALSE; } - - return TRUE; } gboolean obexagent_cancel(OBEXAgent *self, GError **error) @@ -117,16 +205,22 @@ gboolean obexagent_cancel(OBEXAgent *self, GError **error) /* Client API */ gboolean obexagent_release(OBEXAgent *self, GError **error) { - g_print("OBEX Agent released\n"); + g_print("OBEXAgent released\n"); + + g_signal_emit(self, signals[OBEXAGENT_RELEASED], 0); + return TRUE; } gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, GError **error) { *ret = NULL; - OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("Transfer: %s (%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); - g_object_unref(transfer_obj); + OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("[Transfer Request]\n"); + g_print(" Name: %s\n", obexclient_transfer_get_name(transfer_t)); + g_print(" Size: %llu bytes\n", obexclient_transfer_get_size(transfer_t)); + g_print(" Filename: %s\n", obexclient_transfer_get_filename(transfer_t)); + g_object_unref(transfer_t); gchar yn[4] = {0,}; g_print("Accept (yes/no)? "); @@ -148,27 +242,43 @@ gboolean obexagent_request(OBEXAgent *self, const gchar *transfer, gchar **ret, gboolean obexagent_progress(OBEXAgent *self, const gchar *transfer, guint64 transferred, GError **error) { - OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("Transfer progress: %s (%llu/%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), transferred, obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); - g_object_unref(transfer_obj); + OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + guint64 total = obexclient_transfer_get_size(transfer_t); + + guint pp = (transferred / (gfloat) total)*100; + + static gboolean update_progress = FALSE; + if (!update_progress) { + g_print("[Transfer#%s] Progress: %3u%%", obexclient_transfer_get_filename(transfer_t), pp); + update_progress = TRUE; + } else { + g_print("\b\b\b\b%3u%%", pp); + } + + if (pp == 100) { + g_print("\n"); + update_progress = FALSE; + } + + g_object_unref(transfer_t); return TRUE; } gboolean obexagent_complete(OBEXAgent *self, const gchar *transfer, GError **error) { - OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("Transfer complete: %s (%llu bytes), %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj)); - g_object_unref(transfer_obj); + OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("[Transfer#%s] Completed\n", obexclient_transfer_get_filename(transfer_t)); + g_object_unref(transfer_t); return TRUE; } gboolean obexagent_error(OBEXAgent *self, const gchar *transfer, const gchar *message, GError **error) { - OBEXClientTransfer *transfer_obj = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); - g_print("Transfer error: %s (%llu bytes), %s: %s\n", obexclient_transfer_get_name(transfer_obj), obexclient_transfer_get_size(transfer_obj), obexclient_transfer_get_filename(transfer_obj), message); - g_object_unref(transfer_obj); + OBEXClientTransfer *transfer_t = g_object_new(OBEXCLIENT_TRANSFER_TYPE, "DBusObjectPath", transfer, NULL); + g_print("[Transfer#%s] Error: %s\n", obexclient_transfer_get_filename(transfer_t), message); + g_object_unref(transfer_t); return TRUE; } diff --git a/src/lib/obexd/obexagent.h b/src/lib/obexd/obexagent.h index 997ac6d..b94fb2c 100644 --- a/src/lib/obexd/obexagent.h +++ b/src/lib/obexd/obexagent.h @@ -63,7 +63,7 @@ GType obexagent_get_type(void) G_GNUC_CONST; * Method definitions */ -/* Agent API */ +/* Server API */ gboolean obexagent_authorize(OBEXAgent *self, const gchar *transfer, const gchar *bt_address, const gchar *name, const gchar *type, gint length, gint time, gchar **ret, GError **error); gboolean obexagent_cancel(OBEXAgent *self, GError **error); diff --git a/src/lib/obexd/obexclient.c b/src/lib/obexd/obexclient.c index ba78633..1a15c93 100644 --- a/src/lib/obexd/obexclient.c +++ b/src/lib/obexd/obexclient.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -73,6 +73,9 @@ static void obexclient_init(OBEXClient *self) { self->priv = OBEXCLIENT_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); GError *error = NULL; diff --git a/src/lib/obexd/obexclient_file_transfer.c b/src/lib/obexd/obexclient_file_transfer.c index 60f44dd..e15de6c 100644 --- a/src/lib/obexd/obexclient_file_transfer.c +++ b/src/lib/obexd/obexclient_file_transfer.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -92,6 +92,9 @@ static void obexclient_file_transfer_init(OBEXClientFileTransfer *self) { self->priv = OBEXCLIENT_FILE_TRANSFER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); } diff --git a/src/lib/obexd/obexclient_session.c b/src/lib/obexd/obexclient_session.c index 810536c..8702d39 100644 --- a/src/lib/obexd/obexclient_session.c +++ b/src/lib/obexd/obexclient_session.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -116,6 +116,9 @@ static void obexclient_session_init(OBEXClientSession *self) { self->priv = OBEXCLIENT_SESSION_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); } diff --git a/src/lib/obexd/obexclient_transfer.c b/src/lib/obexd/obexclient_transfer.c index 04f7444..b3e7560 100644 --- a/src/lib/obexd/obexclient_transfer.c +++ b/src/lib/obexd/obexclient_transfer.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -116,6 +116,9 @@ static void obexclient_transfer_init(OBEXClientTransfer *self) { self->priv = OBEXCLIENT_TRANSFER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); } diff --git a/src/lib/obexd/obexmanager.c b/src/lib/obexd/obexmanager.c index f17292d..3a6d368 100644 --- a/src/lib/obexd/obexmanager.c +++ b/src/lib/obexd/obexmanager.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -124,6 +124,9 @@ static void obexmanager_init(OBEXManager *self) { self->priv = OBEXMANAGER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); GError *error = NULL; diff --git a/src/lib/obexd/obexsession.c b/src/lib/obexd/obexsession.c index 8883c1d..fa80e02 100644 --- a/src/lib/obexd/obexsession.c +++ b/src/lib/obexd/obexsession.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -103,6 +103,9 @@ static void obexsession_init(OBEXSession *self) { self->priv = OBEXSESSION_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); } diff --git a/src/lib/obexd/obextransfer.c b/src/lib/obexd/obextransfer.c index bb08db9..59556e4 100644 --- a/src/lib/obexd/obextransfer.c +++ b/src/lib/obexd/obextransfer.c @@ -25,8 +25,8 @@ #include <config.h> #endif -#include <glib.h> #include <string.h> +#include <glib.h> #include "../dbus-common.h" #include "../marshallers.h" @@ -113,6 +113,9 @@ static void obextransfer_init(OBEXTransfer *self) { self->priv = OBEXTRANSFER_GET_PRIVATE(self); + /* DBusGProxy init */ + self->priv->dbus_g_proxy = NULL; + g_assert(session_conn != NULL); } diff --git a/src/lib/ods-api.h b/src/lib/ods-api.h deleted file mode 100644 index b0644f3..0000000 --- a/src/lib/ods-api.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __ODS_API_H -#define __ODS_API_H - -/* Global includes */ -#include <glib.h> -#include <dbus/dbus-glib.h> - -#define ODS_DBUS_NAME "org.openobex" - -/* ODS DBus API */ -#include "ods/obexmanager.h" -#include "ods/obexserver.h" -#include "ods/obexserver_session.h" -#include "ods/obexsession.h" - -#endif /* __ODS_API_H */ - diff --git a/src/lib/ods/obexmanager.c b/src/lib/ods/obexmanager.c deleted file mode 100644 index 3eb7b10..0000000 --- a/src/lib/ods/obexmanager.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <string.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexmanager.h" - -#define OBEXMANAGER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXMANAGER_TYPE, OBEXManagerPrivate)) - -struct _OBEXManagerPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXManager, obexmanager, G_TYPE_OBJECT); - -enum { - SESSION_CLOSED, - SESSION_CONNECT_ERROR, - SESSION_CONNECTED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void session_closed_handler(DBusGProxy *dbus_g_proxy, const gchar *path, gpointer data); -static void session_connect_error_handler(DBusGProxy *dbus_g_proxy, const gchar *path, const gchar *error_name, const gchar *error_message, gpointer data); -static void session_connected_handler(DBusGProxy *dbus_g_proxy, const gchar *path, gpointer data); - -static void obexmanager_dispose(GObject *gobject) -{ - OBEXManager *self = OBEXMANAGER(gobject); - - /* DBus signals disconnection */ - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionClosed", G_CALLBACK(session_closed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionConnectError", G_CALLBACK(session_connect_error_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionConnected", G_CALLBACK(session_connected_handler), self); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexmanager_parent_class)->dispose(gobject); -} - -static void obexmanager_class_init(OBEXManagerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexmanager_dispose; - - g_type_class_add_private(klass, sizeof(OBEXManagerPrivate)); - - /* Signals registation */ - signals[SESSION_CLOSED] = g_signal_new("SessionClosed", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - signals[SESSION_CONNECT_ERROR] = g_signal_new("SessionConnectError", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_STRING_STRING, - G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - - signals[SESSION_CONNECTED] = g_signal_new("SessionConnected", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); -} - -static void obexmanager_init(OBEXManager *self) -{ - self->priv = OBEXMANAGER_GET_PRIVATE(self); - - g_assert(system_conn != NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", OBEXMANAGER_DBUS_PATH, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXMANAGER_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXMANAGER_DBUS_INTERFACE, OBEXMANAGER_DBUS_PATH); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", OBEXMANAGER_DBUS_PATH, OBEXMANAGER_DBUS_INTERFACE); - - /* DBus signals connection */ - - /* SessionClosed(object path) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionClosed", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionClosed", G_CALLBACK(session_closed_handler), self, NULL); - - /* SessionConnectError(object path, string error_name, string error_message) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionConnectError", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionConnectError", G_CALLBACK(session_connect_error_handler), self, NULL); - - /* SessionConnected(object path) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionConnected", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionConnected", G_CALLBACK(session_connected_handler), self, NULL); -} - -/* Methods */ - -/* boolean CancelSessionConnect(object session_object) */ -gboolean obexmanager_cancel_session_connect(OBEXManager *self, const gchar *session_object, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - gboolean ret = FALSE; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CancelSessionConnect", error, DBUS_TYPE_G_OBJECT_PATH, session_object, G_TYPE_INVALID, G_TYPE_BOOLEAN, &ret, G_TYPE_INVALID); - - return ret; -} - -/* object CreateBluetoothServer(string source_address, string pattern, boolean require_pairing) */ -gchar *obexmanager_create_bluetooth_server(OBEXManager *self, const gchar *source_address, const gchar *pattern, const gboolean require_pairing, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateBluetoothServer", error, G_TYPE_STRING, source_address, G_TYPE_STRING, pattern, G_TYPE_BOOLEAN, require_pairing, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID); - - return ret; -} - -/* object CreateBluetoothSession(string target_address, string source_address, string pattern) */ -gchar *obexmanager_create_bluetooth_session(OBEXManager *self, const gchar *target_address, const gchar *source_address, const gchar *pattern, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateBluetoothSession", error, G_TYPE_STRING, target_address, G_TYPE_STRING, source_address, G_TYPE_STRING, pattern, G_TYPE_INVALID, DBUS_TYPE_G_OBJECT_PATH, &ret, G_TYPE_INVALID); - - return ret; -} - -/* dict{s,s} GetServerInfo(object server_object) */ -GHashTable *obexmanager_get_server_info(OBEXManager *self, const gchar *server_object, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetServerInfo", error, DBUS_TYPE_G_OBJECT_PATH, server_object, G_TYPE_INVALID, DBUS_TYPE_G_STRING_STRING_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* array{string} GetServerList() */ -gchar **obexmanager_get_server_list(OBEXManager *self, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - gchar **ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetServerList", error, G_TYPE_INVALID, G_TYPE_STRV, &ret, G_TYPE_INVALID); - - return ret; -} - -/* dict{s,s} GetSessionInfo(object session_object) */ -GHashTable *obexmanager_get_session_info(OBEXManager *self, const gchar *session_object, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetSessionInfo", error, DBUS_TYPE_G_OBJECT_PATH, session_object, G_TYPE_INVALID, DBUS_TYPE_G_STRING_STRING_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* array{string} GetSessionList() */ -gchar **obexmanager_get_session_list(OBEXManager *self, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - gchar **ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetSessionList", error, G_TYPE_INVALID, G_TYPE_STRV, &ret, G_TYPE_INVALID); - - return ret; -} - -/* string GetVersion() */ -gchar *obexmanager_get_version(OBEXManager *self, GError **error) -{ - g_assert(OBEXMANAGER_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetVersion", error, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID); - - return ret; -} - -/* Signals handlers */ -static void session_closed_handler(DBusGProxy *dbus_g_proxy, const gchar *path, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[SESSION_CLOSED], 0, path); -} - -static void session_connect_error_handler(DBusGProxy *dbus_g_proxy, const gchar *path, const gchar *error_name, const gchar *error_message, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[SESSION_CONNECT_ERROR], 0, path, error_name, error_message); -} - -static void session_connected_handler(DBusGProxy *dbus_g_proxy, const gchar *path, gpointer data) -{ - OBEXManager *self = OBEXMANAGER(data); - - g_signal_emit(self, signals[SESSION_CONNECTED], 0, path); -} - diff --git a/src/lib/ods/obexmanager.h b/src/lib/ods/obexmanager.h deleted file mode 100644 index 20e12ea..0000000 --- a/src/lib/ods/obexmanager.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXMANAGER_H -#define __OBEXMANAGER_H - -#include <glib-object.h> - -#define OBEXMANAGER_DBUS_PATH "/org/openobex" -#define OBEXMANAGER_DBUS_INTERFACE "org.openobex.Manager" - -/* - * Type macros - */ -#define OBEXMANAGER_TYPE (obexmanager_get_type()) -#define OBEXMANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXMANAGER_TYPE, OBEXManager)) -#define OBEXMANAGER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXMANAGER_TYPE)) -#define OBEXMANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXMANAGER_TYPE, OBEXManagerClass)) -#define OBEXMANAGER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXMANAGER_TYPE)) -#define OBEXMANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXMANAGER_TYPE, OBEXManagerClass)) - -typedef struct _OBEXManager OBEXManager; -typedef struct _OBEXManagerClass OBEXManagerClass; -typedef struct _OBEXManagerPrivate OBEXManagerPrivate; - -struct _OBEXManager { - GObject parent_instance; - - /*< private >*/ - OBEXManagerPrivate *priv; -}; - -struct _OBEXManagerClass { - GObjectClass parent_class; -}; - -/* used by OBEXMANAGER_TYPE */ -GType obexmanager_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -gboolean obexmanager_cancel_session_connect(OBEXManager *self, const gchar *session_object, GError **error); -gchar *obexmanager_create_bluetooth_server(OBEXManager *self, const gchar *source_address, const gchar *pattern, const gboolean require_pairing, GError **error); -gchar *obexmanager_create_bluetooth_session(OBEXManager *self, const gchar *target_address, const gchar *source_address, const gchar *pattern, GError **error); -GHashTable *obexmanager_get_server_info(OBEXManager *self, const gchar *server_object, GError **error); -gchar **obexmanager_get_server_list(OBEXManager *self, GError **error); -GHashTable *obexmanager_get_session_info(OBEXManager *self, const gchar *session_object, GError **error); -gchar **obexmanager_get_session_list(OBEXManager *self, GError **error); -gchar *obexmanager_get_version(OBEXManager *self, GError **error); - -#endif /* __OBEXMANAGER_H */ - diff --git a/src/lib/ods/obexserver.c b/src/lib/ods/obexserver.c deleted file mode 100644 index ab968b2..0000000 --- a/src/lib/ods/obexserver.c +++ /dev/null @@ -1,373 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <string.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexserver.h" - -#define OBEXSERVER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSERVER_TYPE, OBEXServerPrivate)) - -struct _OBEXServerPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXServer, obexserver, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH /* readwrite, construct only */ -}; - -static void _obexserver_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexserver_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -enum { - CLOSED, - ERROR_OCCURRED, - SESSION_CREATED, - SESSION_REMOVED, - STARTED, - STOPPED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void closed_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void error_occurred_handler(DBusGProxy *dbus_g_proxy, const gchar *error_name, const gchar *error_message, gpointer data); -static void session_created_handler(DBusGProxy *dbus_g_proxy, const gchar *session_object, gpointer data); -static void session_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *session_object, gpointer data); -static void started_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void stopped_handler(DBusGProxy *dbus_g_proxy, gpointer data); - -static void obexserver_dispose(GObject *gobject) -{ - OBEXServer *self = OBEXSERVER(gobject); - - /* DBus signals disconnection */ - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Closed", G_CALLBACK(closed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_CALLBACK(error_occurred_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionCreated", G_CALLBACK(session_created_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "SessionRemoved", G_CALLBACK(session_removed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Started", G_CALLBACK(started_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Stopped", G_CALLBACK(stopped_handler), self); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexserver_parent_class)->dispose(gobject); -} - -static void obexserver_class_init(OBEXServerClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexserver_dispose; - - g_type_class_add_private(klass, sizeof(OBEXServerPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexserver_get_property; - gobject_class->set_property = _obexserver_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* Signals registation */ - signals[CLOSED] = g_signal_new("Closed", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[ERROR_OCCURRED] = g_signal_new("ErrorOccurred", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); - - signals[SESSION_CREATED] = g_signal_new("SessionCreated", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - signals[SESSION_REMOVED] = g_signal_new("SessionRemoved", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - signals[STARTED] = g_signal_new("Started", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[STOPPED] = g_signal_new("Stopped", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void obexserver_init(OBEXServer *self) -{ - self->priv = OBEXSERVER_GET_PRIVATE(self); - - g_assert(system_conn != NULL); -} - -static void obexserver_post_init(OBEXServer *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSERVER_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSERVER_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, OBEXSERVER_DBUS_INTERFACE); - - /* DBus signals connection */ - - /* Closed() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Closed", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Closed", G_CALLBACK(closed_handler), self, NULL); - - /* ErrorOccurred(string error_name, string error_message) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_CALLBACK(error_occurred_handler), self, NULL); - - /* SessionCreated(object session_object) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionCreated", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionCreated", G_CALLBACK(session_created_handler), self, NULL); - - /* SessionRemoved(object session_object) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "SessionRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "SessionRemoved", G_CALLBACK(session_removed_handler), self, NULL); - - /* Started() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Started", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Started", G_CALLBACK(started_handler), self, NULL); - - /* Stopped() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Stopped", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Stopped", G_CALLBACK(stopped_handler), self, NULL); -} - -static void _obexserver_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXServer *self = OBEXSERVER(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexserver_get_dbus_object_path(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexserver_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXServer *self = OBEXSERVER(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexserver_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void Close() */ -void obexserver_close(OBEXServer *self, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Close", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* dict{s,s} GetServerSessionInfo(object session_object) */ -GHashTable *obexserver_get_server_session_info(OBEXServer *self, const gchar *session_object, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetServerSessionInfo", error, DBUS_TYPE_G_OBJECT_PATH, session_object, G_TYPE_INVALID, DBUS_TYPE_G_STRING_STRING_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* array{string} GetServerSessionList() */ -gchar **obexserver_get_server_session_list(OBEXServer *self, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - gchar **ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetServerSessionList", error, G_TYPE_INVALID, G_TYPE_STRV, &ret, G_TYPE_INVALID); - - return ret; -} - -/* boolean IsStarted() */ -gboolean obexserver_is_started(OBEXServer *self, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - gboolean ret = FALSE; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "IsStarted", error, G_TYPE_INVALID, G_TYPE_BOOLEAN, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void SetOption(string name, variant value) */ -void obexserver_set_option(OBEXServer *self, const gchar *name, const GValue *value, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SetOption", error, G_TYPE_STRING, name, G_TYPE_VALUE, value, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Start(string path, boolean allow_write, boolean auto_accept) */ -void obexserver_start(OBEXServer *self, const gchar *path, const gboolean allow_write, const gboolean auto_accept, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Start", error, G_TYPE_STRING, path, G_TYPE_BOOLEAN, allow_write, G_TYPE_BOOLEAN, auto_accept, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Stop() */ -void obexserver_stop(OBEXServer *self, GError **error) -{ - g_assert(OBEXSERVER_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Stop", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *obexserver_get_dbus_object_path(OBEXServer *self) -{ - g_assert(OBEXSERVER_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -/* Signals handlers */ -static void closed_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXServer *self = OBEXSERVER(data); - - g_signal_emit(self, signals[CLOSED], 0); -} - -static void error_occurred_handler(DBusGProxy *dbus_g_proxy, const gchar *error_name, const gchar *error_message, gpointer data) -{ - OBEXServer *self = OBEXSERVER(data); - - g_signal_emit(self, signals[ERROR_OCCURRED], 0, error_name, error_message); -} - -static void session_created_handler(DBusGProxy *dbus_g_proxy, const gchar *session_object, gpointer data) -{ - OBEXServer *self = OBEXSERVER(data); - - g_signal_emit(self, signals[SESSION_CREATED], 0, session_object); -} - -static void session_removed_handler(DBusGProxy *dbus_g_proxy, const gchar *session_object, gpointer data) -{ - OBEXServer *self = OBEXSERVER(data); - - g_signal_emit(self, signals[SESSION_REMOVED], 0, session_object); -} - -static void started_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXServer *self = OBEXSERVER(data); - - g_signal_emit(self, signals[STARTED], 0); -} - -static void stopped_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXServer *self = OBEXSERVER(data); - - g_signal_emit(self, signals[STOPPED], 0); -} - diff --git a/src/lib/ods/obexserver.h b/src/lib/ods/obexserver.h deleted file mode 100644 index f4a3c60..0000000 --- a/src/lib/ods/obexserver.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXSERVER_H -#define __OBEXSERVER_H - -#include <glib-object.h> - -#define OBEXSERVER_DBUS_INTERFACE "org.openobex.Server" - -/* - * Type macros - */ -#define OBEXSERVER_TYPE (obexserver_get_type()) -#define OBEXSERVER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXSERVER_TYPE, OBEXServer)) -#define OBEXSERVER_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXSERVER_TYPE)) -#define OBEXSERVER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXSERVER_TYPE, OBEXServerClass)) -#define OBEXSERVER_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXSERVER_TYPE)) -#define OBEXSERVER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXSERVER_TYPE, OBEXServerClass)) - -typedef struct _OBEXServer OBEXServer; -typedef struct _OBEXServerClass OBEXServerClass; -typedef struct _OBEXServerPrivate OBEXServerPrivate; - -struct _OBEXServer { - GObject parent_instance; - - /*< private >*/ - OBEXServerPrivate *priv; -}; - -struct _OBEXServerClass { - GObjectClass parent_class; -}; - -/* used by OBEXSERVER_TYPE */ -GType obexserver_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexserver_close(OBEXServer *self, GError **error); -GHashTable *obexserver_get_server_session_info(OBEXServer *self, const gchar *session_object, GError **error); -gchar **obexserver_get_server_session_list(OBEXServer *self, GError **error); -gboolean obexserver_is_started(OBEXServer *self, GError **error); -void obexserver_set_option(OBEXServer *self, const gchar *name, const GValue *value, GError **error); -void obexserver_start(OBEXServer *self, const gchar *path, const gboolean allow_write, const gboolean auto_accept, GError **error); -void obexserver_stop(OBEXServer *self, GError **error); - -const gchar *obexserver_get_dbus_object_path(OBEXServer *self); - -#endif /* __OBEXSERVER_H */ - diff --git a/src/lib/ods/obexserver_session.c b/src/lib/ods/obexserver_session.c deleted file mode 100644 index 5920517..0000000 --- a/src/lib/ods/obexserver_session.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <string.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexserver_session.h" - -#define OBEXSERVER_SESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSERVER_SESSION_TYPE, OBEXServerSessionPrivate)) - -struct _OBEXServerSessionPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXServerSession, obexserver_session, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH /* readwrite, construct only */ -}; - -static void _obexserver_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexserver_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -enum { - CANCELLED, - DISCONNECTED, - ERROR_OCCURRED, - TRANSFER_COMPLETED, - TRANSFER_PROGRESS, - TRANSFER_STARTED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void cancelled_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void disconnected_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void error_occurred_handler(DBusGProxy *dbus_g_proxy, const gchar *error_name, const gchar *error_message, gpointer data); -static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void transfer_progress_handler(DBusGProxy *dbus_g_proxy, const guint64 bytes_transferred, gpointer data); -static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *filename, const gchar *local_path, const guint64 total_bytes, gpointer data); - -static void obexserver_session_dispose(GObject *gobject) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(gobject); - - /* DBus signals disconnection */ - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Cancelled", G_CALLBACK(cancelled_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Disconnected", G_CALLBACK(disconnected_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_CALLBACK(error_occurred_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferProgress", G_CALLBACK(transfer_progress_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexserver_session_parent_class)->dispose(gobject); -} - -static void obexserver_session_class_init(OBEXServerSessionClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexserver_session_dispose; - - g_type_class_add_private(klass, sizeof(OBEXServerSessionPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexserver_session_get_property; - gobject_class->set_property = _obexserver_session_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* Signals registation */ - signals[CANCELLED] = g_signal_new("Cancelled", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[DISCONNECTED] = g_signal_new("Disconnected", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[ERROR_OCCURRED] = g_signal_new("ErrorOccurred", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); - - signals[TRANSFER_COMPLETED] = g_signal_new("TransferCompleted", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[TRANSFER_PROGRESS] = g_signal_new("TransferProgress", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__UINT64, - G_TYPE_NONE, 1, G_TYPE_UINT64); - - signals[TRANSFER_STARTED] = g_signal_new("TransferStarted", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64, - G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64); -} - -static void obexserver_session_init(OBEXServerSession *self) -{ - self->priv = OBEXSERVER_SESSION_GET_PRIVATE(self); - - g_assert(system_conn != NULL); -} - -static void obexserver_session_post_init(OBEXServerSession *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSERVER_SESSION_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSERVER_SESSION_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, OBEXSERVER_SESSION_DBUS_INTERFACE); - - /* DBus signals connection */ - - /* Cancelled() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Cancelled", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Cancelled", G_CALLBACK(cancelled_handler), self, NULL); - - /* Disconnected() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Disconnected", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Disconnected", G_CALLBACK(disconnected_handler), self, NULL); - - /* ErrorOccurred(string error_name, string error_message) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_CALLBACK(error_occurred_handler), self, NULL); - - /* TransferCompleted() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self, NULL); - - /* TransferProgress(uint64 bytes_transferred) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferProgress", G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferProgress", G_CALLBACK(transfer_progress_handler), self, NULL); - - /* TransferStarted(string filename, string local_path, uint64 total_bytes) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferStarted", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self, NULL); -} - -static void _obexserver_session_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexserver_session_get_dbus_object_path(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexserver_session_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexserver_session_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void Accept() */ -void obexserver_session_accept(OBEXServerSession *self, GError **error) -{ - g_assert(OBEXSERVER_SESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Accept", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Cancel() */ -void obexserver_session_cancel(OBEXServerSession *self, GError **error) -{ - g_assert(OBEXSERVER_SESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Cancel", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Disconnect() */ -void obexserver_session_disconnect(OBEXServerSession *self, GError **error) -{ - g_assert(OBEXSERVER_SESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* dict{s,s} GetTransferInfo() */ -GHashTable *obexserver_session_get_transfer_info(OBEXServerSession *self, GError **error) -{ - g_assert(OBEXSERVER_SESSION_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetTransferInfo", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_STRING_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void Reject() */ -void obexserver_session_reject(OBEXServerSession *self, GError **error) -{ - g_assert(OBEXSERVER_SESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Reject", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *obexserver_session_get_dbus_object_path(OBEXServerSession *self) -{ - g_assert(OBEXSERVER_SESSION_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -/* Signals handlers */ -static void cancelled_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(data); - - g_signal_emit(self, signals[CANCELLED], 0); -} - -static void disconnected_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(data); - - g_signal_emit(self, signals[DISCONNECTED], 0); -} - -static void error_occurred_handler(DBusGProxy *dbus_g_proxy, const gchar *error_name, const gchar *error_message, gpointer data) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(data); - - g_signal_emit(self, signals[ERROR_OCCURRED], 0, error_name, error_message); -} - -static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(data); - - g_signal_emit(self, signals[TRANSFER_COMPLETED], 0); -} - -static void transfer_progress_handler(DBusGProxy *dbus_g_proxy, const guint64 bytes_transferred, gpointer data) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(data); - - g_signal_emit(self, signals[TRANSFER_PROGRESS], 0, bytes_transferred); -} - -static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *filename, const gchar *local_path, const guint64 total_bytes, gpointer data) -{ - OBEXServerSession *self = OBEXSERVER_SESSION(data); - - g_signal_emit(self, signals[TRANSFER_STARTED], 0, filename, local_path, total_bytes); -} - diff --git a/src/lib/ods/obexserver_session.h b/src/lib/ods/obexserver_session.h deleted file mode 100644 index c1be188..0000000 --- a/src/lib/ods/obexserver_session.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXSERVER_SESSION_H -#define __OBEXSERVER_SESSION_H - -#include <glib-object.h> - -#define OBEXSERVER_SESSION_DBUS_INTERFACE "org.openobex.ServerSession" - -/* - * Type macros - */ -#define OBEXSERVER_SESSION_TYPE (obexserver_session_get_type()) -#define OBEXSERVER_SESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXSERVER_SESSION_TYPE, OBEXServerSession)) -#define OBEXSERVER_SESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXSERVER_SESSION_TYPE)) -#define OBEXSERVER_SESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXSERVER_SESSION_TYPE, OBEXServerSessionClass)) -#define OBEXSERVER_SESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXSERVER_SESSION_TYPE)) -#define OBEXSERVER_SESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXSERVER_SESSION_TYPE, OBEXServerSessionClass)) - -typedef struct _OBEXServerSession OBEXServerSession; -typedef struct _OBEXServerSessionClass OBEXServerSessionClass; -typedef struct _OBEXServerSessionPrivate OBEXServerSessionPrivate; - -struct _OBEXServerSession { - GObject parent_instance; - - /*< private >*/ - OBEXServerSessionPrivate *priv; -}; - -struct _OBEXServerSessionClass { - GObjectClass parent_class; -}; - -/* used by OBEXSERVER_SESSION_TYPE */ -GType obexserver_session_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexserver_session_accept(OBEXServerSession *self, GError **error); -void obexserver_session_cancel(OBEXServerSession *self, GError **error); -void obexserver_session_disconnect(OBEXServerSession *self, GError **error); -GHashTable *obexserver_session_get_transfer_info(OBEXServerSession *self, GError **error); -void obexserver_session_reject(OBEXServerSession *self, GError **error); - -const gchar *obexserver_session_get_dbus_object_path(OBEXServerSession *self); - -#endif /* __OBEXSERVER_SESSION_H */ - diff --git a/src/lib/ods/obexsession.c b/src/lib/ods/obexsession.c deleted file mode 100644 index 2fde069..0000000 --- a/src/lib/ods/obexsession.c +++ /dev/null @@ -1,496 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <string.h> - -#include "../dbus-common.h" -#include "../marshallers.h" - -#include "obexsession.h" - -#define OBEXSESSION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), OBEXSESSION_TYPE, OBEXSessionPrivate)) - -struct _OBEXSessionPrivate { - DBusGProxy *dbus_g_proxy; - - /* Introspection data */ - DBusGProxy *introspection_g_proxy; - gchar *introspection_xml; -}; - -G_DEFINE_TYPE(OBEXSession, obexsession, G_TYPE_OBJECT); - -enum { - PROP_0, - - PROP_DBUS_OBJECT_PATH /* readwrite, construct only */ -}; - -static void _obexsession_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec); -static void _obexsession_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec); - -enum { - CANCELLED, - CLOSED, - DISCONNECTED, - ERROR_OCCURRED, - TRANSFER_COMPLETED, - TRANSFER_PROGRESS, - TRANSFER_STARTED, - - LAST_SIGNAL -}; - -static guint signals[LAST_SIGNAL] = {0}; - -static void cancelled_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void closed_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void disconnected_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void error_occurred_handler(DBusGProxy *dbus_g_proxy, const gchar *error_name, const gchar *error_message, gpointer data); -static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, gpointer data); -static void transfer_progress_handler(DBusGProxy *dbus_g_proxy, const guint64 bytes_transferred, gpointer data); -static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *filename, const gchar *local_path, const guint64 total_bytes, gpointer data); - -static void obexsession_dispose(GObject *gobject) -{ - OBEXSession *self = OBEXSESSION(gobject); - - /* DBus signals disconnection */ - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Cancelled", G_CALLBACK(cancelled_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Closed", G_CALLBACK(closed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "Disconnected", G_CALLBACK(disconnected_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_CALLBACK(error_occurred_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferProgress", G_CALLBACK(transfer_progress_handler), self); - dbus_g_proxy_disconnect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self); - - /* Proxy free */ - g_object_unref(self->priv->dbus_g_proxy); - - /* Introspection data free */ - g_free(self->priv->introspection_xml); - g_object_unref(self->priv->introspection_g_proxy); - - /* Chain up to the parent class */ - G_OBJECT_CLASS(obexsession_parent_class)->dispose(gobject); -} - -static void obexsession_class_init(OBEXSessionClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - - gobject_class->dispose = obexsession_dispose; - - g_type_class_add_private(klass, sizeof(OBEXSessionPrivate)); - - /* Properties registration */ - GParamSpec *pspec; - - gobject_class->get_property = _obexsession_get_property; - gobject_class->set_property = _obexsession_set_property; - - /* object DBusObjectPath [readwrite, construct only] */ - pspec = g_param_spec_string("DBusObjectPath", "dbus_object_path", "Adapter D-Bus object path", NULL, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY); - g_object_class_install_property(gobject_class, PROP_DBUS_OBJECT_PATH, pspec); - - /* Signals registation */ - signals[CANCELLED] = g_signal_new("Cancelled", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[CLOSED] = g_signal_new("Closed", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[DISCONNECTED] = g_signal_new("Disconnected", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[ERROR_OCCURRED] = g_signal_new("ErrorOccurred", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_STRING, - G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRING); - - signals[TRANSFER_COMPLETED] = g_signal_new("TransferCompleted", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - - signals[TRANSFER_PROGRESS] = g_signal_new("TransferProgress", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__UINT64, - G_TYPE_NONE, 1, G_TYPE_UINT64); - - signals[TRANSFER_STARTED] = g_signal_new("TransferStarted", - G_TYPE_FROM_CLASS(gobject_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, - g_cclosure_bt_marshal_VOID__STRING_STRING_UINT64, - G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64); -} - -static void obexsession_init(OBEXSession *self) -{ - self->priv = OBEXSESSION_GET_PRIVATE(self); - - g_assert(system_conn != NULL); -} - -static void obexsession_post_init(OBEXSession *self, const gchar *dbus_object_path) -{ - g_assert(dbus_object_path != NULL); - g_assert(strlen(dbus_object_path) > 0); - g_assert(self->priv->dbus_g_proxy == NULL); - - GError *error = NULL; - - /* Getting introspection XML */ - self->priv->introspection_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, "org.freedesktop.DBus.Introspectable"); - self->priv->introspection_xml = NULL; - if (!dbus_g_proxy_call(self->priv->introspection_g_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &self->priv->introspection_xml, G_TYPE_INVALID)) { - g_critical("%s", error->message); - } - g_assert(error == NULL); - - gchar *check_intf_regex_str = g_strconcat("<interface name=\"", OBEXSESSION_DBUS_INTERFACE, "\">", NULL); - if (!g_regex_match_simple(check_intf_regex_str, self->priv->introspection_xml, 0, 0)) { - g_critical("Interface \"%s\" does not exist in \"%s\"", OBEXSESSION_DBUS_INTERFACE, dbus_object_path); - g_assert(FALSE); - } - g_free(check_intf_regex_str); - self->priv->dbus_g_proxy = dbus_g_proxy_new_for_name(system_conn, "org.openobex", dbus_object_path, OBEXSESSION_DBUS_INTERFACE); - - /* DBus signals connection */ - - /* Cancelled() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Cancelled", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Cancelled", G_CALLBACK(cancelled_handler), self, NULL); - - /* Closed() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Closed", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Closed", G_CALLBACK(closed_handler), self, NULL); - - /* Disconnected() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "Disconnected", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "Disconnected", G_CALLBACK(disconnected_handler), self, NULL); - - /* ErrorOccurred(string error_name, string error_message) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "ErrorOccurred", G_CALLBACK(error_occurred_handler), self, NULL); - - /* TransferCompleted() */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferCompleted", G_CALLBACK(transfer_completed_handler), self, NULL); - - /* TransferProgress(uint64 bytes_transferred) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferProgress", G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferProgress", G_CALLBACK(transfer_progress_handler), self, NULL); - - /* TransferStarted(string filename, string local_path, uint64 total_bytes) */ - dbus_g_proxy_add_signal(self->priv->dbus_g_proxy, "TransferStarted", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT64, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(self->priv->dbus_g_proxy, "TransferStarted", G_CALLBACK(transfer_started_handler), self, NULL); -} - -static void _obexsession_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) -{ - OBEXSession *self = OBEXSESSION(object); - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - g_value_set_string(value, obexsession_get_dbus_object_path(self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } -} - -static void _obexsession_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) -{ - OBEXSession *self = OBEXSESSION(object); - GError *error = NULL; - - switch (property_id) { - case PROP_DBUS_OBJECT_PATH: - obexsession_post_init(self, g_value_get_string(value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); - break; - } - - if (error != NULL) { - g_critical("%s", error->message); - } - g_assert(error == NULL); -} - -/* Methods */ - -/* void Cancel() */ -void obexsession_cancel(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Cancel", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void ChangeCurrentFolder(string path) */ -void obexsession_change_current_folder(OBEXSession *self, const gchar *path, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ChangeCurrentFolder", error, G_TYPE_STRING, path, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void ChangeCurrentFolderBackward() */ -void obexsession_change_current_folder_backward(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ChangeCurrentFolderBackward", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void ChangeCurrentFolderToRoot() */ -void obexsession_change_current_folder_to_root(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "ChangeCurrentFolderToRoot", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Close() */ -void obexsession_close(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Close", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void CopyRemoteFile(string remote_filename, string local_path) */ -void obexsession_copy_remote_file(OBEXSession *self, const gchar *remote_filename, const gchar *local_path, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CopyRemoteFile", error, G_TYPE_STRING, remote_filename, G_TYPE_STRING, local_path, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void CopyRemoteFileByType(string type, string local_path) */ -void obexsession_copy_remote_file_by_type(OBEXSession *self, const gchar *type, const gchar *local_path, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CopyRemoteFileByType", error, G_TYPE_STRING, type, G_TYPE_STRING, local_path, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void CreateFolder(string folder_name) */ -void obexsession_create_folder(OBEXSession *self, const gchar *folder_name, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "CreateFolder", error, G_TYPE_STRING, folder_name, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void DeleteRemoteFile(string remote_filename) */ -void obexsession_delete_remote_file(OBEXSession *self, const gchar *remote_filename, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "DeleteRemoteFile", error, G_TYPE_STRING, remote_filename, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void Disconnect() */ -void obexsession_disconnect(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "Disconnect", error, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* string GetCapability() */ -gchar *obexsession_get_capability(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetCapability", error, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID); - - return ret; -} - -/* string GetCurrentPath() */ -gchar *obexsession_get_current_path(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetCurrentPath", error, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID); - - return ret; -} - -/* dict{s,s} GetTransferInfo() */ -GHashTable *obexsession_get_transfer_info(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - GHashTable *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "GetTransferInfo", error, G_TYPE_INVALID, DBUS_TYPE_G_STRING_STRING_HASHTABLE, &ret, G_TYPE_INVALID); - - return ret; -} - -/* boolean IsBusy() */ -gboolean obexsession_is_busy(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - gboolean ret = FALSE; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "IsBusy", error, G_TYPE_INVALID, G_TYPE_BOOLEAN, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void RemoteCopy(string remote_source, string remote_destination) */ -void obexsession_remote_copy(OBEXSession *self, const gchar *remote_source, const gchar *remote_destination, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "RemoteCopy", error, G_TYPE_STRING, remote_source, G_TYPE_STRING, remote_destination, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void RemoteMove(string remote_source, string remote_destination) */ -void obexsession_remote_move(OBEXSession *self, const gchar *remote_source, const gchar *remote_destination, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "RemoteMove", error, G_TYPE_STRING, remote_source, G_TYPE_STRING, remote_destination, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* string RetrieveFolderListing() */ -gchar *obexsession_retrieve_folder_listing(OBEXSession *self, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - gchar *ret = NULL; - dbus_g_proxy_call(self->priv->dbus_g_proxy, "RetrieveFolderListing", error, G_TYPE_INVALID, G_TYPE_STRING, &ret, G_TYPE_INVALID); - - return ret; -} - -/* void SendFile(string local_path) */ -void obexsession_send_file(OBEXSession *self, const gchar *local_path, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SendFile", error, G_TYPE_STRING, local_path, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* void SendFileExt(string local_path, string remote_filename, string type) */ -void obexsession_send_file_ext(OBEXSession *self, const gchar *local_path, const gchar *remote_filename, const gchar *type, GError **error) -{ - g_assert(OBEXSESSION_IS(self)); - - dbus_g_proxy_call(self->priv->dbus_g_proxy, "SendFileExt", error, G_TYPE_STRING, local_path, G_TYPE_STRING, remote_filename, G_TYPE_STRING, type, G_TYPE_INVALID, G_TYPE_INVALID); -} - -/* Properties access methods */ -const gchar *obexsession_get_dbus_object_path(OBEXSession *self) -{ - g_assert(OBEXSESSION_IS(self)); - - return dbus_g_proxy_get_path(self->priv->dbus_g_proxy); -} - -/* Signals handlers */ -static void cancelled_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[CANCELLED], 0); -} - -static void closed_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[CLOSED], 0); -} - -static void disconnected_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[DISCONNECTED], 0); -} - -static void error_occurred_handler(DBusGProxy *dbus_g_proxy, const gchar *error_name, const gchar *error_message, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[ERROR_OCCURRED], 0, error_name, error_message); -} - -static void transfer_completed_handler(DBusGProxy *dbus_g_proxy, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[TRANSFER_COMPLETED], 0); -} - -static void transfer_progress_handler(DBusGProxy *dbus_g_proxy, const guint64 bytes_transferred, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[TRANSFER_PROGRESS], 0, bytes_transferred); -} - -static void transfer_started_handler(DBusGProxy *dbus_g_proxy, const gchar *filename, const gchar *local_path, const guint64 total_bytes, gpointer data) -{ - OBEXSession *self = OBEXSESSION(data); - - g_signal_emit(self, signals[TRANSFER_STARTED], 0, filename, local_path, total_bytes); -} - diff --git a/src/lib/ods/obexsession.h b/src/lib/ods/obexsession.h deleted file mode 100644 index 93289bf..0000000 --- a/src/lib/ods/obexsession.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * bluez-tools - a set of tools to manage bluetooth devices for linux - * - * Copyright (C) 2010 Alexander Orlenko <zxteam@gmail.com> - * - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __OBEXSESSION_H -#define __OBEXSESSION_H - -#include <glib-object.h> - -#define OBEXSESSION_DBUS_INTERFACE "org.openobex.Session" - -/* - * Type macros - */ -#define OBEXSESSION_TYPE (obexsession_get_type()) -#define OBEXSESSION(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), OBEXSESSION_TYPE, OBEXSession)) -#define OBEXSESSION_IS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), OBEXSESSION_TYPE)) -#define OBEXSESSION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), OBEXSESSION_TYPE, OBEXSessionClass)) -#define OBEXSESSION_IS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), OBEXSESSION_TYPE)) -#define OBEXSESSION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), OBEXSESSION_TYPE, OBEXSessionClass)) - -typedef struct _OBEXSession OBEXSession; -typedef struct _OBEXSessionClass OBEXSessionClass; -typedef struct _OBEXSessionPrivate OBEXSessionPrivate; - -struct _OBEXSession { - GObject parent_instance; - - /*< private >*/ - OBEXSessionPrivate *priv; -}; - -struct _OBEXSessionClass { - GObjectClass parent_class; -}; - -/* used by OBEXSESSION_TYPE */ -GType obexsession_get_type(void) G_GNUC_CONST; - -/* - * Method definitions - */ -void obexsession_cancel(OBEXSession *self, GError **error); -void obexsession_change_current_folder(OBEXSession *self, const gchar *path, GError **error); -void obexsession_change_current_folder_backward(OBEXSession *self, GError **error); -void obexsession_change_current_folder_to_root(OBEXSession *self, GError **error); -void obexsession_close(OBEXSession *self, GError **error); -void obexsession_copy_remote_file(OBEXSession *self, const gchar *remote_filename, const gchar *local_path, GError **error); -void obexsession_copy_remote_file_by_type(OBEXSession *self, const gchar *type, const gchar *local_path, GError **error); -void obexsession_create_folder(OBEXSession *self, const gchar *folder_name, GError **error); -void obexsession_delete_remote_file(OBEXSession *self, const gchar *remote_filename, GError **error); -void obexsession_disconnect(OBEXSession *self, GError **error); -gchar *obexsession_get_capability(OBEXSession *self, GError **error); -gchar *obexsession_get_current_path(OBEXSession *self, GError **error); -GHashTable *obexsession_get_transfer_info(OBEXSession *self, GError **error); -gboolean obexsession_is_busy(OBEXSession *self, GError **error); -void obexsession_remote_copy(OBEXSession *self, const gchar *remote_source, const gchar *remote_destination, GError **error); -void obexsession_remote_move(OBEXSession *self, const gchar *remote_source, const gchar *remote_destination, GError **error); -gchar *obexsession_retrieve_folder_listing(OBEXSession *self, GError **error); -void obexsession_send_file(OBEXSession *self, const gchar *local_path, GError **error); -void obexsession_send_file_ext(OBEXSession *self, const gchar *local_path, const gchar *remote_filename, const gchar *type, GError **error); - -const gchar *obexsession_get_dbus_object_path(OBEXSession *self); - -#endif /* __OBEXSESSION_H */ - |