Working with program > Automation (XML-RPC)

Navigation:  Working with program >

Automation (XML-RPC)

Previous pageReturn to chapter overviewNext page

Engineers, who would like to create their own extension to the Internet Cafe software the XML-RPC API is proposed. The number supported functions is growing up as it allow us to extend Android-application functionality "Компьютерный Зал" (https://play.google.com/store/apps/details?id=com.astrumsoft.czprototype1).

 

You can implement application that shows free, busy computers, start and stop their session.

 

Sample of usage (do it yourself): big TV shows what client computers are free, busy. The information is casted by Android box.

 

Read about XML-RPC at the wikipedia. The protocol is implemented for many programming languages, that manual will use python 3.3 samples.

 

What do you need to start?

 

Enable XML-RPC in server program security settings and set password (for example, "mypass"). Password to be used in all XML-RPC functions as first parameter.

 

URL to access XML-RPC: http://server-ip:8850/RPC2

 

Replace the server-ip with address of your server computer in local network. Port number is fixed at the moment. Your application and server program should be in the same local network. If it is Android-device, its WiFi address should be in the same network as server program.

 

Sample usage with python3.3 - return server program version.

 

>>> import xmlrpc.client

>>> proxy=xmlrpc.client.ServerProxy("http://192.168.100.100:8850/RPC2")

>>> proxy.version("mypass")

'3.91'

 

List all supported mehods:

 

>>> proxy.system.listMethods()

['system.listMethods', 'system.methodExist', 'system.methodHelp', 'system.methodSignature', 'system.multicall', 'system.shutdown', 'system.capabilities', 'numComps', 'version', 'compState', 'timeList', 'startTime', 'resetTime', 'currency', 'pauseTime', 'protocolVersion']

 

Show version method signature (input parameter is password-string, output is version-string):

 

>>> proxy.system.methodSignature("version")

[['string', 'string']]

 

Backwards compatibility of protocol versions

 

As server program and Android application are evolved separately, but interact using the same protocol, there should be a technique to guarantee the work of protocol (Android-application will receive responses on its requests).

 

The key is a protocol version:

 

>>> proxy.protocolVersion("mypass")

1

 

It is guaranteed that clients (for example, Android-application), that were created for lower version protocol, will continue to operate with server program of newer version.

We can invalidate the support of older protocol versions, so ideally you should have a newest server program and client program (Android-application), however we will try to keep backwards compatibility as much as possible.

Client (for example, Android) application, using newest protocol, will not work with older version of server program. Read about it here.

New functions to be added as usual, but if we will need to change the signature of old method, new method with the number at the end to be added (equal to old protocol version).

 

 

List of functions (API)

 

protocolVersion - return protocol version

 

>>> proxy.system.methodSignature("protocolVersion")

[['int', 'string']]

 

Input parameters: string - password to access server program

Output parameter: number - server program protocol version

 

>>> proxy.protocolVersion("mypass")

1

 

Read about backwards compatibility of protocol versions.

 

version - return server program version

 

>>> proxy.system.methodSignature("version")

[['string', 'string']]

 

Input parameters: string - password to access server program

Output parameter: string - server program version

 

>>> proxy.version("mypass")

'3.91'

 

numComps - return number of client computers in cafe

 

>>> proxy.system.methodSignature("numComps")

[['int', 'string']]

 

Input parameters: string - password to access server program

Output parameter: integer - number of client computers in cafe

 

>>> proxy.numComps("mypass")

16

 

compState - return the state of client computer

 

>>> proxy.system.methodSignature("compState")

[['struct', 'string', 'int']]

 

Input parameters:

string - password to access server program
client computer number (starting zero)

 

Output parameters: client computer state structure

List of output structure fields:

startFinishTime - string, start time of session in timer (post-paid) mode or end of session in pre-paid mode
discount - number, discount entered in the server program indicator
game - boolean, True if games and False if Internet mode
remainingSpentTime - string, the amount of spent time in timer (post-paid) mode or the remaining amount of time in pre-paid mode
online - boolean, True if client computer is connected to server program (corresponds to green connection status)
isFree - boolean. True if client computer is in use free of charge (field added starting with 4.29 version)

 

>>> proxy.compState("mypass", 3)

{'startFinishTime': '11:36', 'discount': 0, 'status': 2, 'game': False, 'remainingSpentTime': '1h 00min', 'online': False, 'isFree': False}

 

timeList - return the list of values used in the time entering field of indicator

 

>>> proxy.system.methodSignature("timeList")

[['array', 'string']]

 

Input parameters: string - password to access server program

Output parameter: string array - values in the time entering field of indicator

 

>>> proxy.timeList("mypass")

['20', '30', '40', '60', '120', 'Timer', 'Night', 'Half-night']

 

startTime - add time, start session for customer

 

>>> proxy.system.methodSignature("startTime")

[['int', 'string', 'int', 'boolean', 'int', 'string']]

 

Input parameters:

string - password to access server program
integer - client computer number (starting with zero)
boolean - True if games mode, False if Internet mode
number - discount
string - value that you enter in the time entering field of indicator, for example "60" - to add 60 minutes, "Timer" to start post-paid mode (timer mode)

 

Output parameter: number, not used

 

Add 60 minutes of games to client computer 16, no discount:

>>> proxy.startTime("mypass", 15, True, 0, "60")

0

 

resetTime - stop work session or stop timer

 

>>> proxy.system.methodSignature("resetTime")

[['string', 'string', 'int']]

 

Input parameters:

string - password to access server program
integer - client computer number (starting with zero)

 

Output parameter: string, if not empty, the charge amount (for example, when stop post-paid mode)

 

>>> proxy.resetTime("mypass",0)

'3.00'

 

currency - return currency name used in program

 

>>> proxy.system.methodSignature("currency")

[['string', 'string']]

 

Input parameters: string - password to access server program

Output parameter: string - currency name used in program (used to show payment amount, sum of cash, etc...)

 

>>> proxy.currency("mypass")

'$'

 

pauseTime - pause client computer session

 

>>> proxy.system.methodSignature("pauseTime")

[['int', 'string', 'int', 'string']]

 

Input parameters:

string - password to access server program
integer - client computer number (starting with zero)
string - pause reason

 

Output parameter: numner, not used

 

>>> proxy.pauseTime("mypass", 5, "out to smoke")

0

 

screenshot - get screenshot of client computer desktop

(protocol version 2)

 

>>> proxy.system.methodSignature("screenshot")

[['base64', 'string', 'int']]

 

Input parameters:

string - password to access server program
integer - client computer number (starting with zero)

 

Output parameter: binary, jpeg-image

 

>>> proxy.screenshot("mypass", 5)

<binary jpeg encoded image>

 

reboot - reboot client computer

(protocol version 2)

 

>>> proxy.system.methodSignature("reboot")

[['int', 'string', 'int']]

 

Input parameters:

string - password to access server program
integer - client computer number (starting with zero)

 

Output parameter: number, not used

 

>>> proxy.reboot("mypass", 5)

0

 

shutdown - shutdown client computer

(protocol version 2)

 

>>> proxy.system.methodSignature("shutdown")

[['int', 'string', 'int']]

 

Input parameters:

string - password to access server program
integer - client computer number (starting with zero)

 

Output parameter: number, not used

 

>>> proxy.shutdown("mypass", 5)

0