summaryrefslogtreecommitdiff
path: root/include/hybbx/plugin.h
blob: 9a51211ac835d5b1517334ce104b4764882ff9b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef HYBBX_PLUGIN_H
#define HYBBX_PLUGIN_H

#include "hybbx/types.h"

#ifdef __cplusplus
extern "C" {
#endif

struct hybbx_service;
struct hybbx_session;
struct hybbx_parsed_command;

/**
 * Transport plugin interface (link adapters / host-client bridges).
 *
 * HyBBX is plugin-only: session core + plugins. Modems, TNCs, sound-card
 * software, ARDOPC, and CRDOPC are external — never embedded in HyBBX.
 *
 * Core uses TCP/IPv4+IPv6 and HBX internally. Plugins terminate the wire
 * to external services (telnet TCP, serial TNC, ARDOP host TCP, …) and
 * expose a byte stream to hybbx_session via the write callback.
 *
 * Optional extensions (NULL = not used):
 *   tick        — called every ~1s from service loop (game clocks, AI, …)
 *   on_command  — intercept "/verb" before core dispatch (entertainment, …)
 */
typedef struct hybbx_transport_plugin {
    const char *name;
    hybbx_transport_kind_t kind;
    unsigned int version;

    /** Called once when the plugin is loaded. */
    hybbx_result_t (*init)(struct hybbx_service *service);

    /** Called once when the plugin is unloaded. */
    void (*shutdown)(void);

    /**
     * Start listening / accepting connections on the given bind address.
     * @p config is a semicolon-separated key=value string built from the
     * transport's INI section (e.g. "bind=0.0.0.0;port=2323").
     */
    hybbx_result_t (*start)(const char *config);

    /** Stop accepting new connections; existing sessions may continue. */
    hybbx_result_t (*stop)(void);

    /**
     * Send raw bytes to the connected client for this session.
     * NULL → core writes to stdout (development fallback).
     */
    hybbx_result_t (*write)(struct hybbx_session *session,
                            const char *data, size_t len);

    /**
     * Periodic tick — called every ~1 second from the service loop.
     * NULL → no periodic work. Used by game clocks, AI timers, etc.
     */
    void (*tick)(struct hybbx_service *service);

    /**
     * Command intercept — called before core command dispatch.
     * Return HYBBX_OK if handled, HYBBX_ERR_NOT_FOUND to fall through.
     * NULL → no command handling.
     */
    hybbx_result_t (*on_command)(struct hybbx_service *service,
                                 struct hybbx_session *session,
                                 const struct hybbx_parsed_command *cmd);

} hybbx_transport_plugin_t;

/**
 * Session callbacks invoked by a transport plugin when a client connects.
 */
typedef struct hybbx_session_ops {
    hybbx_result_t (*on_connect)(struct hybbx_session *session, void *userdata);
    hybbx_result_t (*on_data)(struct hybbx_session *session,
                              const uint8_t *data, size_t len,
                              void *userdata);
    void (*on_disconnect)(struct hybbx_session *session, void *userdata);
} hybbx_session_ops_t;

/** Opaque session handle passed between core and transport plugins. */
typedef struct hybbx_session {
    const hybbx_transport_plugin_t *transport;
    void *transport_data;
    void *core_data;
} hybbx_session_t;

#ifdef __cplusplus
}
#endif

#endif /* HYBBX_PLUGIN_H */
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com