diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-09-08 15:59:00 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-09-12 10:20:09 +0200 |
commit | 159c895986f2358d6df8bb5804cc4419cc6b457f (patch) | |
tree | 7c6e43fe9c412bfa30d33e75dbce114b7540ce37 /src/afb-proto-ws.h | |
parent | 6415707ead57b42a52e7752dc197a5dac479ce3d (diff) |
afb-proto-ws: Split afb-stub-ws in twoeel_4.99.1eel/4.99.14.99.1
The file afb-stub-ws is split in two parts:
- afb-stub-ws: implements the interface between
xreq and protocol.
- afb-proto-ws: implements the pbinary protocol
over wer sockets
The intent is to have a clean separation between
a kind of generic stub and the protocol implmentation.
This will allow soon to provide a library to access
directly in C to the websocket of an API exposed
through the otpion --ws-server.
At the moment, the protocol implementation is on
websockets but in the futur it will be cleanly
rewritten to use any binary transport.
This commit also fixe a double free in subcalls.
Change-Id: I831787533db9fe073d060dd8ee9401cbab2894e1
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-proto-ws.h')
-rw-r--r-- | src/afb-proto-ws.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/afb-proto-ws.h b/src/afb-proto-ws.h new file mode 100644 index 00000000..9cdf4902 --- /dev/null +++ b/src/afb-proto-ws.h @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2016, 2017 "IoT.bzh" + * Author: José Bollo <jose.bollo@iot.bzh> + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#pragma once + +struct afb_proto_ws; +struct afb_proto_ws_call; +struct afb_proto_ws_subcall; +struct afb_proto_ws_describe; + +struct afb_proto_ws_client_itf +{ + void (*on_reply_success)(void *closure, void *request, struct json_object *result, const char *info); + void (*on_reply_fail)(void *closure, void *request, const char *status, const char *info); + + void (*on_event_create)(void *closure, const char *event_name, int event_id); + void (*on_event_remove)(void *closure, const char *event_name, int event_id); + void (*on_event_subscribe)(void *closure, void *request, const char *event_name, int event_id); + void (*on_event_unsubscribe)(void *closure, void *request, const char *event_name, int event_id); + void (*on_event_push)(void *closure, const char *event_name, int event_id, struct json_object *data); + void (*on_event_broadcast)(void *closure, const char *event_name, struct json_object *data); + + void (*on_subcall)(void *closure, struct afb_proto_ws_subcall *subcall, void *request, const char *api, const char *verb, struct json_object *args); +}; + +struct afb_proto_ws_server_itf +{ + void (*on_call)(void *closure, struct afb_proto_ws_call *call, const char *verb, struct json_object *args, const char *sessionid); + void (*on_describe)(void *closure, struct afb_proto_ws_describe *describe); +}; + +extern struct afb_proto_ws *afb_proto_ws_create_client(int fd, const struct afb_proto_ws_client_itf *itf, void *closure); +extern struct afb_proto_ws *afb_proto_ws_create_server(int fd, const struct afb_proto_ws_server_itf *itf, void *closure); + +extern void afb_proto_ws_unref(struct afb_proto_ws *protows); +extern void afb_proto_ws_addref(struct afb_proto_ws *protows); + +extern int afb_proto_ws_is_client(struct afb_proto_ws *protows); +extern int afb_proto_ws_is_server(struct afb_proto_ws *protows); + +extern void afb_proto_ws_hangup(struct afb_proto_ws *protows); +extern void afb_proto_ws_on_hangup(struct afb_proto_ws *protows, void (*on_hangup)(void *closure)); + + + +extern int afb_proto_ws_client_call(struct afb_proto_ws *protows, const char *verb, struct json_object *args, const char *sessionid, void *request); +extern int afb_proto_ws_client_describe(struct afb_proto_ws *protows, void (*callback)(void*, struct json_object*), void *closure); + +extern int afb_proto_ws_server_event_create(struct afb_proto_ws *protows, const char *event_name, int event_id); +extern int afb_proto_ws_server_event_remove(struct afb_proto_ws *protows, const char *event_name, int event_id); +extern int afb_proto_ws_server_event_push(struct afb_proto_ws *protows, const char *event_name, int event_id, struct json_object *data); +extern int afb_proto_ws_server_event_broadcast(struct afb_proto_ws *protows, const char *event_name, struct json_object *data); + +extern void afb_proto_ws_call_addref(struct afb_proto_ws_call *call); +extern void afb_proto_ws_call_unref(struct afb_proto_ws_call *call); + +extern int afb_proto_ws_call_success(struct afb_proto_ws_call *call, struct json_object *obj, const char *info); +extern int afb_proto_ws_call_fail(struct afb_proto_ws_call *call, const char *status, const char *info); + +extern int afb_proto_ws_call_subcall(struct afb_proto_ws_call *call, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure); +extern int afb_proto_ws_call_subscribe(struct afb_proto_ws_call *call, const char *event_name, int event_id); +extern int afb_proto_ws_call_unsubscribe(struct afb_proto_ws_call *call, const char *event_name, int event_id); + +extern int afb_proto_ws_subcall_reply(struct afb_proto_ws_subcall *subcall, int status, struct json_object *result); + +extern int afb_proto_ws_describe_put(struct afb_proto_ws_describe *describe, struct json_object *description); + |