Changeset 50 for remote_control/puzzlebox_brainstorms_client_thinkgear.py
- Timestamp:
- 06/16/10 22:09:46 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
remote_control/puzzlebox_brainstorms_client_thinkgear.py
r49 r50 17 17 18 18 from twisted.internet import reactor, protocol, defer 19 from twisted.protocols import basic 19 20 20 21 import puzzlebox_brainstorms_configuration as configuration … … 33 34 NO_REPLY_WAIT = configuration.NO_REPLY_WAIT 34 35 36 35 37 AUTHORIZATION_REQUEST = configuration.THINKGEAR_AUTHORIZATION_REQUEST 36 38 37 PARAMETERS = {"enableRawOutput": False, "format": "Json"} 39 THINKGEAR_PARAMETERS = {"enableRawOutput": False, "format": "Json"} 40 #THINKGEAR_PARAMETERS = {"enableRawOutput": True, "format": "Json"} 38 41 39 42 ##################################################################### … … 56 59 self.server_port = server_port 57 60 self.max_connection_attempts = MAX_CONNECTION_ATTEMPTS 61 62 63 ################################################################## 64 65 def send_command(self, \ 66 command, \ 67 max_connection_attempts=MAX_CONNECTION_ATTEMPTS): 68 69 factory = puzzlebox_brainstorms_client_thinkgear_factory(self.log, \ 70 command, \ 71 self.server_host, \ 72 self.server_port, \ 73 max_connection_attempts, \ 74 self.DEBUG) 75 76 reactor.connectTCP(self.server_host, self.server_port, factory) 77 78 return factory.replyDefer 58 79 59 80 … … 78 99 print "---> [Client] Server Response:", 79 100 print response 80 81 reactor.stop() 82 101 102 103 ##################################################################### 104 # ThinkGear Client Protocol class 105 ##################################################################### 106 107 class puzzlebox_brainstorms_client_thinkgear_protocol( \ 108 basic.LineReceiver): 109 110 delimiter='\r' 111 112 ## def __init__(self): 113 ## 114 ## self.DEBUG = DEBUG 115 116 117 ################################################################## 118 119 ## def connectionMade(self): 120 ## 121 ## #data = pickle.dumps(self.factory.command) 122 ## data = json.dumps(self.factory.command) 123 ## self.transport.write(data) 124 ## 125 ## self.factory.noReply = reactor.callLater(NO_REPLY_WAIT, self.noReply) 126 127 128 ################################################################## 129 130 ## def noReply(self): 131 ## 132 ## try: 133 ## self.factory.replyDefer.callback('NO_REPLY') 134 ## except: 135 ## if self.DEBUG: 136 ## print "noReply failed to call callback" 137 ## #self.factory.log.error("noReply failed to call callback") 138 ## 139 ## self.transport.loseConnection() 140 141 142 ################################################################## 143 144 def lineReceived(self, line): 145 146 # Ignore blank lines 147 if not line: 148 return 149 150 151 data = json.loads(line) 152 print "data:", 153 print data 154 155 156 ##################################################################### 157 # ThinkGear Client Factory class 158 ##################################################################### 159 160 class puzzlebox_brainstorms_client_thinkgear_factory( \ 161 client.puzzlebox_brainstorms_client_send_command_factory): 162 163 def __init__(self, log, \ 164 command, \ 165 server_host=SERVER_HOST, \ 166 server_port=SERVER_PORT, \ 167 max_connection_attempts=MAX_CONNECTION_ATTEMPTS, \ 168 DEBUG=DEBUG): 169 170 self.log = log 171 self.DEBUG = DEBUG 172 self.server_host = server_host 173 self.server_port = server_port 174 self.command = command 175 176 self.max_connection_attempts = max_connection_attempts 177 self.connection_attempt = 1 178 179 self.protocol = \ 180 puzzlebox_brainstorms_client_thinkgear_protocol 181 182 self.replyDefer = defer.Deferred() 183 83 184 84 185 ##################################################################### … … 92 193 93 194 #authorization_request = AUTHORIZATION_REQUEST 94 authorization_request = None # Sending JSON not working 195 authorization_request = None # ThinkGear authentication not working 196 thinkgear_parameters = THINKGEAR_PARAMETERS 95 197 96 198 #log.info("Command parameters: %s" % command_parameters) … … 105 207 reactor.callWhenRunning( \ 106 208 thinkgear_client.send_command_and_print_response, \ 107 thinkgear_ client.authorization_request)209 thinkgear_parameters) 108 210 109 211
Note: See TracChangeset
for help on using the changeset viewer.