Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
1db66c2a
Kaydet (Commit)
1db66c2a
authored
Agu 22, 2012
tarafından
Andrzej J.R. Hunt
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Bluetooth connection working (Linux).
Change-Id: Iac77c3ce0ab0ea7bda3105c58859888e55e64d2d
üst
9d735972
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
231 additions
and
121 deletions
+231
-121
BluetoothClient.java
...reoffice/impressremote/communication/BluetoothClient.java
+66
-52
BluetoothFinder.java
...reoffice/impressremote/communication/BluetoothFinder.java
+6
-5
Receiver.java
...org/libreoffice/impressremote/communication/Receiver.java
+2
-0
ServerFinder.java
...libreoffice/impressremote/communication/ServerFinder.java
+2
-1
BluetoothServer.cxx
sd/source/ui/remotecontrol/BluetoothServer.cxx
+70
-25
BluetoothServer.hxx
sd/source/ui/remotecontrol/BluetoothServer.hxx
+6
-2
BufferedStreamSocket.cxx
sd/source/ui/remotecontrol/BufferedStreamSocket.cxx
+38
-3
BufferedStreamSocket.hxx
sd/source/ui/remotecontrol/BufferedStreamSocket.hxx
+21
-2
Communicator.cxx
sd/source/ui/remotecontrol/Communicator.cxx
+11
-20
Receiver.cxx
sd/source/ui/remotecontrol/Receiver.cxx
+0
-2
Server.cxx
sd/source/ui/remotecontrol/Server.cxx
+2
-2
Transmitter.cxx
sd/source/ui/remotecontrol/Transmitter.cxx
+4
-4
Transmitter.hxx
sd/source/ui/remotecontrol/Transmitter.hxx
+3
-3
No files found.
android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java
Dosyayı görüntüle @
1db66c2a
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
*/
*/
package
org
.
libreoffice
.
impressremote
.
communication
;
package
org
.
libreoffice
.
impressremote
.
communication
;
import
java.io.BufferedReader
;
import
java.io.InputStreamReader
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.util.UUID
;
import
java.util.UUID
;
...
@@ -15,6 +17,8 @@ import android.bluetooth.BluetoothAdapter;
...
@@ -15,6 +17,8 @@ import android.bluetooth.BluetoothAdapter;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothDevice
;
import
android.bluetooth.BluetoothSocket
;
import
android.bluetooth.BluetoothSocket
;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.support.v4.content.LocalBroadcastManager
;
/**
/**
* Standard Network client. Connects to a server using Sockets.
* Standard Network client. Connects to a server using Sockets.
...
@@ -31,67 +35,77 @@ public class BluetoothClient extends Client {
...
@@ -31,67 +35,77 @@ public class BluetoothClient extends Client {
super
(
aContext
);
super
(
aContext
);
try
{
try
{
BluetoothAdapter
aAdapter
=
BluetoothAdapter
.
getDefaultAdapter
();
BluetoothAdapter
aAdapter
=
BluetoothAdapter
.
getDefaultAdapter
();
System
.
out
.
println
(
"Attemtping to connect to:"
+
bluetoothAddress
);
BluetoothDevice
aDevice
=
aAdapter
BluetoothDevice
aDevice
=
aAdapter
.
getRemoteDevice
(
bluetoothAddress
);
.
getRemoteDevice
(
bluetoothAddress
);
aAdapter
.
cancelDiscovery
();
BluetoothSocket
aSocket
=
aDevice
BluetoothSocket
aSocket
=
aDevice
.
createRfcommSocketToServiceRecord
(
UUID
.
createRfcommSocketToServiceRecord
(
UUID
.
fromString
(
"00001101-0000-1000-8000-00805
f9b34fb
"
));
.
fromString
(
"00001101-0000-1000-8000-00805
F9B34FB
"
));
aSocket
.
connect
();
aSocket
.
connect
();
// mSocket = aSocket;
System
.
out
.
println
(
"Connected"
);
mInputStream
=
aSocket
.
getInputStream
();
mReader
=
new
BufferedReader
(
new
InputStreamReader
(
mInputStream
,
CHARSET
));
mOutputStream
=
aSocket
.
getOutputStream
();
// mOutputStream.write(20);
// mOutputStream.write(20);
// mOutputStream.write(20);
// mOutputStream.flush();
// System.out.println("reading");
// while (true) {
// System.out.println(mInputStream.read());
// }
String
aTemp
=
mReader
.
readLine
();
System
.
out
.
println
(
"SF:waited"
);
if
(!
aTemp
.
equals
(
"LO_SERVER_SERVER_PAIRED"
))
{
return
;
}
while
(
mReader
.
readLine
().
length
()
!=
0
)
{
// Get rid of extra lines
}
Intent
aIntent
=
new
Intent
(
CommunicationService
.
MSG_PAIRING_SUCCESSFUL
);
LocalBroadcastManager
.
getInstance
(
mContext
).
sendBroadcast
(
aIntent
);
startListening
();
// Pairing.
// Random aRandom = new Random();
// String aPin = "" + (aRandom.nextInt(9000) + 1000);
// while (aPin.length() < 4) {
// aPin = "0" + aPin; // Add leading zeros if necessary
// }
// Intent aIntent = new Intent(
// CommunicationService.MSG_PAIRING_STARTED);
// aIntent.putExtra("PIN", aPin);
// mPin = aPin;
// LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
// // Send out
// String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
// sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin
// + "\n\n");
//
// // Wait until we get the appropriate string back...
// System.out.println("SF:waiting");
// String aTemp = mReader.readLine();
// System.out.println("SF:waited");
// if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
// return;
// } else {
//
// }
// while (mReader.readLine().length() != 0) {
// // Get rid of extra lines
// System.out.println("SF: empty line");
// }
// System.out.println("SD: empty");
// startListening();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
// BluetoothSocket aSocket = new BluetoothClient(bluetoothAddress, aContext)
// .createRfcommSocketToServiceRecord(UUID
// .fromString("00001101-0000-1000-8000-00805F9B34F
// }
// try {
// mSocket = new Socket(ipAddress, PORT);
// mInputStream = mSocket.getInputStream();
// mReader = new BufferedReader(new InputStreamReader(mInputStream,
// CHARSET));
// mOutputStream = mSocket.getOutputStream();
// // Pairing.
// Random aRandom = new Random();
// String aPin = "" + (aRandom.nextInt(9000) + 1000);
// while (aPin.length() < 4) {
// aPin = "0" + aPin; // Add leading zeros if necessary
// }
// Intent aIntent = new Intent(
// CommunicationService.MSG_PAIRING_STARTED);
// aIntent.putExtra("PIN", aPin);
// mPin = aPin;
// LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
// // Send out
// String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
// sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin
// + "\n\n");
//
// // Wait until we get the appropriate string back...
// System.out.println("SF:waiting");
// String aTemp = mReader.readLine();
// System.out.println("SF:waited");
// if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
// return;
// } else {
// aIntent = new Intent(
// CommunicationService.MSG_PAIRING_SUCCESSFUL);
// LocalBroadcastManager.getInstance(mContext).sendBroadcast(
// aIntent);
// }
// while (mReader.readLine().length() != 0) {
// // Get rid of extra lines
// System.out.println("SF: empty line");
// }
// System.out.println("SD: empty");
// startListening();
// } catch (UnknownHostException e) {
// // TODO Tell the user we have a problem
// e.printStackTrace();
// } catch (IOException e) {
// // TODO As above
// e.printStackTrace();
// }
}
}
...
...
android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java
Dosyayı görüntüle @
1db66c2a
...
@@ -11,6 +11,7 @@ import android.content.BroadcastReceiver;
...
@@ -11,6 +11,7 @@ import android.content.BroadcastReceiver;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.content.IntentFilter
;
import
android.support.v4.content.LocalBroadcastManager
;
public
class
BluetoothFinder
{
public
class
BluetoothFinder
{
...
@@ -32,9 +33,8 @@ public class BluetoothFinder {
...
@@ -32,9 +33,8 @@ public class BluetoothFinder {
return
;
// No bluetooth adapter found (emulator, special devices)
return
;
// No bluetooth adapter found (emulator, special devices)
}
}
System
.
out
.
println
(
"BT:Discovery starting"
);
System
.
out
.
println
(
"BT:Discovery starting"
);
IntentFilter
aFilter
=
new
IntentFilter
(
IntentFilter
aFilter
=
new
IntentFilter
(
BluetoothDevice
.
ACTION_FOUND
);
BluetoothAdapter
.
ACTION_DISCOVERY_FINISHED
);
aFilter
.
addAction
(
BluetoothAdapter
.
ACTION_DISCOVERY_FINISHED
);
aFilter
.
addAction
(
BluetoothDevice
.
ACTION_FOUND
);
mContext
.
registerReceiver
(
mReceiver
,
aFilter
);
mContext
.
registerReceiver
(
mReceiver
,
aFilter
);
mAdapter
.
enable
();
mAdapter
.
enable
();
...
@@ -64,7 +64,7 @@ public class BluetoothFinder {
...
@@ -64,7 +64,7 @@ public class BluetoothFinder {
@Override
@Override
public
void
onReceive
(
Context
context
,
Intent
aIntent
)
{
public
void
onReceive
(
Context
context
,
Intent
aIntent
)
{
// TODO Auto-generated method stub
// TODO Auto-generated method stub
System
.
out
.
print
ln
(
"Received intent
"
);
System
.
out
.
print
(
"Received intent<<<
"
);
System
.
out
.
println
(
aIntent
.
getAction
());
System
.
out
.
println
(
aIntent
.
getAction
());
if
(
aIntent
.
getAction
().
equals
(
BluetoothDevice
.
ACTION_FOUND
))
{
if
(
aIntent
.
getAction
().
equals
(
BluetoothDevice
.
ACTION_FOUND
))
{
BluetoothDevice
aDevice
=
(
BluetoothDevice
)
aIntent
.
getExtras
()
BluetoothDevice
aDevice
=
(
BluetoothDevice
)
aIntent
.
getExtras
()
...
@@ -77,7 +77,8 @@ public class BluetoothFinder {
...
@@ -77,7 +77,8 @@ public class BluetoothFinder {
System
.
out
.
println
(
"Now we have: "
+
mServerList
.
size
());
System
.
out
.
println
(
"Now we have: "
+
mServerList
.
size
());
Intent
aNIntent
=
new
Intent
(
Intent
aNIntent
=
new
Intent
(
CommunicationService
.
MSG_SERVERLIST_CHANGED
);
CommunicationService
.
MSG_SERVERLIST_CHANGED
);
mContext
.
sendBroadcast
(
aNIntent
);
LocalBroadcastManager
.
getInstance
(
mContext
).
sendBroadcast
(
aNIntent
);
// System.out.println("Found " + aDevice.getName());
// System.out.println("Found " + aDevice.getName());
// try {
// try {
// // "f36d0a20-e876-11e1-aff1-0800200c9a66"
// // "f36d0a20-e876-11e1-aff1-0800200c9a66"
...
...
android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
Dosyayı görüntüle @
1db66c2a
...
@@ -35,6 +35,8 @@ public class Receiver {
...
@@ -35,6 +35,8 @@ public class Receiver {
}
}
public
void
parseCommand
(
ArrayList
<
String
>
aCommand
)
{
public
void
parseCommand
(
ArrayList
<
String
>
aCommand
)
{
if
(
aCommand
.
size
()
==
0
)
return
;
// E.g. if empty line received for whatever reason.
String
aInstruction
=
aCommand
.
get
(
0
);
String
aInstruction
=
aCommand
.
get
(
0
);
if
(
aInstruction
.
equals
(
"slideshow_started"
))
{
if
(
aInstruction
.
equals
(
"slideshow_started"
))
{
int
aSlideShowlength
=
Integer
.
parseInt
(
aCommand
.
get
(
1
));
int
aSlideShowlength
=
Integer
.
parseInt
(
aCommand
.
get
(
1
));
...
...
android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
Dosyayı görüntüle @
1db66c2a
...
@@ -13,6 +13,7 @@ import org.libreoffice.impressremote.communication.Server.Protocol;
...
@@ -13,6 +13,7 @@ import org.libreoffice.impressremote.communication.Server.Protocol;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.support.v4.content.LocalBroadcastManager
;
public
class
ServerFinder
{
public
class
ServerFinder
{
...
@@ -169,7 +170,7 @@ public class ServerFinder {
...
@@ -169,7 +170,7 @@ public class ServerFinder {
*/
*/
private
void
notifyActivity
()
{
private
void
notifyActivity
()
{
Intent
aIntent
=
new
Intent
(
CommunicationService
.
MSG_SERVERLIST_CHANGED
);
Intent
aIntent
=
new
Intent
(
CommunicationService
.
MSG_SERVERLIST_CHANGED
);
mContext
.
sendBroadcast
(
aIntent
);
LocalBroadcastManager
.
getInstance
(
mContext
)
.
sendBroadcast
(
aIntent
);
}
}
public
Collection
<
Server
>
getServerList
()
{
public
Collection
<
Server
>
getServerList
()
{
...
...
sd/source/ui/remotecontrol/BluetoothServer.cxx
Dosyayı görüntüle @
1db66c2a
...
@@ -22,29 +22,60 @@
...
@@ -22,29 +22,60 @@
#include "bluetooth/rfcomm.h"
#include "bluetooth/rfcomm.h"
#endif
#endif
#include "Communicator.hxx"
using
namespace
sd
;
using
namespace
sd
;
BluetoothServer
::
BluetoothServer
()
:
BluetoothServer
::
BluetoothServer
(
std
::
vector
<
Communicator
*>*
pCommunicators
)
:
Thread
(
"BluetoothServer"
)
Thread
(
"BluetoothServer"
),
mpCommunicators
(
pCommunicators
)
{
{
}
}
BluetoothServer
::~
BluetoothServer
()
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
()
{
{
#ifdef LINUX
#ifdef LINUX
// g_type_init();
g_type_init
();
// GError* aError = NULL;
GError
*
aError
=
NULL
;
// GDBusConnection* aConnection = g_bus_get_sync( G_BUS_TYPE_SYSTEM, NULL, &aError );
GDBusConnection
*
aConnection
=
g_bus_get_sync
(
G_BUS_TYPE_SYSTEM
,
NULL
,
&
aError
);
// if ( aError )
if
(
aError
)
// {
{
// fprintf( stderr, aError->message );
fprintf
(
stderr
,
aError
->
message
);
// g_error_free( aError );
g_error_free
(
aError
);
// }
}
GVariant
*
aAdapter
=
g_dbus_connection_call_sync
(
aConnection
,
"org.bluez"
,
"/"
,
"org.bluez.Manager"
,
"DefaultAdapter"
,
NULL
,
G_VARIANT_TYPE_TUPLE
,
G_DBUS_CALL_FLAGS_NONE
,
-
1
,
NULL
,
&
aError
);
GVariant
*
aAdapterName
=
g_variant_get_child_value
(
aAdapter
,
0
);
if
(
aError
)
{
fprintf
(
stderr
,
aError
->
message
);
g_error_free
(
aError
);
}
fprintf
(
stderr
,
(
const
char
*
)
g_variant_get_string
(
aAdapterName
,
NULL
)
);
// GDBusObjectManager* aManager = g_dbus_object_manager_client_new_sync( aConnection,
// GDBusObjectManager* aManager = g_dbus_object_manager_client_new_sync( aConnection,
// G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, "org.bluez.Manager", "/org/bluez",
// G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE, "org.bluez.Manager", "/org/bluez",
// NULL, NULL, NULL, NULL, &aError );
// NULL, NULL, NULL, NULL, &aError );
...
@@ -53,14 +84,21 @@ void BluetoothServer::execute()
...
@@ -53,14 +84,21 @@ void BluetoothServer::execute()
// fprintf( stderr, aError->message );
// fprintf( stderr, aError->message );
// g_error_free( aError );
// g_error_free( aError );
// }
// }
//
// GVariant *aRet = g_dbus_connection_call_sync( aConnection,
GVariant
*
aRecordHandle
=
g_dbus_connection_call_sync
(
aConnection
,
// "org.bluez", "/", "org.bluez.Database",
"org.bluez"
,
g_variant_get_string
(
aAdapterName
,
NULL
),
"org.bluez.Service"
,
// "AddServiceRecordFromXml",
"AddRecord"
,
// g_variant_new ("s",
g_variant_new
(
"(s)"
,
// ""),,
"<?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>"
),
// G_VARIANT_TYPE_UINT32,
G_VARIANT_TYPE_TUPLE
,
// G_DBUS_CALL_FLAGS_NONE, -1, NULL, &aError);
G_DBUS_CALL_FLAGS_NONE
,
-
1
,
NULL
,
&
aError
);
if
(
aError
)
{
fprintf
(
stderr
,
aError
->
message
);
g_error_free
(
aError
);
}
(
void
)
aRecordHandle
;
// Remove handle again at some point
// g_variant_unref( aRet );
// g_variant_unref( aRet );
// fprintf( stderr, "Manager gotten\n" );
// fprintf( stderr, "Manager gotten\n" );
//
//
...
@@ -125,8 +163,8 @@ void BluetoothServer::execute()
...
@@ -125,8 +163,8 @@ void BluetoothServer::execute()
sockaddr_rc
aAddr
;
sockaddr_rc
aAddr
;
aAddr
.
rc_family
=
AF_BLUETOOTH
;
aAddr
.
rc_family
=
AF_BLUETOOTH
;
// aAddr.rc_bdaddr = *BDADDR_ANY;
aAddr
.
rc_bdaddr
=
{{
0
,
0
,
0
,
0
,
0
,
0
}};
// BDADDR_ANY is broken
aAddr
.
rc_channel
=
1
;
aAddr
.
rc_channel
=
5
;
if
(
bind
(
aSocket
,
(
sockaddr
*
)
&
aAddr
,
sizeof
(
aAddr
))
<
0
)
{
if
(
bind
(
aSocket
,
(
sockaddr
*
)
&
aAddr
,
sizeof
(
aAddr
))
<
0
)
{
close
(
aSocket
);
close
(
aSocket
);
...
@@ -141,12 +179,18 @@ void BluetoothServer::execute()
...
@@ -141,12 +179,18 @@ void BluetoothServer::execute()
sockaddr_rc
aRemoteAddr
;
sockaddr_rc
aRemoteAddr
;
socklen_t
aRemoteAddrLen
=
sizeof
(
aRemoteAddr
);
socklen_t
aRemoteAddrLen
=
sizeof
(
aRemoteAddr
);
if
(
accept
(
aSocket
,
(
sockaddr
*
)
&
aRemoteAddr
,
&
aRemoteAddrLen
)
<
0
)
int
bSocket
;
if
(
(
bSocket
=
accept
(
aSocket
,
(
sockaddr
*
)
&
aRemoteAddr
,
&
aRemoteAddrLen
))
<
0
)
{
{
close
(
aSocket
);
close
(
aSocket
);
return
;
return
;
}
else
{
}
else
{
fprintf
(
stderr
,
"Accepted Bluetooth
\n
"
);
fprintf
(
stderr
,
"Accepted Bluetooth
\n
"
);
Communicator
*
pCommunicator
=
new
Communicator
(
new
BufferedStreamSocket
(
bSocket
)
);
mpCommunicators
->
push_back
(
pCommunicator
);
pCommunicator
->
launch
();
}
}
#endif
#endif
...
@@ -163,14 +207,14 @@ void BluetoothServer::execute()
...
@@ -163,14 +207,14 @@ void BluetoothServer::execute()
BluetoothServer
*
sd
::
BluetoothServer
::
spServer
=
NULL
;
BluetoothServer
*
sd
::
BluetoothServer
::
spServer
=
NULL
;
void
BluetoothServer
::
setup
()
void
BluetoothServer
::
setup
(
std
::
vector
<
Communicator
*>*
pCommunicators
)
{
{
if
(
spServer
)
if
(
spServer
)
return
;
return
;
spServer
=
new
BluetoothServer
();
spServer
=
new
BluetoothServer
(
pCommunicators
);
spServer
->
launch
();
spServer
->
launch
();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
sd/source/ui/remotecontrol/BluetoothServer.hxx
Dosyayı görüntüle @
1db66c2a
...
@@ -10,16 +10,19 @@
...
@@ -10,16 +10,19 @@
#define _SD_IMPRESSREMOTE_BLUETOOTHSERVER_HXX
#define _SD_IMPRESSREMOTE_BLUETOOTHSERVER_HXX
#include <salhelper/thread.hxx>
#include <salhelper/thread.hxx>
#include <vector>
namespace
sd
namespace
sd
{
{
class
Communicator
;
class
BluetoothServer
:
class
BluetoothServer
:
public
salhelper
::
Thread
public
salhelper
::
Thread
{
{
public
:
public
:
static
void
setup
();
static
void
setup
(
std
::
vector
<
Communicator
*>*
pCommunicators
);
private
:
private
:
BluetoothServer
();
BluetoothServer
(
std
::
vector
<
Communicator
*>*
pCommunicators
);
~
BluetoothServer
();
~
BluetoothServer
();
static
BluetoothServer
*
spServer
;
static
BluetoothServer
*
spServer
;
...
@@ -27,6 +30,7 @@ namespace sd
...
@@ -27,6 +30,7 @@ namespace sd
public
:
public
:
private
:
private
:
void
execute
();
void
execute
();
std
::
vector
<
Communicator
*>*
mpCommunicators
;
};
};
}
}
...
...
sd/source/ui/remotecontrol/BufferedStreamSocket.cxx
Dosyayı görüntüle @
1db66c2a
...
@@ -11,6 +11,12 @@
...
@@ -11,6 +11,12 @@
#include <algorithm>
#include <algorithm>
#ifdef WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#include <unistd.h>
#endif
using
namespace
sd
;
using
namespace
sd
;
using
namespace
std
;
using
namespace
std
;
using
namespace
osl
;
using
namespace
osl
;
...
@@ -19,10 +25,36 @@ BufferedStreamSocket::BufferedStreamSocket( const osl::StreamSocket &aSocket ):
...
@@ -19,10 +25,36 @@ BufferedStreamSocket::BufferedStreamSocket( const osl::StreamSocket &aSocket ):
StreamSocket
(
aSocket
),
StreamSocket
(
aSocket
),
aRet
(
0
),
aRet
(
0
),
aRead
(
0
),
aRead
(
0
),
aBuffer
()
aBuffer
(),
mSocket
(
0
),
usingCSocket
(
false
)
{
{
}
}
BufferedStreamSocket
::
BufferedStreamSocket
(
int
aSocket
)
:
StreamSocket
(),
aRet
(
0
),
aRead
(
0
),
aBuffer
(),
mSocket
(
aSocket
),
usingCSocket
(
true
)
{
}
void
BufferedStreamSocket
::
getPeerAddr
(
osl
::
SocketAddr
&
rAddr
)
{
assert
(
!
usingCSocket
);
StreamSocket
::
getPeerAddr
(
rAddr
);
}
sal_Int32
BufferedStreamSocket
::
write
(
const
void
*
pBuffer
,
sal_uInt32
n
)
{
if
(
!
usingCSocket
)
return
StreamSocket
::
write
(
pBuffer
,
n
);
else
return
::
write
(
mSocket
,
pBuffer
,
(
size_t
)
n
);
}
sal_Int32
BufferedStreamSocket
::
readLine
(
OString
&
aLine
)
sal_Int32
BufferedStreamSocket
::
readLine
(
OString
&
aLine
)
{
{
while
(
true
)
while
(
true
)
...
@@ -39,12 +71,15 @@ sal_Int32 BufferedStreamSocket::readLine( OString& aLine )
...
@@ -39,12 +71,15 @@ sal_Int32 BufferedStreamSocket::readLine( OString& aLine )
aBuffer
.
erase
(
aBuffer
.
begin
(),
aIt
+
1
);
// Also delete the empty line
aBuffer
.
erase
(
aBuffer
.
begin
(),
aIt
+
1
);
// Also delete the empty line
aRead
-=
(
aLocation
+
1
);
aRead
-=
(
aLocation
+
1
);
return
aLine
.
getLength
();
return
aLine
.
getLength
()
+
1
;
}
}
// Then try and receive if nothing present
// Then try and receive if nothing present
aBuffer
.
resize
(
aRead
+
100
);
aBuffer
.
resize
(
aRead
+
100
);
aRet
=
recv
(
&
aBuffer
[
aRead
],
100
);
if
(
!
usingCSocket
)
aRet
=
StreamSocket
::
recv
(
&
aBuffer
[
aRead
],
100
);
else
aRet
=
::
read
(
mSocket
,
&
aBuffer
[
aRead
],
100
);
if
(
aRet
==
0
)
if
(
aRet
==
0
)
{
{
...
...
sd/source/ui/remotecontrol/BufferedStreamSocket.hxx
Dosyayı görüntüle @
1db66c2a
...
@@ -20,14 +20,27 @@ namespace sd
...
@@ -20,14 +20,27 @@ namespace sd
{
{
/**
/**
* A wrapper for an osl StreamSocket to allow reading lines.
* [A wrapper for an osl StreamSocket to allow reading lines.]
*
* Currently wraps either an osl StreamSocket or a standard c socket,
* allowing reading and writing for our purposes. Should eventually be
* returned to being a StreamSocket wrapper if/when Bluetooth is
* integrated into osl Sockets.
*/
*/
class
BufferedStreamSocket
:
class
BufferedStreamSocket
:
p
ublic
::
osl
::
StreamSocket
,
p
rivate
::
osl
::
StreamSocket
,
private
::
boost
::
noncopyable
private
::
boost
::
noncopyable
{
{
public
:
public
:
/**
* Create a BufferedStreamSocket on top of an
* osl::StreamSocket.
*/
BufferedStreamSocket
(
const
osl
::
StreamSocket
&
aSocket
);
BufferedStreamSocket
(
const
osl
::
StreamSocket
&
aSocket
);
/**
* Create a BufferedStreamSocket on top of a standard c socket.
*/
BufferedStreamSocket
(
int
aSocket
);
BufferedStreamSocket
(
const
BufferedStreamSocket
&
aSocket
);
BufferedStreamSocket
(
const
BufferedStreamSocket
&
aSocket
);
/**
/**
* Blocks until a line is read.
* Blocks until a line is read.
...
@@ -35,9 +48,15 @@ namespace sd
...
@@ -35,9 +48,15 @@ namespace sd
* if there was a problem in communications.
* if there was a problem in communications.
*/
*/
sal_Int32
readLine
(
OString
&
aLine
);
sal_Int32
readLine
(
OString
&
aLine
);
sal_Int32
write
(
const
void
*
pBuffer
,
sal_uInt32
n
);
void
getPeerAddr
(
osl
::
SocketAddr
&
);
private
:
private
:
sal_Int32
aRet
,
aRead
;
sal_Int32
aRet
,
aRead
;
std
::
vector
<
char
>
aBuffer
;
std
::
vector
<
char
>
aBuffer
;
int
mSocket
;
bool
usingCSocket
;
};
};
}
}
...
...
sd/source/ui/remotecontrol/Communicator.cxx
Dosyayı görüntüle @
1db66c2a
...
@@ -37,7 +37,7 @@ Communicator::~Communicator()
...
@@ -37,7 +37,7 @@ Communicator::~Communicator()
// Run as a thread
// Run as a thread
void
Communicator
::
execute
()
void
Communicator
::
execute
()
{
{
pTransmitter
=
new
Transmitter
(
*
mpSocket
);
pTransmitter
=
new
Transmitter
(
mpSocket
);
pTransmitter
->
launch
();
pTransmitter
->
launch
();
pTransmitter
->
addMessage
(
"LO_SERVER_SERVER_PAIRED
\n\n
"
,
pTransmitter
->
addMessage
(
"LO_SERVER_SERVER_PAIRED
\n\n
"
,
...
@@ -61,33 +61,24 @@ void Communicator::execute()
...
@@ -61,33 +61,24 @@ void Communicator::execute()
{
{
}
}
sal_uInt64
aRet
,
aRead
;
sal_uInt64
aRet
;
vector
<
char
>
aBuffer
;
vector
<
OString
>
aCommand
;
vector
<
OString
>
aCommand
;
aRead
=
0
;
while
(
true
)
while
(
true
)
{
{
aBuffer
.
resize
(
aRead
+
100
)
;
OString
aLine
;
aRet
=
mpSocket
->
re
cv
(
&
aBuffer
[
aRead
],
100
);
aRet
=
mpSocket
->
re
adLine
(
aLine
);
if
(
aRet
==
0
)
if
(
aRet
==
0
)
{
{
break
;
// I.e. transmission finished.
break
;
// I.e. transmission finished.
}
}
aRead
+=
aRet
;
if
(
aLine
.
getLength
()
)
vector
<
char
>::
iterator
aIt
;
while
(
(
aIt
=
find
(
aBuffer
.
begin
(),
aBuffer
.
end
(),
'\n'
))
!=
aBuffer
.
end
()
)
{
{
sal_uInt64
aLocation
=
aIt
-
aBuffer
.
begin
();
aCommand
.
push_back
(
aLine
);
}
aCommand
.
push_back
(
OString
(
&
(
*
aBuffer
.
begin
()),
aLocation
)
);
else
if
(
aIt
==
aBuffer
.
begin
()
)
{
{
aReceiver
.
parseCommand
(
aCommand
);
aReceiver
.
parseCommand
(
aCommand
);
aCommand
.
clear
();
aCommand
.
clear
();
}
aBuffer
.
erase
(
aBuffer
.
begin
(),
aIt
+
1
);
// Also delete the empty line
aRead
-=
(
aLocation
+
1
);
}
}
}
}
// TODO: deal with transmision errors gracefully.
// TODO: deal with transmision errors gracefully.
...
...
sd/source/ui/remotecontrol/Receiver.cxx
Dosyayı görüntüle @
1db66c2a
...
@@ -55,8 +55,6 @@ void Receiver::parseCommand( std::vector<OString> aCommand )
...
@@ -55,8 +55,6 @@ void Receiver::parseCommand( std::vector<OString> aCommand )
}
}
catch
(
uno
::
RuntimeException
&
)
catch
(
uno
::
RuntimeException
&
)
{
{
fprintf
(
stderr
,
"Error in retrieving Controller
\n
"
);
//return;
}
}
if
(
aCommand
[
0
].
equals
(
"transition_next"
)
)
if
(
aCommand
[
0
].
equals
(
"transition_next"
)
)
...
...
sd/source/ui/remotecontrol/Server.cxx
Dosyayı görüntüle @
1db66c2a
...
@@ -83,7 +83,6 @@ void RemoteServer::execute()
...
@@ -83,7 +83,6 @@ void RemoteServer::execute()
if
(
!
pSocket
->
readLine
(
aLine
)
)
delete
pSocket
;
if
(
!
pSocket
->
readLine
(
aLine
)
)
delete
pSocket
;
OString
aPin
(
aLine
);
OString
aPin
(
aLine
);
fprintf
(
stderr
,
"Pin:%s
\n
"
,
aPin
.
getStr
()
);
SocketAddr
aClientAddr
;
SocketAddr
aClientAddr
;
pSocket
->
getPeerAddr
(
aClientAddr
);
pSocket
->
getPeerAddr
(
aClientAddr
);
...
@@ -117,6 +116,8 @@ void RemoteServer::setup()
...
@@ -117,6 +116,8 @@ void RemoteServer::setup()
spServer
=
new
RemoteServer
();
spServer
=
new
RemoteServer
();
spServer
->
launch
();
spServer
->
launch
();
sd
::
BluetoothServer
::
setup
(
&
(
spServer
->
mCommunicators
)
);
}
}
...
@@ -211,7 +212,6 @@ void SdDLL::RegisterRemotes()
...
@@ -211,7 +212,6 @@ void SdDLL::RegisterRemotes()
sd
::
RemoteServer
::
setup
();
sd
::
RemoteServer
::
setup
();
sd
::
DiscoveryService
::
setup
();
sd
::
DiscoveryService
::
setup
();
sd
::
BluetoothServer
::
setup
();
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sd/source/ui/remotecontrol/Transmitter.cxx
Dosyayı görüntüle @
1db66c2a
...
@@ -13,9 +13,9 @@ using namespace std;
...
@@ -13,9 +13,9 @@ using namespace std;
using
namespace
osl
;
// Sockets etc.
using
namespace
osl
;
// Sockets etc.
using
namespace
sd
;
using
namespace
sd
;
Transmitter
::
Transmitter
(
StreamSocket
&
aSocket
)
Transmitter
::
Transmitter
(
BufferedStreamSocket
*
aSocket
)
:
Thread
(
"TransmitterThread"
),
:
Thread
(
"TransmitterThread"
),
m
StreamSocket
(
aSocket
),
p
StreamSocket
(
aSocket
),
mQueuesNotEmpty
(),
mQueuesNotEmpty
(),
mFinishRequested
(),
mFinishRequested
(),
mQueueMutex
(),
mQueueMutex
(),
...
@@ -38,13 +38,13 @@ void Transmitter::execute()
...
@@ -38,13 +38,13 @@ void Transmitter::execute()
{
{
OString
aMessage
(
mHighPriority
.
front
()
);
OString
aMessage
(
mHighPriority
.
front
()
);
mHighPriority
.
pop
();
mHighPriority
.
pop
();
mStreamSocket
.
write
(
aMessage
.
getStr
(),
aMessage
.
getLength
()
);
pStreamSocket
->
write
(
aMessage
.
getStr
(),
aMessage
.
getLength
()
);
}
}
else
if
(
!
mLowPriority
.
empty
()
)
else
if
(
!
mLowPriority
.
empty
()
)
{
{
OString
aMessage
(
mLowPriority
.
front
()
);
OString
aMessage
(
mLowPriority
.
front
()
);
mLowPriority
.
pop
();
mLowPriority
.
pop
();
mStreamSocket
.
write
(
aMessage
.
getStr
(),
aMessage
.
getLength
()
);
pStreamSocket
->
write
(
aMessage
.
getStr
(),
aMessage
.
getLength
()
);
}
}
if
(
mLowPriority
.
empty
()
&&
mHighPriority
.
empty
()
)
if
(
mLowPriority
.
empty
()
&&
mHighPriority
.
empty
()
)
...
...
sd/source/ui/remotecontrol/Transmitter.hxx
Dosyayı görüntüle @
1db66c2a
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
#include <osl/conditn.hxx>
#include <osl/conditn.hxx>
#include <osl/mutex.hxx>
#include <osl/mutex.hxx>
#include
<osl/socket.hxx>
#include
"BufferedStreamSocket.hxx"
#include <salhelper/thread.hxx>
#include <salhelper/thread.hxx>
#include <rtl/string.hxx>
#include <rtl/string.hxx>
...
@@ -25,7 +25,7 @@ class Transmitter
...
@@ -25,7 +25,7 @@ class Transmitter
{
{
public
:
public
:
enum
Priority
{
PRIORITY_LOW
=
1
,
PRIORITY_HIGH
};
enum
Priority
{
PRIORITY_LOW
=
1
,
PRIORITY_HIGH
};
Transmitter
(
osl
::
StreamSocket
&
aSocket
);
Transmitter
(
::
sd
::
BufferedStreamSocket
*
aSocket
);
~
Transmitter
();
~
Transmitter
();
void
addMessage
(
const
rtl
::
OString
&
aMessage
,
const
Priority
aPriority
);
void
addMessage
(
const
rtl
::
OString
&
aMessage
,
const
Priority
aPriority
);
void
notifyFinished
();
void
notifyFinished
();
...
@@ -33,7 +33,7 @@ public:
...
@@ -33,7 +33,7 @@ public:
private
:
private
:
void
execute
();
void
execute
();
::
osl
::
StreamSocket
m
StreamSocket
;
::
sd
::
BufferedStreamSocket
*
p
StreamSocket
;
::
osl
::
Condition
mQueuesNotEmpty
;
::
osl
::
Condition
mQueuesNotEmpty
;
::
osl
::
Condition
mFinishRequested
;
::
osl
::
Condition
mFinishRequested
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment