def messagehandler(self,message):
    		connection_manager = ConnectionManager(self.associated_devices) 
		print('Request received from eventbus')
		print(message)
		thread = None
		if message != None:
			body = message['body']
			action = body['action']
			payload = body['payload']
			if action == "CONNECT":
    				deviceName = payload['deviceName']
				connection_manager.connect_device(deviceName)
			elif action == "INQUIRY":
				print action
				self.devices = []
				thread = inquiryThread(eb, self.devices, body['id'], associated_devices)
			elif action == "READ" or action == "WRITE":
				deviceURI = body['device']
				if connection_manager.contains_name(deviceURI):
    					thread = PersistentConnectionThread(eb, connection_manager.get_btsocket_for_name(deviceURI), body)
				else:
					print action
					for device in self.associated_devices:
						if device['name'] == deviceURI:
							deviceMAC = device['address']
							thread = communicationThread(eb, deviceMAC, body)
			elif action == "disconnect":
				deviceURI = body['device']
				del devices[deviceURI]	
		else:
			print("no msg found")
		thread.start()
Beispiel #2
0
 def connectToServer(self, server):
     """
     Launches Urban Terror and connect to the passed server
     
     @param server - the server to connect to 
     """
     Log.log.debug('[GuiController] connectToServer called...')
     
     cm = ConnectionManager()
     cm.connectToServer(server)
Beispiel #3
0
    def __init__(self, server_ips, mac=None, f=None):
        if f:
            self.f = f

        self.server_ips = server_ips
        raw_ips = lambda ip: bytes(map(int, ip.split(".")))
        self.server_ips_raw = tuple(map(raw_ips, server_ips))

        self.qi = Queue()
        self.qo = Queue()
        ConnectionManager(self.qi, self.qo, server_ips).start()

        self.ndisapi = windll.ndisapi
        self.kernel32 = windll.kernel32

        self.hnd = self.ndisapi.OpenFilterDriver(DRIVER_NAME_A)
        tmp = TCP_AdapterList()
        self.ndisapi.GetTcpipBoundAdaptersInfo(self.hnd, byref(tmp))

        self.mode = ADAPTER_MODE()
        self.mode.dwFlags = MSTCP_FLAG_SENT_TUNNEL | MSTCP_FLAG_RECV_TUNNEL

        adapter_id = None
        if mac != None:
            for i in range(tmp.m_nAdapterCount):
                if mac == pmac(tmp.m_czCurrentAddress[i]):
                    adapter_id = i + 1
                    break
            else:
                print("Can't find mac = {} in adapters list\n".format(mac))
        if adapter_id == None:
            print("Use 'ipconfig /all' to determine your mac address")
            print("you can write it in 'mac.txt' for more silent run\n")
            for i in range(tmp.m_nAdapterCount):
                print("{}). {}".format(i + 1, pmac(tmp.m_czCurrentAddress[i])))
            adapter_id = int(input("#: "))
            mac = pmac(tmp.m_czCurrentAddress[adapter_id - 1])

        print("\nUsing:\n\tadapter id = {}\n\tmac = {}".format(
            adapter_id, mac))
        self.mode.hAdapterHandle = tmp.m_nAdapterHandle[adapter_id - 1]

        self.hEvent = self.kernel32.CreateEventW(None, True, False, None)
        self.ndisapi.SetPacketEvent(self.hnd, self.mode.hAdapterHandle,
                                    self.hEvent)

        self.request = ETH_REQUEST()
        self.packetbuffer = INTERMEDIATE_BUFFER()
        self.request.EthPacket.Buffer = pointer(self.packetbuffer)
        self.request.hAdapterHandle = self.mode.hAdapterHandle

        self.ndisapi.SetAdapterMode(self.hnd, byref(self.mode))
        register(self.release)
    def __init__(self):
        super().__init__()
        self.CONNECTIONS_FILE = "wii.motes"
        self.card_id = 0
        self.wiimote = None
        self.ir_callback_count = 0
        self.old_x_coord = 0
        self.old_y_coord = 0
        self.all_cards = []
        self.default_delete_card_style = None

        self.my_vector_transform = VectorTransform()
        self.classifier = GestureClassifier()
        self.connections = ConnectionManager()
        self.classifier.register_callback(self.handle_shake_gesture)

        self.init_ui()
        self.load_available_charts()
        self.display_known_wiimotes()
Beispiel #5
0
class GtkUI(object):
    def __init__(self, args):
        self.daemon_bps = (0, 0, 0)
        # Setup signals
        try:
            import gnome.ui
            import gnome

            #Suppress: Warning: Attempt to add property GnomeProgram::*** after class was initialised
            original_filters = warnings.filters[:]
            warnings.simplefilter("ignore")
            try:
                self.gnome_prog = gnome.init("Deluge",
                                             deluge.common.get_version())
            finally:
                warnings.filters = original_filters

            self.gnome_client = gnome.ui.master_client()

            def on_die(*args):
                reactor.stop()

            self.gnome_client.connect("die", on_die)
            log.debug("GNOME session 'die' handler registered!")
        except Exception, e:
            log.warning(
                "Unable to register a 'die' handler with the GNOME session manager: %s",
                e)

        if deluge.common.windows_check():
            from win32api import SetConsoleCtrlHandler
            from win32con import CTRL_CLOSE_EVENT
            from win32con import CTRL_SHUTDOWN_EVENT

            def win_handler(ctrl_type):
                log.debug("ctrl_type: %s", ctrl_type)
                if ctrl_type in (CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT):
                    reactor.stop()
                    return 1

            SetConsoleCtrlHandler(win_handler)

        if deluge.common.osx_check() and Gdk.WINDOWING == "quartz":
            import gtkosx_application
            self.osxapp = gtkosx_application.gtkosx_application_get()

            def on_die(*args):
                reactor.stop()

            self.osxapp.connect("NSApplicationWillTerminate", on_die)

        # Set process name again to fix gtk issue
        setproctitle(getproctitle())

        # Attempt to register a magnet URI handler with gconf, but do not overwrite
        # if already set by another program.
        common.associate_magnet_links(False)

        # Make sure gtkui.conf has at least the defaults set
        self.config = deluge.configmanager.ConfigManager(
            "gtkui.conf", DEFAULT_PREFS)

        # We need to check on exit if it was started in classic mode to ensure we
        # shutdown the daemon.
        self.started_in_classic = self.config["classic_mode"]

        # Start the IPC Interface before anything else.. Just in case we are
        # already running.
        self.queuedtorrents = QueuedTorrents()
        self.ipcinterface = IPCInterface(args)

        # Initialize gdk threading
        Gdk.threads_init()
        GObject.threads_init()

        # We make sure that the UI components start once we get a core URI
        client.set_disconnect_callback(self.__on_disconnect)

        self.trackericons = TrackerIcons()
        self.sessionproxy = SessionProxy()
        # Initialize various components of the gtkui
        self.mainwindow = MainWindow()
        self.menubar = MenuBar()
        self.toolbar = ToolBar()
        self.torrentview = TorrentView()
        self.torrentdetails = TorrentDetails()
        self.sidebar = SideBar()
        self.filtertreeview = FilterTreeView()
        self.preferences = Preferences()
        self.systemtray = SystemTray()
        self.statusbar = StatusBar()
        self.addtorrentdialog = AddTorrentDialog()

        if deluge.common.osx_check() and Gdk.WINDOWING == "quartz":

            def nsapp_open_file(osxapp, filename):
                # Will be raised at app launch (python opening main script)
                if filename.endswith('Deluge-bin'):
                    return True
                from deluge.ui.gtkui.ipcinterface import process_args
                process_args([filename])

            self.osxapp.connect("NSApplicationOpenFile", nsapp_open_file)
            from menubar_osx import menubar_osx
            menubar_osx(self, self.osxapp)
            self.osxapp.ready()

        # Initalize the plugins
        self.plugins = PluginManager()

        # Show the connection manager
        self.connectionmanager = ConnectionManager()

        from twisted.internet.task import LoopingCall
        rpc_stats = LoopingCall(self.print_rpc_stats)
        rpc_stats.start(10)

        reactor.callWhenRunning(self._on_reactor_start)
        # Start the gtk main loop
        Gdk.threads_enter()
        reactor.run()
        self.shutdown()
        Gdk.threads_leave()
