Merge pull request #11270 from haslinghuis/rename_attr
[betaflight.git] / lib / main / dyad / dyad.h
blob0f29a798d2e0565bf77e9941690bd39eeec043c6
1 /**
2 * Copyright (c) 2016 rxi
4 * This library is free software; you can redistribute it and/or modify it
5 * under the terms of the MIT license. See LICENSE for details.
6 */
8 #ifndef DYAD_H
9 #define DYAD_H
11 #include <stdarg.h>
13 #ifdef _WIN32
14 #include <windows.h> /* For SOCKET */
15 #endif
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
22 #if _WIN32
23 typedef SOCKET dyad_Socket;
24 #else
25 typedef int dyad_Socket;
26 #endif
28 struct dyad_Stream;
29 typedef struct dyad_Stream dyad_Stream;
31 typedef struct {
32 int type;
33 void *udata;
34 dyad_Stream *stream;
35 dyad_Stream *remote;
36 const char *msg;
37 char *data;
38 int size;
39 } dyad_Event;
41 typedef void (*dyad_Callback)(dyad_Event*);
42 typedef void (*dyad_PanicCallback)(const char*);
44 enum {
45 DYAD_EVENT_NULL,
46 DYAD_EVENT_DESTROY,
47 DYAD_EVENT_ACCEPT,
48 DYAD_EVENT_LISTEN,
49 DYAD_EVENT_CONNECT,
50 DYAD_EVENT_CLOSE,
51 DYAD_EVENT_READY,
52 DYAD_EVENT_DATA,
53 DYAD_EVENT_LINE,
54 DYAD_EVENT_ERROR,
55 DYAD_EVENT_TIMEOUT,
56 DYAD_EVENT_TICK
59 enum {
60 DYAD_STATE_CLOSED,
61 DYAD_STATE_CLOSING,
62 DYAD_STATE_CONNECTING,
63 DYAD_STATE_CONNECTED,
64 DYAD_STATE_LISTENING
68 void dyad_init(void);
69 void dyad_update(void);
70 void dyad_shutdown(void);
71 const char *dyad_getVersion(void);
72 double dyad_getTime(void);
73 int dyad_getStreamCount(void);
74 void dyad_setTickInterval(double seconds);
75 void dyad_setUpdateTimeout(double seconds);
76 dyad_PanicCallback dyad_atPanic(dyad_PanicCallback func);
78 dyad_Stream *dyad_newStream(void);
79 int dyad_listen(dyad_Stream *stream, int port);
80 int dyad_listenEx(dyad_Stream *stream, const char *host, int port,
81 int backlog);
82 int dyad_connect(dyad_Stream *stream, const char *host, int port);
83 void dyad_addListener(dyad_Stream *stream, int event,
84 dyad_Callback callback, void *udata);
85 void dyad_removeListener(dyad_Stream *stream, int event,
86 dyad_Callback callback, void *udata);
87 void dyad_removeAllListeners(dyad_Stream *stream, int event);
88 void dyad_end(dyad_Stream *stream);
89 void dyad_close(dyad_Stream *stream);
90 void dyad_write(dyad_Stream *stream, const void *data, int size);
91 void dyad_vwritef(dyad_Stream *stream, const char *fmt, va_list args);
92 void dyad_writef(dyad_Stream *stream, const char *fmt, ...);
93 void dyad_setTimeout(dyad_Stream *stream, double seconds);
94 void dyad_setNoDelay(dyad_Stream *stream, int opt);
95 int dyad_getState(dyad_Stream *stream);
96 const char *dyad_getAddress(dyad_Stream *stream);
97 int dyad_getPort(dyad_Stream *stream);
98 int dyad_getBytesSent(dyad_Stream *stream);
99 int dyad_getBytesReceived(dyad_Stream *stream);
100 dyad_Socket dyad_getSocket(dyad_Stream *stream);
102 #ifdef __cplusplus
103 } // extern "C"
104 #endif
106 #endif