Kaydet (Commit) 5dcb5399 authored tarafından Andrzej J.R. Hunt's avatar Andrzej J.R. Hunt

Port remote from gdbus to dbus-glib.

Change-Id: I291ee5d32110d2fffd976f3e5257daf976428a76
üst defe079d
...@@ -82,6 +82,7 @@ endif ...@@ -82,6 +82,7 @@ endif
$(eval $(call gb_CppunitTest_use_externals,sd_uimpress,\ $(eval $(call gb_CppunitTest_use_externals,sd_uimpress,\
gtk \ gtk \
dbus \
)) ))
$(eval $(call gb_CppunitTest_add_exception_objects,sd_uimpress,\ $(eval $(call gb_CppunitTest_add_exception_objects,sd_uimpress,\
......
...@@ -108,7 +108,7 @@ $(eval $(call gb_Library_use_libraries,sd,\ ...@@ -108,7 +108,7 @@ $(eval $(call gb_Library_use_libraries,sd,\
$(eval $(call gb_Library_use_externals,sd,\ $(eval $(call gb_Library_use_externals,sd,\
libxml2 \ libxml2 \
gio \ dbus \
)) ))
ifeq ($(OS),WNT) ifeq ($(OS),WNT)
......
...@@ -9,20 +9,19 @@ ...@@ -9,20 +9,19 @@
#include "BluetoothServer.hxx" #include "BluetoothServer.hxx"
#include <stdio.h> #include <stdio.h>
#if defined(LINUX) && defined(ENABLE_GIO) && defined(ENABLE_DBUS) #if defined(LINUX) && defined(ENABLE_DBUS)
#include <glib.h> #include <glib.h>
#include <gio/gio.h> #include <dbus/dbus-glib.h>
#include <sys/unistd.h> #include <sys/unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#endif
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#ifdef LINUX
#include "bluetooth/bluetooth.h" #include "bluetooth/bluetooth.h"
#include "bluetooth/rfcomm.h" #include "bluetooth/rfcomm.h"
#endif #endif
// FIXME: move this into an external file and look at sharing definitions
// across OS's (i.e. UUID and port ).
// Also look at determining which ports are available.
#define BLUETOOTH_SERVICE_RECORD "<?xml version='1.0' encoding= 'UTF-8' ?><record><attribute id='0x0001'><sequence><uuid value='0x1101' /></sequence></attribute><attribute id='0x0004'><sequence><sequence><uuid value='0x0100' /></sequence><sequence><uuid value='0x0003' /><uint8 value='0x05' /></sequence></sequence></attribute><attribute id='0x0005'><sequence><uuid value='0x1002' /></sequence></attribute><attribute id='0x0006'><sequence><uint16 value='0x656e' /><uint16 value='0x006a' /><uint16 value='0x0100' /></sequence></attribute><attribute id='0x0009'><sequence><sequence><uuid value='0x1101' /><uint16 value='0x0100' /></sequence></sequence></attribute><attribute id='0x0100'><text value='Serial Port' /></attribute><attribute id='0x0101'><text value='COM Port' /></attribute></record>"
#include "Communicator.hxx" #include "Communicator.hxx"
...@@ -38,66 +37,71 @@ BluetoothServer::~BluetoothServer() ...@@ -38,66 +37,71 @@ BluetoothServer::~BluetoothServer()
{ {
} }
struct oslSocketImpl {
int m_Socket;
int m_nLastError;
void* m_CloseCallback;
void* m_CallbackArg;
oslInterlockedCount m_nRefCount;
#if defined(LINUX)
sal_Bool m_bIsAccepting;
sal_Bool m_bIsInShutdown;
#endif
};
void BluetoothServer::execute() void BluetoothServer::execute()
{ {
#if defined(LINUX) && defined(ENABLE_GIO) && defined(ENABLE_DBUS) #if defined(LINUX) && defined(ENABLE_DBUS)
#ifdef GLIB_VERSION_2_26
g_type_init(); g_type_init();
GError* aError = NULL;
GDBusConnection* aConnection = g_bus_get_sync( G_BUS_TYPE_SYSTEM, NULL, &aError ); GError *aError = NULL;
if ( aError )
{ DBusGConnection *aConnection = NULL;
g_error_free( aError ); aConnection = dbus_g_bus_get( DBUS_BUS_SYSTEM, &aError );
return; // We can't get a dbus connection
if ( aError != NULL ) {
g_error_free (aError);
return;
} }
GVariant *aAdapter = g_dbus_connection_call_sync( aConnection,
"org.bluez", "/", "org.bluez.Manager", DBusGProxy *aManager = NULL;
"DefaultAdapter", NULL, aManager = dbus_g_proxy_new_for_name( aConnection, "org.bluez", "/",
G_VARIANT_TYPE_TUPLE, "org.bluez.Manager" );
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &aError);
if ( aError ) if ( aManager == NULL )
{ {
g_error_free( aError ); dbus_g_connection_unref( aConnection );
g_object_unref( aConnection ); return;
return; // We can't get an adapter -- no bluetooth possible
} }
GVariant *aAdapterName = g_variant_get_child_value( aAdapter, 0 );
GVariant *aRecordHandle = g_dbus_connection_call_sync( aConnection, gboolean aResult;
"org.bluez", g_variant_get_string( aAdapterName, NULL ), "org.bluez.Service", DBusGObjectPath *aAdapterPath = NULL;
"AddRecord", aResult = dbus_g_proxy_call( aManager, "DefaultAdapter", &aError,
g_variant_new("(s)", G_TYPE_INVALID,
"<?xml version='1.0' encoding= 'UTF-8' ?><record><attribute id='0x0001'><sequence><uuid value='0x1101' /></sequence></attribute><attribute id='0x0004'><sequence><sequence><uuid value='0x0100' /></sequence><sequence><uuid value='0x0003' /><uint8 value='0x05' /></sequence></sequence></attribute><attribute id='0x0005'><sequence><uuid value='0x1002' /></sequence></attribute><attribute id='0x0006'><sequence><uint16 value='0x656e' /><uint16 value='0x006a' /><uint16 value='0x0100' /></sequence></attribute><attribute id='0x0009'><sequence><sequence><uuid value='0x1101' /><uint16 value='0x0100' /></sequence></sequence></attribute><attribute id='0x0100'><text value='Serial Port' /></attribute><attribute id='0x0101'><text value='COM Port' /></attribute></record>"), DBUS_TYPE_G_OBJECT_PATH, &aAdapterPath,
G_VARIANT_TYPE_TUPLE, G_TYPE_INVALID);
G_DBUS_CALL_FLAGS_NONE, -1, NULL, &aError);
g_variant_unref( aAdapter ); g_object_unref( G_OBJECT( aManager ));
g_object_unref( aConnection ); if ( !aResult )
{
dbus_g_connection_unref( aConnection );
return;
}
if ( aError ) DBusGProxy *aAdapter = NULL;
aAdapter = dbus_g_proxy_new_for_name( aConnection, "org.bluez",
aAdapterPath, "org.bluez.Service" );
g_free( aAdapterPath );
if ( aAdapter == NULL )
{ {
g_object_unref( aAdapter ); dbus_g_connection_unref( aConnection );
return; // Couldn't set up the service. return;
} }
g_variant_unref( aRecordHandle ); // We don't need the handle
// as the service is automatically
// deregistered on exit.
// Add the record -- the handle can be used to release it again, but we
// don't bother as the record is automatically released when LO exits.
guint aHandle;
aResult = dbus_g_proxy_call( aAdapter, "AddRecord", &aError,
G_TYPE_STRING, BLUETOOTH_SERVICE_RECORD ,
G_TYPE_INVALID,
G_TYPE_UINT, &aHandle,
G_TYPE_INVALID);
g_object_unref( G_OBJECT( aAdapter ));
dbus_g_connection_unref( aConnection );
if ( !aResult)
{
return;
}
// ---------------- Socket code // ---------------- Socket code
int aSocket; int aSocket;
...@@ -139,8 +143,7 @@ void BluetoothServer::execute() ...@@ -139,8 +143,7 @@ void BluetoothServer::execute()
} }
} }
#endif // GLIB_VERSION_2_26 #endif // LINUX && ENABLE_DBUS
#endif // LINUX
#ifdef WIN32 #ifdef WIN32
......
...@@ -26,11 +26,9 @@ namespace sd ...@@ -26,11 +26,9 @@ namespace sd
~BluetoothServer(); ~BluetoothServer();
static BluetoothServer *spServer; static BluetoothServer *spServer;
void execute(); // salhelper::Thread
public:
private:
void execute();
std::vector<Communicator*>* mpCommunicators; std::vector<Communicator*>* mpCommunicators;
}; };
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment