pcremote-client-n8x0 -> client sources
[remotepc] / pcremote-server-desktop-60 / debian / pcremote-server / usr / share / pcremote-server / runserver.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 # ****************************************************************************
5 # Copyright (c) 2008 INdT/Fucapi.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 #  This program is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public License
17 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # ============================================================================
20 # Project Name : PC Remote
21 # Author       : Nilson ; Jonatas Izvi; Andre Portela
22 # Email        : fergus.mao@gmail.com ; nona@gmail.com ; 
23 #                andre_portela_@hotmail.com;
24 # Version      : 1.0
25 # Class        : Server File - This is the main script of the server
26 # ============================================================================
27
28 from connection.iconnection import *
29 from services.service import *
30 from utils import *
31 from utils.messages import *
32
33 class Server():
34
35     def __init__(self, AppName):
36         self.msgbox = Message(AppName)
37         self.msgbox.show_message("Server Initialized...")
38
39     def start(self, servername):
40
41         label = Labels()
42         iconn = Iconnection('blue')
43         iconn.bluetooth_create_server('l2cap', 0x1001)
44
45         address = iconn.get_client_address()
46
47         self.msgbox.show_message("Accepted connection from " + address[0])
48
49         while (1):
50
51             data = iconn.received_message()
52
53             if data == 'Tablet:#start':
54
55                 self.msgbox.show_message('Service Tablet initialized...')
56
57                 service = Service()
58                 service.set_service('Tablet')
59
60                 while(1):
61                     data = iconn.received_message()
62                     if data == 'Tablet:#stop':
63                         service.clean_all()
64                         self.msgbox.show_message('Service Tablet stoped')
65                         break
66                     service.execute(data)
67
68             elif data == 'Slideshow:#start':
69
70                 self.msgbox.show_message('Service Slideshow initialized...')
71
72                 service = Service()
73                 service.set_service('Slideshow')
74
75                 while(1):
76                     data = iconn.received_message()
77                     if data == 'Slideshow:#stop':
78                         service.clean_all()
79                         self.msgbox.show_message('Service Slideshow stoped')
80                         break
81                     print data, "\n"
82                     service.execute(data)
83     
84             elif data == 'Player:#start':
85
86                 self.msgbox.show_message('Service Player initialized...')
87
88                 service = Service()
89                 service.set_service('Player')
90
91                 while(1):
92                     data = iconn.received_message()
93                     if data == 'Player:#stop':
94                         self.msgbox.show_message('Service Player stoped')
95                         break
96                     elif data == 'Player:#download':
97                         service.set_address_to_download(address[0])
98                     elif data == 'Player:#load_playlist':
99                         # e preciso criar um metodo de transferencia
100                         # no caso de carregar uma playlist para o cliente
101                         service.execute_transfer(data)
102                 
103                         service.execute(data)
104
105             else:       
106                 exit(1)
107                         
108         self.msgbox.show_message('Desconected from ' + address[0])