From d158fcec80f0a028d9c6c8dceb326de4f336910a Mon Sep 17 00:00:00 2001 From: Radu Ioan Fericean Date: Mon, 18 Apr 2016 19:07:37 +0300 Subject: [PATCH] work in proggress --- engine/action.go | 14 ++++++++++---- utils/rpc_object_test.go | 13 ++++++++++--- utils/rpc_objects.go | 4 ++-- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/engine/action.go b/engine/action.go index a7f9cdb5e..4018a7c1c 100644 --- a/engine/action.go +++ b/engine/action.go @@ -32,6 +32,7 @@ import ( "github.com/cgrates/cgrates/config" "github.com/cgrates/cgrates/utils" + "github.com/cgrates/rpcclient" ) /* @@ -651,19 +652,24 @@ func transferMonetaryDefaultAction(acc *Account, sq *StatsQueueTriggered, a *Act } type RPCRequest struct { - Server string + Address string Transport string Method string Attempts int Async bool - Arg map[string]interface{} + Param string } func cgrRPCAction(account *Account, sq *StatsQueueTriggered, a *Action, acs Actions) error { - rpcRequest := RPCRequest{} - if err := json.Unmarshal([]byte(a.ExtraParameters), &rpcRequest); err != nil { + req := RPCRequest{} + if err := json.Unmarshal([]byte(a.ExtraParameters), &req); err != nil { return err } + client, err := rpcclient.NewRpcClient(req.Method, req.Address, req.Attempts, 0, req.Transport, nil) + if err != nil { + return nil, err + } + client.Call() return nil } diff --git a/utils/rpc_object_test.go b/utils/rpc_object_test.go index 8cdf368c3..f42ea882a 100644 --- a/utils/rpc_object_test.go +++ b/utils/rpc_object_test.go @@ -8,14 +8,21 @@ func (rpc *RpcStruct) Hopa(normal string, out *float64) error { return nil } -func TestRPCObjectSimple(t *testing.T) { +func (rpc *RpcStruct) Tropa(pointer *string, out *float64) error { + return nil +} +func TestRPCObjectPointer(t *testing.T) { RegisterRpcObject("", &RpcStruct{}) - if len(RpcObjects) != 1 { + if len(RpcObjects) != 2 { t.Errorf("error registering rpc object: %v", RpcObjects) } x, found := RpcObjects["RpcStruct.Hopa"] - if found { + if !found { + t.Errorf("error getting rpcobject: %v (%+v)", RpcObjects, x) + } + x, found = RpcObjects["RpcStruct.Tropa"] + if !found { t.Errorf("error getting rpcobject: %v (%+v)", RpcObjects, x) } } diff --git a/utils/rpc_objects.go b/utils/rpc_objects.go index 6aef9be2e..22028d274 100644 --- a/utils/rpc_objects.go +++ b/utils/rpc_objects.go @@ -29,8 +29,8 @@ func RegisterRpcObject(name string, rpcObject interface{}) { if methodType.NumIn() == 3 { // if it has three parameters (one is self and two are rpc params) RpcObjects[name+"."+method.Name] = &RpcObject{ Object: objType, - InParam: reflect.New(methodType.In(1)).Elem().Interface(), - OutParam: reflect.New(methodType.In(2)).Elem().Interface(), + InParam: reflect.New(methodType.In(1)).Interface(), + OutParam: reflect.New(methodType.In(2).Elem()).Interface(), } }