summaryrefslogtreecommitdiffstats
path: root/src/libtdeobex
diff options
context:
space:
mode:
Diffstat (limited to 'src/libtdeobex')
-rw-r--r--src/libtdeobex/CMakeLists.txt66
-rw-r--r--src/libtdeobex/interfaces/CMakeLists.txt103
-rw-r--r--src/libtdeobex/obexobjectmanagerImpl.cpp286
-rw-r--r--src/libtdeobex/obexobjectmanagerImpl.h94
4 files changed, 549 insertions, 0 deletions
diff --git a/src/libtdeobex/CMakeLists.txt b/src/libtdeobex/CMakeLists.txt
new file mode 100644
index 0000000..c998ff0
--- /dev/null
+++ b/src/libtdeobex/CMakeLists.txt
@@ -0,0 +1,66 @@
+#################################################
+#
+# (C) 2018 Emanoil Kotsev
+# deloptes (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+project( libtdeobex )
+set(LIBRARY_VERSION 0.0.1)
+
+# include( ConfigureChecks.cmake )
+foreach( f ${TQT_LIBRARIES} )
+ if( ${f} STREQUAL "tqt-mt" )
+ set(TQUI_LIBRARIES "tqui" CACHE TYPE STRING FORCE)
+ endif()
+ if( ${f} STREQUAL "qt-mt" )
+ set(TQUI_LIBRARIES "qui" CACHE TYPE STRING FORCE)
+ endif()
+endforeach()
+
+# import required
+#tde_import( lib... )
+
+add_subdirectory( interfaces )
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}
+ ${CMAKE_SOURCE_DIR}
+ ${TDE_INCLUDE_DIR}
+ ${TQT_INCLUDE_DIRS}
+ ${DBUS_INCLUDE_DIRS}
+ ${DBUS_TQT_INCLUDE_DIRS}
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+##### headers ###################################
+# implementations
+install(
+ FILES obexobjectmanagerImpl.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/tdeobex )
+
+set( target tdeobex )
+
+set( ${target}_SRCS obexobjectmanagerImpl.cpp )
+
+
+##### tdeobex (shared) ###########################
+# set( KDE3_DCOPIDL_EXECUTABLE ${KDE3_DCOPIDLNG_EXECUTABLE} )
+tde_add_library( ${target} SHARED AUTOMOC
+ SOURCES ${${target}_SRCS}
+ VERSION ${LIBRARY_VERSION}
+ DEPENDS obexinterfaces-static
+ LINK ${DBUS_TQT_LIBRARIES} tdeparts-shared obexinterfaces-static ${TQUI_LIBRARIES}
+ DESTINATION ${LIB_INSTALL_DIR}
+ )
+
+##### install import cmake modules ###############
+tde_install_export( )
diff --git a/src/libtdeobex/interfaces/CMakeLists.txt b/src/libtdeobex/interfaces/CMakeLists.txt
new file mode 100644
index 0000000..60a9659
--- /dev/null
+++ b/src/libtdeobex/interfaces/CMakeLists.txt
@@ -0,0 +1,103 @@
+#################################################
+#
+# (C) 2020 Emanoil Kotsev
+# deloptes (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${TQT_INCLUDE_DIRS}
+ ${DBUS_TQT_INCLUDE_DIRS}
+)
+
+set( INTROSPECTIONPATH ${CMAKE_SOURCE_DIR}/src/interfaces )
+set( DBUSXML2QT3_EXECUTABLE dbusxml2qt3 )
+
+function( make_moc fileinput )
+ add_custom_command( OUTPUT ${fileinput}.moc
+ COMMAND ${TMOC_EXECUTABLE} ${fileinput}.h -o ${fileinput}.moc
+ DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.h
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ )
+ set_property( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.cpp APPEND
+ PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.moc )
+endfunction( )
+
+set( ObjectManager_HDRS objectmanagerInterface.h objectmanagerProxy.h introspectableInterface.h )
+set( ObjectManager_SRCS objectmanagerInterface.cpp objectmanagerProxy.cpp introspectableInterface.cpp )
+
+set (Agent_HDRS agent1Interface.h agent1Proxy.h dbusbaseNode.h tdeobexNode.h)
+set (Agent_SRCS agent1Interface.cpp agent1Proxy.cpp dbusbaseNode.cpp tdeobexNode.cpp)
+
+set (Client_HDRS agentmanager1Interface.h agentmanager1Proxy.h client1Interface.h client1Proxy.h filetransfer1Interface.h filetransfer1Proxy.h obexNode.h objectpush1Interface.h objectpush1Proxy.h phonebookaccess1Interface.h phonebookaccess1Proxy.h session1Interface.h session1Proxy.h synchronization1Interface.h synchronization1Proxy.h transfer1Interface.h transfer1Proxy.h)
+set (Client_SRCS agentmanager1Interface.cpp agentmanager1Proxy.cpp client1Interface.cpp client1Proxy.cpp filetransfer1Interface.cpp filetransfer1Proxy.cpp obexNode.cpp objectpush1Interface.cpp objectpush1Proxy.cpp phonebookaccess1Interface.cpp phonebookaccess1Proxy.cpp session1Interface.cpp session1Proxy.cpp synchronization1Interface.cpp synchronization1Proxy.cpp transfer1Interface.cpp transfer1Proxy.cpp propertiesProxy.h propertiesProxy.cpp )
+
+
+##### ObjectManager #########################
+add_custom_command(
+ OUTPUT ${ObjectManager_HDRS} ${ObjectManager_SRCS}
+ COMMAND ${DBUSXML2QT3_EXECUTABLE} ${INTROSPECTIONPATH}/org.freedesktop.DBus.ObjectManager.xml 2>/dev/null
+ DEPENDS ${INTROSPECTIONPATH}/org.freedesktop.DBus.ObjectManager.xml
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+make_moc ( objectmanagerProxy )
+
+##### Agent #########################
+add_custom_command(
+ OUTPUT ${Agent_HDRS} ${Agent_SRCS}
+ COMMAND ${DBUSXML2QT3_EXECUTABLE} ${INTROSPECTIONPATH}/org.bluez.obex.Agent1.xml 2>/dev/null
+ DEPENDS ${INTROSPECTIONPATH}/org.bluez.obex.Agent1.xml
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+make_moc ( agent1Proxy )
+
+##### Client #########################
+add_custom_command(
+ OUTPUT ${Client_HDRS} ${Client_SRCS}
+ COMMAND ${DBUSXML2QT3_EXECUTABLE} ${INTROSPECTIONPATH}/org.bluez.obex.client.xml 2>/dev/null
+ DEPENDS ${INTROSPECTIONPATH}/org.bluez.obex.client.xml
+ WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+)
+make_moc ( agentmanager1Proxy )
+make_moc ( client1Proxy )
+make_moc ( filetransfer1Proxy )
+make_moc ( objectpush1Proxy )
+make_moc ( phonebookaccess1Proxy )
+make_moc ( session1Proxy )
+make_moc ( synchronization1Proxy )
+make_moc ( transfer1Proxy )
+make_moc ( propertiesProxy )
+
+tde_add_library( obexinterfaces STATIC_PIC AUTOMOC
+ SOURCES ${ObjectManager_SRCS} ${Agent_SRCS} ${Client_SRCS}
+ LINK ${DBUS_TQT_LIBRARIES}
+)
+
+##### headers ###################################
+
+#file( GLOB _bin_dirs RELATIVE ${CMAKE_CURRENT_BINARY_DIR}
+#      ${CMAKE_CURRENT_BINARY_DIR}/* )
+#unset( _exclude_dirs )
+#foreach( _dir IN LISTS _bin_dirs )
+#  if( IS_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_dir} )
+#    list( APPEND _exclude_dirs PATTERN ${_dir} EXCLUDE )
+#  endif()
+#endforeach()
+#
+#install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+# DESTINATION ${INCLUDE_INSTALL_DIR}/tdeobex
+# USE_SOURCE_PERMISSIONS
+# FILES_MATCHING PATTERN PATTERN "*.h"
+# ${_exclude_dirs}
+#)
+
+install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
+ DESTINATION ${INCLUDE_INSTALL_DIR}/tdeobex
+ USE_SOURCE_PERMISSIONS
+ FILES_MATCHING PATTERN PATTERN "*.h"
+ PATTERN "CMakeFiles" EXCLUDE )
diff --git a/src/libtdeobex/obexobjectmanagerImpl.cpp b/src/libtdeobex/obexobjectmanagerImpl.cpp
new file mode 100644
index 0000000..56a8798
--- /dev/null
+++ b/src/libtdeobex/obexobjectmanagerImpl.cpp
@@ -0,0 +1,286 @@
+/*
+ *
+ * Object Manager implementation of bluez5
+ *
+ * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com>
+ *
+ *
+ * This file is part of libtdebluez.
+ *
+ * libtdebluez 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.
+ *
+ * libtdebluez 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 kbluetooth; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+// QT - Header
+#include <tqtimer.h>
+//
+// debug
+#include <kdebug.h>
+
+// declaration include
+#include <tqdbusproxy.h>
+#include <tqdbusmessage.h>
+#include <tqdbusobjectpath.h>
+#include <tqdbusdatamap.h>
+#include <tqdbusdata.h>
+//
+#include <tqstringlist.h>
+
+#include "obexobjectmanagerImpl.h"
+#include "../libtdebluez/btuuids.h"
+
+namespace TDEObex
+{
+
+ObexObjectManagerImpl::ObexObjectManagerImpl(const TQString& service, const TQString& path, TQObject* parent, const char* name) :
+ org::freedesktop::DBus::ObjectManagerProxy(service, path, parent, name)
+{
+ kdDebug() << k_funcinfo << endl;
+ // init connection to dbus
+ initDBUS();
+}
+
+ObexObjectManagerImpl::~ObexObjectManagerImpl()
+{
+ kdDebug() << k_funcinfo << endl;
+ close();
+}
+
+/*!
+ * This function try a reconnect to D-Bus.
+ * \return boolean with the result of the operation
+ * \retval true if successful reconnected to D-Bus
+ * \retval false if unsuccessful
+ */
+bool ObexObjectManagerImpl::reconnect()
+{
+ kdDebug() << k_funcinfo << endl;
+ // close D-Bus connection
+ close();
+ // init D-Bus conntection
+ return (initDBUS());
+}
+
+/*!
+ * This function return information about connection status to the DBUS daemon.
+ * \return boolean with the state of the connection to D-Bus
+ * \retval true if connected
+ * \retval false if disconnected
+ */
+bool ObexObjectManagerImpl::isConnectedToDBUS()
+{
+ kdDebug() << k_funcinfo << endl;
+ return dBusConn.isConnected();
+}
+
+/*!
+ * This function returns pointer to connection of the DBUS.
+ * \return TQT_DBusConnection* of the connection to D-Bus
+ * \retval TQT_DBusConnection*
+ */
+TQT_DBusConnection* ObexObjectManagerImpl::getConnection()
+{
+ kdDebug() << k_funcinfo << endl;
+ return &dBusConn;
+}
+
+/*!
+ * This function close the connection to manager over the D-Bus daemon.
+ * \return boolean with the result of the operation
+ * \retval true if successful closed the connection
+ * \retval false if any problems
+ */
+bool ObexObjectManagerImpl::close()
+{
+ kdDebug() << k_funcinfo << endl;
+
+ if (mSession)
+ delete mSession;
+ if (mFileTransfer)
+ delete mFileTransfer;
+ if (mClient)
+ delete mClient;
+ if (dBusConn.isConnected())
+ dBusConn.closeConnection(DBUS_CONN_NAME);
+ return true;
+}
+
+/*!
+ * This function initialise the connection to the D-Bus daemon.
+ * \return boolean with the result of the operation
+ * \retval true if successful initialised D-Bus connection
+ * \retval false if unsuccessful
+ */
+bool ObexObjectManagerImpl::initDBUS()
+{
+ kdDebug() << k_funcinfo << endl;
+ dBusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SessionBus, DBUS_CONN_NAME);
+ if (!dBusConn.isConnected())
+ {
+ kdError() << "Failed to open connection to system message bus: " << dBusConn.lastError().message() << endl;
+ TQTimer::singleShot(4000, this, TQT_SLOT(reconnect()));
+ return false;
+ }
+ setConnection(dBusConn);
+
+ TQT_DBusDataMap<TQT_DBusObjectPath> objects;
+ TQT_DBusError error;
+ if (!GetManagedObjects(objects, error))
+ {
+ tqDebug("GetManagedObjects(objects,error) FAILED\n");
+ return false;
+ }
+
+ TQT_DBusDataMap<TQT_DBusObjectPath>::const_iterator it = objects.begin();
+ for (it; it != objects.end(); ++it)
+ {
+ bool ok = false;
+ TQT_DBusDataMap<TQString> tqMap1 = it.data().toStringKeyMap(&ok);
+ if (!ok)
+ {
+ tqWarning("Failed to convert dbus data to string map: %s", it.key().latin1());
+ return false;
+ }
+ slotInterfacesAdded(it.key(), tqMap1);
+ }
+
+ connect(this, SIGNAL(InterfacesAdded(const TQT_DBusObjectPath&, const TQT_DBusDataMap< TQString >&)), this, SLOT(slotInterfacesAdded(const TQT_DBusObjectPath&, const TQT_DBusDataMap< TQString >& )));
+ connect(this, SIGNAL(InterfacesRemoved(const TQT_DBusObjectPath& , const TQStringList& )), this, SLOT(slotInterfacesRemoved(const TQT_DBusObjectPath& , const TQStringList& )));
+ return true;
+}
+
+/*!
+ * This function initialise the connection to the D-Bus daemon.
+ * \return pointer to AgentManager1
+ */
+org::bluez::obex::AgentManager1Proxy * ObexObjectManagerImpl::getAgentManager()
+{
+ kdDebug() << k_funcinfo << endl;
+ return mAgentManager;
+}
+
+/*!
+ * This function initialise the connection to the D-Bus daemon.
+ * \return pointer to AgentManager1
+ */
+org::bluez::obex::Client1Proxy * ObexObjectManagerImpl::getClient()
+{
+ kdDebug() << k_funcinfo << endl;
+ return mClient;
+}
+
+void ObexObjectManagerImpl::slotInterfacesAdded(const TQT_DBusObjectPath& object, const TQT_DBusDataMap<TQString>& interfaces)
+{
+ kdDebug() << k_funcinfo << endl;
+
+ TQT_DBusDataMap<TQString>::const_iterator it1 = interfaces.begin();
+ for (it1; it1 != interfaces.end(); it1++)
+ {
+ TQString interface = it1.key();
+ if (interface == "org.bluez.obex.AgentManager1")
+ {
+ mAgentManager = new org::bluez::obex::AgentManager1Proxy("org.bluez.obex", object);
+ if (mAgentManager)
+ {
+ mAgentManager->setConnection(dBusConn);
+ }
+ else
+ {
+ tqDebug("org.bluez.obex.AgentManager1 initialization failed\n");
+ }
+ }
+ else if (interface == "org.bluez.obex.Client1")
+ {
+ mClient = new org::bluez::obex::Client1Proxy("org.bluez.obex", object);
+ if (mClient)
+ {
+ mClient->setConnection(dBusConn);
+ }
+ else
+ {
+ tqDebug("org.bluez.obex.Client1 initialization failed\n");
+ }
+ }
+ else if (interface == "org.bluez.obex.Session1")
+ {
+ mSession = new org::bluez::obex::Session1Proxy("org.bluez.obex", object);
+ if (mSession)
+ {
+ mSession->setConnection(dBusConn);
+ }
+ else
+ {
+ tqDebug("org.bluez.obex.Session1 initialization failed\n");
+ }
+ }
+ else if (interface == "org.bluez.obex.FileTransfer1")
+ {
+ mFileTransfer = new org::bluez::obex::FileTransfer1Proxy("org.bluez.obex", object);
+ if (mFileTransfer)
+ {
+ mFileTransfer->setConnection(dBusConn);
+ }
+ else
+ {
+ tqDebug("org.bluez.obex.FileTransfer1 initialization failed\n");
+ }
+ }
+ else if (interface == "org.freedesktop.DBus.Introspectable")
+ {
+ // do nothing
+ }
+ else
+ {
+ tqWarning("Interface not implemented: %s", interface.local8Bit().data());
+ }
+ }
+}
+
+void ObexObjectManagerImpl::slotInterfacesRemoved(const TQT_DBusObjectPath& object, const TQStringList& interfaces)
+{
+ kdDebug() << k_funcinfo << endl;
+ // TODO: remove interface
+ for (TQValueListConstIterator<TQString> it = interfaces.begin();
+ it != interfaces.end(); ++it)
+ {
+ if ((*it) == "org.bluez.obex.AgentManager1")
+ {
+ // TODO: remove AgentManager1
+ }
+ else if ((*it) == "org.bluez.obex.Client1")
+ {
+ // TODO: remove Client1
+ }
+ else if ((*it) == "org.bluez.obex.Session1")
+ {
+ // TODO: remove Session1
+ }
+ else if ((*it) == "org.bluez.obex.FileTransfer1")
+ {
+ // TODO: remove FileTransfer1
+ }
+ else
+ {
+ tqWarning("Interface not implemented: %s", (*it).local8Bit().data());
+ }
+ }
+}
+
+};
+// namespace TDEObex
+
+#include "obexobjectmanagerImpl.moc"
+// End of File
+
diff --git a/src/libtdeobex/obexobjectmanagerImpl.h b/src/libtdeobex/obexobjectmanagerImpl.h
new file mode 100644
index 0000000..65ef978
--- /dev/null
+++ b/src/libtdeobex/obexobjectmanagerImpl.h
@@ -0,0 +1,94 @@
+/*
+ *
+ * Obex Object Manager implementation of bluez5
+ *
+ * Copyright (C) 2018 Emanoil Kotsev <deloptes@gmail.com>
+ *
+ *
+ * This file is part of libtdebluez.
+ *
+ * libtdebluez 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.
+ *
+ * libtdebluez 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 kbluetooth; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef OBEXOBJECTMANAGERIMPL_H_INCLUDED
+#define OBEXOBJECTMANAGERIMPL_H_INCLUDED
+
+#include <tqdbusconnection.h>
+#include <tdelocale.h>
+
+#include "interfaces/propertiesProxy.h"
+#include "interfaces/objectmanagerProxy.h"
+#include "interfaces/agentmanager1Proxy.h"
+#include "interfaces/client1Proxy.h"
+#include "interfaces/session1Proxy.h"
+#include "interfaces/filetransfer1Proxy.h"
+
+namespace TDEObex
+{
+
+#define DBUS_CONN_NAME "TDEBluezObex"
+
+class ObexObjectManagerImpl: public org::freedesktop::DBus::ObjectManagerProxy
+{
+ Q_OBJECT
+
+public:
+ // ObexObjectManagerImpl(){}
+ ObexObjectManagerImpl(const TQString& service, const TQString& path, TQObject* parent = 0, const char* name = 0);
+
+ virtual ~ObexObjectManagerImpl();
+
+ // --- helper to get private members of the class --- //
+ //! to get information if TDEBluez is connected to D-Bus
+ bool isConnectedToDBUS();
+ //! pointer to the D-Bus connection
+ TQT_DBusConnection* getConnection();
+ //! to close the connection to D-Bus
+ bool close();
+
+ //
+ org::bluez::obex::AgentManager1Proxy* getAgentManager();
+ org::bluez::obex::Client1Proxy* getClient();
+ // ConnectionList listConnections(const TQString&);
+
+private:
+ bool initDBUS();
+
+ void slotInterfacesAdded(const TQT_DBusObjectPath& object, const TQT_DBusDataMap<
+ TQString>& interfaces);
+
+ void slotInterfacesRemoved(const TQT_DBusObjectPath& object, const TQStringList& interfaces);
+
+private:
+ //! TQt connection to D-Bus
+ TQT_DBusConnection dBusConn;
+ org::bluez::obex::AgentManager1Proxy* mAgentManager;
+ org::bluez::obex::Client1Proxy* mClient;
+ org::bluez::obex::Session1Proxy* mSession;
+ org::bluez::obex::FileTransfer1Proxy* mFileTransfer;
+
+private slots:
+ bool reconnect();
+
+};
+// class ObexObjectManagerImpl
+
+};
+// namespace TDEObex
+
+#endif //OBEXOBJECTMANAGERIMPL_H_INCLUDED
+
+// End of File