diff options
author | Philipp Schmidt <philschmidt@gmx.net> | 2013-07-14 11:39:25 +0200 |
---|---|---|
committer | Philipp Schmidt <philschmidt@gmx.net> | 2013-07-14 11:39:25 +0200 |
commit | 35e3ca39894ead43c9839dd523233ff72d5bec7b (patch) | |
tree | 44d7d7b8c7e6e1ebaffe22eb4c3f787647f12789 | |
parent | 903ea5d96de75715327318fcf203f9d0218ec6ac (diff) | |
download | libmtp-35e3ca39894ead43c9839dd523233ff72d5bec7b.tar.gz |
Initial daemon code, alter gdbus-codegen call, add interface
-rw-r--r-- | daemon/Makefile.am | 7 | ||||
-rw-r--r-- | daemon/dbus-interface.xml | 334 | ||||
-rw-r--r-- | daemon/mtpd.c | 57 |
3 files changed, 390 insertions, 8 deletions
diff --git a/daemon/Makefile.am b/daemon/Makefile.am index bfc2a8f..6ba6108 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -17,8 +17,11 @@ BUILT_SOURCES = $(dbus_built_sources) $(dbus_built_sources) : Makefile.am dbus-interface.xml $(AM_V_GEN) gdbus-codegen \ - --interface-prefix org.libmtp. \ - --c-namespace MTP \ + --interface-prefix org.libmtp.mtpd. \ + --c-namespace MTPD \ + --c-generate-object-manager \ + --generate-c-code mtp-dbus \ + --generate-docbook generated-docs \ --generate-c-code mtp-dbus \ $(srcdir)/dbus-interface.xml \ $(NULL) diff --git a/daemon/dbus-interface.xml b/daemon/dbus-interface.xml index dc5badb..6d0cd6d 100644 --- a/daemon/dbus-interface.xml +++ b/daemon/dbus-interface.xml @@ -4,8 +4,9 @@ <!-- DBus Interface to libmtp - + Copyright (C) 2013 Philip Langdale <philipl@overt.org> + Copyright (C) 2013 Philipp Schmidt <philschmidt@gmx.net> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -24,8 +25,335 @@ --> <node name="/" xmlns:doc="http://www.freedesktop.org/dbus/1.0/doc.dtd"> - <interface name='org.libmtp'> - </interface> + <!-- org.libmtp.mtpd.Devices: + @short_description: MTP device access API + + This D-Bus interface is used to access MTP devices. + --> + <interface name="org.libmtp.mtpd.device"> + + <!-- listDevices: The currently discovered and connected devices in the deamon. + @devices: A list of the currently accessible devices represented as an array containing structs with the deviceID, Modelname and Friendlyname. + --> + <method name="listDevices"> + <arg direction="out" type="a(iss)" name="devices" /> + </method> + + <!-- setFriendlyname: Rename the device + @deviceID: The id of the device for which to set the name + @name: The string the Friendlyname property shall be set to + --> + <method name="setFriendlyname"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="s" name="name" /> + </method> + + <!-- listStorages: The storages for a device with the given deviceID. + @deviceID: The id of the device for which to get the storages + @storages: A list of the storages found on the device. The result is presented as an array containing a struct with the storageID, StorageDescription and VolumeIdentifier. + --> + <method name="listStorages"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="out" type="a(iss)" name="storages" /> + </method> + + <!-- getMetadataForDevice: The metadata for a device with the given deviceID. + @deviceID: The id of the device for which to get the metadata + @params: TODO + --> + <method name="getMetadataForDevice"> + <arg direction="in" type="i" name="deviceID" /> + + <arg direction="out" type="s" name="modelName" /> + <arg direction="out" type="s" name="friendlyName" /> + <arg direction="out" type="(ii)" name="usbBusDev" /> + <arg direction="out" type="i" name="vendorID" /> + <arg direction="out" type="s" name="vendorName" /> + <arg direction="out" type="i" name="productID" /> + <arg direction="out" type="s" name="productName" /> + <arg direction="out" type="i" name="deviceFlags" /> + <arg direction="out" type="(iiiiiiii)" name="defaultFolders" /> + <arg direction="out" type="a(sii)" name="deviceExtensions" /> + </method> + + <!-- getMetadataForStorage: The metadata for a device with the given deviceID. + @deviceID: The id of the device which holds the storage + @storageID: The id of the device for which to get the metadata + @params: TODO + --> + <method name="getMetadataForStorage"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="storageID" /> + + <arg direction="out" type="s" name="storageDescription" /> + <arg direction="out" type="s" name="volumeIdentifier" /> + <arg direction="out" type="n" name="storageType" /> + <arg direction="out" type="n" name="filesystemType" /> + <arg direction="out" type="n" name="accessCapability" /> + <arg direction="out" type="x" name="maxCapacity" /> + <arg direction="out" type="x" name="freeSpaceInBytes" /> + <arg direction="out" type="x" name="freeSpaceInObjects" /> + </method> + + <!-- formatStorage: Deletes all data on a storage on a device by formatting it. + @deviceID: The id of the device which holds the storage + @storageID: The id of the storage to format + --> + <method name="formatStorage"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="storageID" /> + </method> + + <!-- getBatteryLevel: The storages for a device with the given deviceID. + @deviceID: The id of the device for which to get the storages + @result: 0 for success, else failure, probably because the underlying property is not supported + @currentLevel: The current battery level + @maximumLevel: The maximum battery level + --> + <method name="getBatteryLevel"> + <arg direction="in" type="i" name="deviceID" /> + + <arg direction="out" type="i" name="result" /> + <arg direction="out" type="y" name="currentLevel" /> + <arg direction="out" type="y" name="maximumLevel" /> + </method> + + <!-- TODO + * LIBMTP_Get_String_From_Object + * LIBMTP_Get_u64_From_Object + * LIBMTP_Get_u32_From_Object + * LIBMTP_Get_u16_From_Object + * LIBMTP_Get_u8_From_Object + * LIBMTP_Set_Object_String + * LIBMTP_Set_Object_u32 + * LIBMTP_Set_Object_u16 + * LIBMTP_Set_Object_u8 + * LIBMTP_Get_Property_Description + * LIBMTP_Is_Property_Supported + * LIBMTP_Get_Allowed_Property_Values + --> + + </interface> + + <!-- org.libmtp.mtpd.Files: + @short_description: MTP file access API + + This D-Bus interface offers the LIBMTP file management API. + --> + <interface name="org.libmtp.mtpd.file"> + <!-- TODO + LIBMTP_Get_Filelisting + --> + + <!-- + getFilesAndFolders: + @deviceID: The id of the device wich contains the requested file. + @deviceID: The id of the requested file. + @result: The result of the operation. 0 if successful, else not. + @listFileStructs: A list of found files. May be empty if no files were found and no error was reported. The struct follows the + LIBMTP_file_struct definitions with some exceptions: + * item_id: unchanged + * parent_id: unchanged + * storage_id: unchanged + * filename: represented as string + * filesize: unchanged + * modificationsdate: represented as an int64 + * filetype: converted to a mime-string + * next: omitted as it is not necessary in a list + --> + <method name="getFilesAndFolders"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="fileID" /> + + <arg direction="out" type="i" name="result" /> + <arg direction="out" type="a(iiisxxs)" name="listFileStructs" /> + </method> + + <!-- + getFileToFileDescriptor: + @deviceID: The id of the device which has the file + @fileID: The ID of the file on the device to be copied to the FD + @fileDescriptorTarget: The unix file descriptor to copy to + @transactionID: Custom ID to be used with the device ID for watching the transaction progress + + @result: The result code for the operation + --> + <method name="getFileToFileDescriptor"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="fileID" /> + <arg direction="in" type="h" name="fileDescriptorTarget" /> + <arg direction="in" type="i" name="transactionID" /> + + <arg direction="out" type="i" name="result" /> + </method> + + <!-- + getFileFromFileDescriptor: + @deviceID: The id of the device which has the file + @fileDescriptorSource: The unix file descriptor to copy from + @transactionID: Custom ID to be used with the device ID for watching the transaction progress + + @result: The result code for the operation + @fileID: The fileID of the copied file on the device + --> + <method name="getFileFromFileDescriptor"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="h" name="fileDescriptorSource" /> + <arg direction="in" type="i" name="transactionID" /> + + <arg direction="out" type="i" name="result" /> + <arg direction="out" type="i" name="newFileID" /> + </method> + + <!-- + copyProgress: Signal is emitted when a progress update has been issued by LIBMTP. Applies only to copy operations. + @deviceOD: The id of the device of the transaction + @transactionID: The custom id of the transaction + @transferredBytes: Currently transferred bytes + @totalBytes: Total number of bytes to transfer + --> + <signal name="copyProgress"> + <arg type="i" name="deviceID"/> + <arg type="i" name="transactionID"/> + <arg type="x" name="transferredBytes"/> + <arg type="x" name="totalBytes"/> + </signal> + + <!-- + getFileMetadata: + @deviceID: The id of the device which has the file + @fileID: The fileID of file on the device + + @result: The result code for the operation + @parentID: fileID of the parent of this file + @storageID: ID of the storage the file is on + @name: Actual name of the file + @size: Size of the file on the device + @modificationsdate: Last modification date (time_t represented as an + int64) + @mimetype: MIME-type of the file + --> + <method name="getFileMetadata"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="fileID" /> + + <arg direction="out" type="i" name="result" /> + <arg direction="out" type="i" name="parentID" /> + <arg direction="out" type="i" name="storageID" /> + <arg direction="out" type="s" name="name" /> + <arg direction="out" type="x" name="size" /> + <arg direction="out" type="x" name="modificationdate" /> + <arg direction="out" type="s" name="mimetype" /> + </method> + + <!-- + setFileName: + @deviceID: The id of the device wich contains the file. + @fileID: The id of the file. + @newName: The new name of the file + @result: The result of the operation. 0 if successful, else not. + --> + <method name="setFileName"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="fileID" /> + <arg direction="in" type="s" name="newName" /> + + <arg direction="out" type="i" name="result" /> + </method> + + <!-- + setFileName: + @deviceID: The id of the device wich contains the file. + @fileID: The id of the file. + @result: The result of the operation. 0 if successful, else not. + @thumbnail: The thumbnail as a byte-array + --> + <method name="getThumbnail"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="fileID" /> + + <arg direction="out" type="i" name="result" /> + <arg direction="out" type="ab" name="thumbnail" /> + </method> + + </interface> + + <!-- org.libmtp.mtpd.folder: + @short_description: MTP folder management API + + This D-Bus interface is used to manage folders on a MTP device. + --> + <interface name="org.libmtp.mtpd.folder"> + <!-- To be defined + LIBMTP_Get_Folder_List + LIBMTP_Get_Folder_List_For_Storage + --> + + <!-- + createFolder: + @deviceID: The id of the device wich contains the file. + @parentID: The id of the parent folder. + @name: The name of the new folder + @result: The result of the operation. 0 if successful, else not. + + DEVELOPER INFO (remove later): storageID can be extracted from the parent folder + --> + <method name="createFolder"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="parentID" /> + <arg direction="in" type="s" name="name" /> + + <arg direction="out" type="i" name="result" /> + </method> + + <!-- + setFolderName: + @deviceID: The id of the device wich contains the file. + @folderID: The id of the file. + @newName: The new name of the file + @result: The result of the operation. 0 if successful, else not. + --> + <method name="setFolderName"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="folderID" /> + <arg direction="in" type="s" name="newName" /> + + <arg direction="out" type="i" name="result" /> + </method> + + </interface> + + <!-- org.libmtp.mtpd.object: + @short_description: MTP object access API + + This D-Bus interface offers the LIBMTP object management API. + --> + <interface name="org.libmtp.mtpd.object"> + <!-- TODO + LIBMTP_GetPartialObject + LIBMTP_SendPartialObject + LIBMTP_BeginEditObject + LIBMTP_EndEditObject + LIBMTP_TruncateObject + + !!! LIBMTP_Set_Object_Filename is deprecated, will not be used (Use + setFilename/setFoldername etc. instead) + --> + + <!-- + deleteObject: + @deviceID: The id of the device wich contains the object. + @objectID: The id of the object. + @result: The result of the operation. 0 if successful, else not. + --> + <method name="deleteObject"> + <arg direction="in" type="i" name="deviceID" /> + <arg direction="in" type="i" name="objectID" /> + + <arg direction="out" type="i" name="result" /> + </method> + + </interface> </node> diff --git a/daemon/mtpd.c b/daemon/mtpd.c index 7ff54e2..e9e2fd3 100644 --- a/daemon/mtpd.c +++ b/daemon/mtpd.c @@ -20,8 +20,59 @@ */ +#include <unistd.h> +#include <signal.h> +#include <syslog.h> + +void +signal_handler(int sig) { + + switch(sig) { + case SIGHUP: + // We can safely ignore this as we are a daemon + break; + + case SIGTERM: + case SIGQUIT: + // Graceful shutdown + + //TODO + + break; + + default: + // Don't react on any other signals + break; + } +} + int -main (int argc, char *argv[]) -{ - return 0; +main(int argc, char **argv) { + + // Set up signal handlers + signal(SIGHUP, signal_handler); + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + signal(SIGQUIT, signal_handler); + + openlog( "LIBMTP_daemon", + LOG_PID | LOG_CONS | LOG_NDELAY, LOG_DAEMON ); + + syslog(LOG_INFO, "Daemoninsing"); + + int daemon_err = daemon(0, 0); + + if (daemon_err < 0) + syslog(LOG_ERR, "Error daemonising"); + + /* + * Set up the actual stuff. E.g. dbus service, udev service, init connected devices (if any) + */ + + pause(); + + closelog(); + + return 0; } + |