X-Git-Url: http://git.maemo.org/git/?p=remotepc;a=blobdiff_plain;f=pcremote-client-n8x0-60%2Fdebian%2Fpcremote-client%2Fusr%2Fshare%2Fpcremote-client%2Fconnection%2Ficonnection.py;fp=pcremote-client-n8x0-60%2Fdebian%2Fpcremote-client%2Fusr%2Fshare%2Fpcremote-client%2Fconnection%2Ficonnection.py;h=118358d6606cb75da079dbe42e6a1f06650ffe8e;hp=0000000000000000000000000000000000000000;hb=8eeea3225c010dea378cdc71c4e91294e04a6e9c;hpb=e8447209e336f2a6845027f50b84cc914fa2c796 diff --git a/pcremote-client-n8x0-60/debian/pcremote-client/usr/share/pcremote-client/connection/iconnection.py b/pcremote-client-n8x0-60/debian/pcremote-client/usr/share/pcremote-client/connection/iconnection.py new file mode 100755 index 0000000..118358d --- /dev/null +++ b/pcremote-client-n8x0-60/debian/pcremote-client/usr/share/pcremote-client/connection/iconnection.py @@ -0,0 +1,164 @@ +# -*- coding: utf-8 -*- + +# **************************************************************************** +# Copyright (c) 2008 INdT/Fucapi. +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation, either version 3 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 Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . + +# ============================================================================ +# Project Name : PC Remote +# Author : André Portela +# Email : andre_portela_@hotmail.com +# Reviewer : Jônatas Isvi +# Email : jonatas.nona@gmail.com +# Version : 1.0 +# Description : Interface Class, connection manager +# ============================================================================ + +from wirelessconnectionmanager import * +from bluetoothconnectionmanager import * +from exceptions import * + + +# connections aliases +_btconst = ['bluetooth', 'BLUETOOTH', 'blue'] +_wificonst = ['wireless', 'WIRELESS', 'wifi'] + +class Iconnection: + def __init__(self, string): + self.string = string + if(self.string in _btconst): + self.obj = BluetoothConnectionManager() + elif(self.string in _wificonst): + self.obj = WirelessConnectionManager() + else: + raise IconnectionError, "Undefined type." + + + # ******************************************************************************** + # Generic methods -> Wireless and Bluetooth * + # ******************************************************************************** + + # create a socket with defined protocol + def create_socket(self, protocol=None): + self.obj.create_socket(protocol) + + # connect device + def connect(self): + self.obj.connect() + + # accept the connection + def accept(self): + return self.obj.accept() + + # send a message to device + def send_message(self, msg=None): + self.obj.send_message(msg) + + # received a message + def received_message(self): + return self.obj.received_message() + + # bind the connection + def bind(self): + self.obj.bind() + + # listen the connection + def listen(self): + self.obj.listen() + + # close connection + def close(self): + self.obj.close() + + # set the port to communicate + def set_port(self, port): + self.obj.set_port(port) + + # get the port to communicate + def get_port(self): + return self.obj.get_port() + + # set the device address + def set_address(self, address): + self.obj.set_address(address) + + # get the device address + def get_address(self): + return self.obj.get_address() + + # get the client address + def get_client_address(self): + return self.obj.get_client_address() + + # ************************************************************************************ + # Bluetooth methods - All methods for bluetooth services * + # ************************************************************************************ + + # fast way to create a simple server + def bt_create_server(self, protocol, port): + if self.string in _btconst: + return self.obj.create_server(protocol, port) + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + # fast way to create a simple client + def bt_create_client(self, protocol, address, port): + if self.string in _btconst: + return self.obj.create_client(protocol, address, port) + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + # search for all devices + def bt_find_devices(self, time=8): + if self.string in _btconst: + return self.obj.find_devices(time) + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + # search only devices names + def bt_find_devices_only_names(self): + if self.string in _btconst: + return self.obj.find_devices_only_names() + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + + # search the device port + def bt_find_port(self, addr): + if self.string in _btconst: + return self.obj.find_port(addr) + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + + # search device services + def bt_find_services(self, service=None, addr=None): + if self.string in _btconst: + return self.obj.find_services(service, addr) + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + + # search the device indicated by name + def bt_find_device_address_by_name(self, device_name=None): + if self.string in _btconst: + return self.obj.find_device_address_by_name(device_name) + else: + raise IconnectionError, "Only method used by Bluetooth connections." + + + + # *********************************************************************************** + # Wireless method - All methods for wireless services * + # ***********************************************************************************