Skip to content

Commit

Permalink
Reimplemented add-config-data-members, which was lost.
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Feuer committed Aug 16, 2012
1 parent 77b063d commit 4d03ecc
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
4 changes: 2 additions & 2 deletions json_rpc_example/add-config-data-members.jr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"id": "1",
"params":
{
"config-data": ["test12", "test11"],
"dev-id": [ "1234", "1235" ]
"config-data": ["test11"],
"dev-id": [ "1235" ]
}
}
10 changes: 10 additions & 0 deletions json_rpc_example/add-dilo-yang.jr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"jsonrpc": "2.0",
"method": "exodm:create-yang-module",
"id": "1",
"params": {
"repository": "user",
"name": "dilo",
"yang-module": "module dilo_tst { description: \"test\", prefix dilo_tst; notification swipe { leaf device_id { type string; } leaf data { type string; } } }"
}
}
44 changes: 40 additions & 4 deletions lib/exodm_rpc/src/exodm_rpc_exodm.erl
Original file line number Diff line number Diff line change
Expand Up @@ -75,28 +75,64 @@ json_rpc_({request, _ReqEnv,
{name, N},
{'yang-module', Y}]}} = _RPC, _Env) when R =:= ?USER_REPOSITORY->
?debug("~p:json_rpc(create-yang-module) repository:~p name:~p~n", [ ?MODULE, R, N ]),
_Res = exodm_db_yang:write(N, Y),
{ok, result_code(ok)};
Res = exodm_db_yang:write(N, Y),
io:format("YANG_RES: ~p\n", [ Res]),
case Res of
ok ->
{ok, result_code(ok)};

{error, {Line, Fmt, Arg } } ->
?info("~p:json_rpc(create-yang-module): Error: Line: ~p: ~p\n",
[?MODULE, Line, io_lib:fwrite(Fmt, Arg) ]),
{ok, result_code('validation-failed')};

Err ->
?info("~p:json_rpc(create-yang-module): Error: ~p\n",
[?MODULE, Err ]),
{ok, result_code('validation-failed')}
end;


json_rpc_({request, _ReqEnv,
{call, exodm, 'provision-device',
[{'dev-id', I},
{'server-key', SK},
{'device-key', DK}]}} = _RPC, _Env) ->
?debug("~p:json_rpc(provision-device) device-id:~p server-key:~p device-key:~p~n",
?debug("~p:json_rpc(provision-device) dev-id:~p server-key:~p device-key:~p~n",
[ ?MODULE, I, SK, DK ]),

exodm_db_device:new(exodm_db_session:get_aid(), I, [{'__ck', <<DK:64/little>>},
{'__sk', <<SK:64/little>>}]),
{ok, result_code(ok)};




json_rpc_({request, _ReqEnv,
{call, exodm, 'add-config-data-members',
[{'config-data', {array, CfgDataList}},
{'dev-id', {array, DevIdList}}]}} = _RPC, _Env) ->
?debug("~p:json_rpc(add-config-data-members) dev-id:~p config-data:~p~n",
[ ?MODULE, CfgDataList, DevIdList ]),
AID = exodm_db_session:get_aid(),

try [ fun(CfgData) ->
exodm_db_config:add_config_data_members(AID, CfgData, DevIdList)
end
|| CfgData <- CfgDataList] of
_Res -> {ok, result_code(ok)}
catch error:E ->
?debug("RPC = ~p; ERROR = ~p~n",
[_RPC, {E, erlang:get_stacktrace()}]),
{error, E}
end;

json_rpc_({request, _ReqEnv,
{call, exodm, 'push-config-data',
[{'config-data', Cfg}]}} = _RPC, _Env) ->
?debug("~p:json_rpc(push-config-data) config-data:~p ~n", [ ?MODULE, Cfg ]),
_AID = exodm_db_session:get_aid(),
AID = exodm_db_session:get_aid(),

{ok, result_code(ok)};

json_rpc_(RPC, _ENV) ->
Expand Down

0 comments on commit 4d03ecc

Please sign in to comment.