def __init__(self, rw_socket, heart_beat_enable=False):
     print "RWCloudSocketAutoHandler init"
     self.running = True
     #RPC methods
     methods = {
         "cloud.register": self.__cloudRegister,
         "cloud.unregister": self.__cloudUnregister,
         "manager.agent.announce": self.__managerAgentAnnounce,
         "manager.agent.attach": self.__managerAgentAttach,
         "manager.agent.detach": self.__dummpyEventHandler,
         "wlan.event.scanresult": self.__wlanEventScanresult,
         "wlan.ap.event.dfslist": self.__dummpyEventHandler,
         "wlan.ap.event.radar": self.__dummpyEventHandler,
         "wlan.ap.event.statechange": self.__dummpyEventHandler,
         "wlan.event.scanresult": self.__dummpyEventHandler,
         "wlan.event.spectralreport": self.__dummpyEventHandler
     }
     self.rpc = pyjsonrpc.JsonRpc(methods)
     self.__client_sock = rw_socket
     self.__heartbeat_started = False
     self.__listener_started = False
     self.__heartbeat_enable = heart_beat_enable
     self.__socket_response_queue = Queue.Queue(
         maxsize=MAX_RESPONSE_QUEUE_SIZE)
     #self.__listener(rw_socket)
     self.subscribe_notification_list = [
         "manager.agent.announce", "manager.agent.attach",
         "manager.agent.detach", "wlan.event.scanresult",
         "wlan.ap.event.dfslist", "wlan.ap.event.radar",
         "wlan.ap.event.statechange", "wlan.event.spectralreport"
     ]
Beispiel #2
0
def mixed_params_example():

    # Initialize JSON-RPC-Class with JSON-RPC-Methods
    rpc = pyjsonrpc.JsonRpc(methods={"add": add})

    # Create JSON-RPC-string with mixed params
    request_json = pyjsonrpc.create_request_json("add", 1, b=2)
    # '{"params": {"b": 2, "__args": [1]}, "jsonrpc": "2.0", "method": "add", "id": "..."}'
    print "Request-JSON:", repr(request_json)

    # RPC-Call
    response_json = rpc.call(request_json)
    # '{"jsonrpc": "2.0", "id": "...", "result": 3}'
    print "Response-JSON:", repr(response_json)

    # Result
    response = pyjsonrpc.parse_response_json(response_json)
    if response.error:
        print "Error:", response.error.code, response.error.message
    else:
        # 3
        print "Result:", response.result
def test_positional_params_example():

    # Initialize JSON-RPC-Class with JSON-RPC-Methods
    rpc = pyjsonrpc.JsonRpc(methods = {"add": add})

    # Create JSON-RPC-string with positional params
    request_json = pyjsonrpc.create_request_json("add", 1, 2)
    # '{"params": [1, 2], "jsonrpc": "2.0", "method": "add", "id": "..."}'
    #print "Request-JSON:", repr(request_json)

    # RPC-Call
    response_json = rpc.call(request_json)
    # '{"jsonrpc": "2.0", "id": "...", "result": 3}'
    #print "Response-JSON:", repr(response_json)

    # Result
    response = pyjsonrpc.parse_response_json(response_json)
    if response.error:
        print "Error:", response.error.code, response.error.message
    else:
        # 3
        #print "Result:", response.result
        assert response.result == 3
Beispiel #4
0
 def update_rpc(self):
     self.rpc = pyjsonrpc.JsonRpc(methods = self.d_funcs)
import sys
THISDIR = os.path.dirname(os.path.abspath(__file__))
APPDIR = os.path.abspath(os.path.join(THISDIR, os.path.pardir, os.path.pardir))
sys.path.insert(0, APPDIR)
# END --- required only for testing, remove in real world code --- END

import pyjsonrpc


def add(a, b):
    """Test function"""
    return a + b


# 1. Initialize JSON-RPC class with JSON-RPC method(s)
rpc = pyjsonrpc.JsonRpc(methods={"add": add})

# 2. Create JSON-RPC string with parameters (= request string)
request_json = pyjsonrpc.create_request_json("add", 1, 2)
# request_json = '{"method": "add", "params": [1, 2], "id": "...", "jsonrpc": "2.0"}'

# 3. Call the JSON-RPC function and get back the JSON-RPC result (= response string)
response_json = rpc.call(request_json)
# response_json = '{"result": 3, "id": "...", "jsonrpc": "2.0"}'

# 4. Convert JSON-RPC string to Python objects
response = pyjsonrpc.parse_response_json(response_json)

# 5. Print result or error
if response.error:
    print "Error:", response.error.code, response.error.message