Beispiel #6
0
 def __init__(self, outbound_channel, associated_resources):
     self.resources = []
     self.associated_resources = associated_resources
     self.connection_manager = ConnectionManager(self.associated_resources)
     self.eventbus = None
     self.outbound_channel = outbound_channel
Beispiel #7
0
class GtkUI(object):
    def __init__(self, args):
        self.daemon_bps = (0, 0, 0)
        # Setup signals
        try:
            import gnome.ui
            import gnome
            self.gnome_prog = gnome.init("Deluge", deluge.common.get_version())
            self.gnome_client = gnome.ui.master_client()

            def on_die(*args):
                reactor.stop()

            self.gnome_client.connect("die", on_die)
            log.debug("GNOME session 'die' handler registered!")
        except Exception, e:
            log.warning(
                "Unable to register a 'die' handler with the GNOME session manager: %s",
                e)

        if deluge.common.windows_check():
            from win32api import SetConsoleCtrlHandler
            from win32con import CTRL_CLOSE_EVENT
            from win32con import CTRL_SHUTDOWN_EVENT

            def win_handler(ctrl_type):
                log.debug("ctrl_type: %s", ctrl_type)
                if ctrl_type in (CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT):
                    reactor.stop()
                    return 1

            SetConsoleCtrlHandler(win_handler)

        # Attempt to register a magnet URI handler with gconf, but do not overwrite
        # if already set by another program.
        common.associate_magnet_links(False)

        # Make sure gtkui.conf has at least the defaults set
        self.config = deluge.configmanager.ConfigManager(
            "gtkui.conf", DEFAULT_PREFS)

        # We need to check on exit if it was started in classic mode to ensure we
        # shutdown the daemon.
        self.started_in_classic = self.config["classic_mode"]

        # Start the IPC Interface before anything else.. Just in case we are
        # already running.
        self.queuedtorrents = QueuedTorrents()
        self.ipcinterface = IPCInterface(args)

        # Initialize gdk threading
        gtk.gdk.threads_init()

        # We make sure that the UI components start once we get a core URI
        client.set_disconnect_callback(self.__on_disconnect)

        self.trackericons = TrackerIcons()
        self.sessionproxy = SessionProxy()
        # Initialize various components of the gtkui
        self.mainwindow = MainWindow()
        self.menubar = MenuBar()
        self.toolbar = ToolBar()
        self.torrentview = TorrentView()
        self.torrentdetails = TorrentDetails()
        self.sidebar = SideBar()
        self.filtertreeview = FilterTreeView()
        self.preferences = Preferences()
        self.systemtray = SystemTray()
        self.statusbar = StatusBar()
        self.addtorrentdialog = AddTorrentDialog()

        # Initalize the plugins
        self.plugins = PluginManager()

        # Late import because of setting up translations
        from connectionmanager import ConnectionManager
        # Show the connection manager
        self.connectionmanager = ConnectionManager()

        from twisted.internet.task import LoopingCall
        rpc_stats = LoopingCall(self.print_rpc_stats)
        rpc_stats.start(10)

        reactor.callWhenRunning(self._on_reactor_start)

        # Initialize gdk threading
        gtk.gdk.threads_enter()
        reactor.run()
        self.shutdown()
        gtk.gdk.threads_leave()
 def __init__(self, associated_devices):
     self.devices = []
     self.associated_devices = associated_devices
     self.connection_manager = ConnectionManager(self.associated_devices)