Skip to content

Commit

Permalink
Define ErrCode enum
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalg0wda committed Mar 10, 2017
1 parent f49c5f7 commit b45e087
Show file tree
Hide file tree
Showing 11 changed files with 212 additions and 355 deletions.
8 changes: 7 additions & 1 deletion hedroid/master/droid_keeper.thrift
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
enum ErrCode {
DEFAULT = 0,
NO_DROIDS_AVAILABLE = 1,
}

struct DroidRequest {
1: string user,
2: optional string apk_url,
Expand All @@ -11,7 +16,8 @@ struct ConnParams {
}

exception ApplicationException {
1: string msg
1: string msg,
2: optional i32 code = ErrCode.DEFAULT,
}

service DroidKeeper {
Expand Down
46 changes: 20 additions & 26 deletions hedroid/master/tgen/droid_keeper/DroidKeeper-remote
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
# Autogenerated by Thrift Compiler (0.9.3)
# Autogenerated by Thrift Compiler (0.9.0)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
Expand All @@ -12,32 +12,30 @@ import pprint
from urlparse import urlparse
from thrift.transport import TTransport
from thrift.transport import TSocket
from thrift.transport import TSSLSocket
from thrift.transport import THttpClient
from thrift.protocol import TBinaryProtocol

from droid_keeper import DroidKeeper
from droid_keeper.ttypes import *
import DroidKeeper
from ttypes import *

if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print('')
print('Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] [-s[sl]] function [arg1 [arg2...]]')
print('')
print('Functions:')
print(' void ping()')
print(' string get_package_name(string apk_url)')
print(' ConnParams get_endpoint_for_user(string user)')
print(' bool interact_with_endpoint(DroidRequest dr)')
print(' void release_endpoint_for_user(string user)')
print('')
print ''
print 'Usage: ' + sys.argv[0] + ' [-h host[:port]] [-u url] [-f[ramed]] function [arg1 [arg2...]]'
print ''
print 'Functions:'
print ' void ping()'
print ' string get_package_name(string apk_url)'
print ' ConnParams get_endpoint_for_user(string user)'
print ' bool interact_with_endpoint(DroidRequest dr)'
print ' void release_endpoint_for_user(string user)'
print ''
sys.exit(0)

pp = pprint.PrettyPrinter(indent = 2)
host = 'localhost'
port = 9090
uri = ''
framed = False
ssl = False
http = False
argi = 1

Expand Down Expand Up @@ -66,17 +64,13 @@ if sys.argv[argi] == '-f' or sys.argv[argi] == '-framed':
framed = True
argi += 1

if sys.argv[argi] == '-s' or sys.argv[argi] == '-ssl':
ssl = True
argi += 1

cmd = sys.argv[argi]
args = sys.argv[argi+1:]

if http:
transport = THttpClient.THttpClient(host, port, uri)
else:
socket = TSSLSocket.TSSLSocket(host, port, validate=False) if ssl else TSocket.TSocket(host, port)
socket = TSocket.TSocket(host, port)
if framed:
transport = TTransport.TFramedTransport(socket)
else:
Expand All @@ -87,36 +81,36 @@ transport.open()

if cmd == 'ping':
if len(args) != 0:
print('ping requires 0 args')
print 'ping requires 0 args'
sys.exit(1)
pp.pprint(client.ping())

elif cmd == 'get_package_name':
if len(args) != 1:
print('get_package_name requires 1 args')
print 'get_package_name requires 1 args'
sys.exit(1)
pp.pprint(client.get_package_name(args[0],))

elif cmd == 'get_endpoint_for_user':
if len(args) != 1:
print('get_endpoint_for_user requires 1 args')
print 'get_endpoint_for_user requires 1 args'
sys.exit(1)
pp.pprint(client.get_endpoint_for_user(args[0],))

elif cmd == 'interact_with_endpoint':
if len(args) != 1:
print('interact_with_endpoint requires 1 args')
print 'interact_with_endpoint requires 1 args'
sys.exit(1)
pp.pprint(client.interact_with_endpoint(eval(args[0]),))

elif cmd == 'release_endpoint_for_user':
if len(args) != 1:
print('release_endpoint_for_user requires 1 args')
print 'release_endpoint_for_user requires 1 args'
sys.exit(1)
pp.pprint(client.release_endpoint_for_user(args[0],))

else:
print('Unrecognized method %s' % cmd)
print 'Unrecognized method %s' % cmd
sys.exit(1)

transport.close()
Loading

0 comments on commit b45e087

Please sign in to comment.