| 1 |
/* |
| 2 |
* Copyright (C) 2014 Red Hat, Inc. |
| 3 |
* SPDX-License-Identifier: LGPL-2.1-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __COCKPIT_TRANSPORT_H__ |
| 7 |
#define __COCKPIT_TRANSPORT_H__ |
| 8 |
|
| 9 |
#include <glib-object.h> |
| 10 |
#include <json-glib/json-glib.h> |
| 11 |
|
| 12 |
G_BEGIN_DECLS |
| 13 |
|
| 14 |
#define COCKPIT_TYPE_TRANSPORT (cockpit_transport_get_type ()) |
| 15 |
G_DECLARE_DERIVABLE_TYPE(CockpitTransport, cockpit_transport, COCKPIT, TRANSPORT, GObject) |
| 16 |
|
| 17 |
struct _CockpitTransportClass |
| 18 |
{ |
| 19 |
GObjectClass parent_class; |
| 20 |
|
| 21 |
/* signals */ |
| 22 |
|
| 23 |
/* |
| 24 |
* Fired when the transport receives a new message. |
| 25 |
*/ |
| 26 |
gboolean (* recv) (CockpitTransport *transport, |
| 27 |
const gchar *channel, |
| 28 |
GBytes *data); |
| 29 |
|
| 30 |
gboolean (* control) (CockpitTransport *transport, |
| 31 |
const char *command, |
| 32 |
const gchar *channel, |
| 33 |
JsonObject *options, |
| 34 |
GBytes *payload); |
| 35 |
|
| 36 |
void (* closed) (CockpitTransport *transport, |
| 37 |
const gchar *problem); |
| 38 |
|
| 39 |
/* vfuncs */ |
| 40 |
|
| 41 |
/* |
| 42 |
* Called when transport should queue a new message to send. |
| 43 |
*/ |
| 44 |
void (* send) (CockpitTransport *transport, |
| 45 |
const gchar *channel, |
| 46 |
GBytes *data); |
| 47 |
|
| 48 |
void (* close) (CockpitTransport *transport, |
| 49 |
const gchar *problem); |
| 50 |
}; |
| 51 |
|
| 52 |
void cockpit_transport_send (CockpitTransport *transport, |
| 53 |
const gchar *channel, |
| 54 |
GBytes *data); |
| 55 |
|
| 56 |
void cockpit_transport_close (CockpitTransport *transport, |
| 57 |
const gchar *problem); |
| 58 |
|
| 59 |
void cockpit_transport_emit_recv (CockpitTransport *transport, |
| 60 |
const gchar *channel, |
| 61 |
GBytes *data); |
| 62 |
|
| 63 |
void cockpit_transport_emit_control (CockpitTransport *transport, |
| 64 |
const gchar *command, |
| 65 |
const gchar *channel, |
| 66 |
JsonObject *options, |
| 67 |
GBytes *data); |
| 68 |
|
| 69 |
void cockpit_transport_emit_closed (CockpitTransport *transport, |
| 70 |
const gchar *problem); |
| 71 |
|
| 72 |
void cockpit_transport_freeze (CockpitTransport *transport, |
| 73 |
const gchar *channel); |
| 74 |
|
| 75 |
void cockpit_transport_thaw (CockpitTransport *transport, |
| 76 |
const gchar *channel); |
| 77 |
|
| 78 |
GBytes * cockpit_transport_parse_frame (GBytes *message, |
| 79 |
gchar **channel); |
| 80 |
|
| 81 |
gboolean cockpit_transport_parse_command (GBytes *payload, |
| 82 |
const gchar **command, |
| 83 |
const gchar **channel, |
| 84 |
JsonObject **options); |
| 85 |
|
| 86 |
JsonObject *cockpit_transport_build_json (const gchar *name, |
| 87 |
...) G_GNUC_NULL_TERMINATED; |
| 88 |
|
| 89 |
GBytes * cockpit_transport_build_control (const gchar *name, |
| 90 |
...) G_GNUC_NULL_TERMINATED; |
| 91 |
|
| 92 |
G_END_DECLS |
| 93 |
|
| 94 |
#endif /* __COCKPIT_TRANSPORT_H__ */ |