1 /* todo: proper system for posting messages to the toxcore thread, comments, better names (?), proper cleanup of a/v and
2  * a/v thread*/
3 /* -proper unpause/pause file transfers, resuming file transfers + what if new file transfer with same id gets created
4 before the main thread receives the message for the old one?
5 >= GiB file sizes with FILE_*_PROGRESS on 32bit */
6 
7 /* details about messages and their (param1, param2, data) values are in the message handlers in tox.c*/
8 #ifndef UTOX_TOX_H
9 #define UTOX_TOX_H
10 
11 #include <tox/tox.h>
12 
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 typedef uint8_t *UTOX_IMAGE;
18 
19 typedef struct {
20     uint8_t  msg;
21     uint32_t param1, param2;
22     void *   data;
23 } TOX_MSG;
24 
25 typedef enum UTOX_ENC_ERR {
26     UTOX_ENC_ERR_NONE,
27     UTOX_ENC_ERR_LENGTH,
28     UTOX_ENC_ERR_BAD_PASS,
29     UTOX_ENC_ERR_BAD_DATA,
30     UTOX_ENC_ERR_UNKNOWN
31 } UTOX_ENC_ERR;
32 
33 /* toxcore thread messages (sent from the client thread) */
34 enum {
35     /* SHUTDOWNEVERYTHING! */
36     TOX_KILL, // 0
37     TOX_SAVE,
38 
39     /* Change our settings in core */
40     TOX_SELF_SET_NAME,
41     TOX_SELF_SET_STATUS,
42     TOX_SELF_SET_STATE,
43     TOX_SELF_CHANGE_NOSPAM,
44 
45     TOX_SELF_NEW_DEVICE,
46 
47     /* Wooo pixturs */
48     TOX_AVATAR_SET,
49     TOX_AVATAR_UNSET,
50 
51     /* Interact with contacts */
52     TOX_FRIEND_NEW,
53     TOX_FRIEND_NEW_DEVICE,
54     TOX_FRIEND_ACCEPT,
55     TOX_FRIEND_DELETE,
56     TOX_FRIEND_ONLINE,
57     TOX_FRIEND_NEW_NO_REQ,
58 
59     /* Default actions */
60     TOX_SEND_MESSAGE,
61     TOX_SEND_ACTION, /* Should we deprecate this, now that core uses a single function? */
62     TOX_SEND_TYPING,
63 
64     /* File Transfers */
65     TOX_FILE_ACCEPT,
66     TOX_FILE_ACCEPT_AUTO,
67     TOX_FILE_SEND_NEW,
68     TOX_FILE_SEND_NEW_INLINE,
69     TOX_FILE_SEND_NEW_SLASH,
70 
71     TOX_FILE_RESUME,
72     TOX_FILE_PAUSE,
73     TOX_FILE_CANCEL,
74 
75     /* Audio/Video Calls */
76     TOX_CALL_SEND,
77     TOX_CALL_INCOMING,
78     TOX_CALL_ANSWER,
79     TOX_CALL_PAUSE_AUDIO,
80     TOX_CALL_PAUSE_VIDEO,
81     TOX_CALL_RESUME_AUDIO,
82     TOX_CALL_RESUME_VIDEO,
83     TOX_CALL_DISCONNECT,
84 
85     TOX_GROUP_CREATE,
86     TOX_GROUP_JOIN,
87     TOX_GROUP_PART,
88     TOX_GROUP_SEND_INVITE,
89     TOX_GROUP_SET_TOPIC,
90     TOX_GROUP_SEND_MESSAGE,
91     TOX_GROUP_SEND_ACTION,
92     TOX_GROUP_AUDIO_START,
93     TOX_GROUP_AUDIO_END,
94 };
95 
96 struct TOX_SEND_INLINE_MSG {
97     size_t     image_size;
98     UTOX_IMAGE image;
99 };
100 
101 /* AV STATUS LIST */
102 enum {
103     UTOX_AV_NONE,
104     UTOX_AV_INVITE,
105     UTOX_AV_RINGING,
106     UTOX_AV_STARTED,
107 };
108 
109 typedef enum {
110     // tox_thread is not initialized yet
111     UTOX_TOX_THREAD_INIT_NONE = 0,
112     // tox_thread is initialized successfully
113     // this means a tox instance has been created
114     UTOX_TOX_THREAD_INIT_SUCCESS = 1,
115     // tox_thread is initialized but not successfully
116     // this means a tox instance may have not been created
117     UTOX_TOX_THREAD_INIT_ERROR = 2,
118 } UTOX_TOX_THREAD_INIT;
119 
120 extern UTOX_TOX_THREAD_INIT tox_thread_init;
121 
122 /* Inter-thread communication vars. */
123 extern TOX_MSG       tox_msg, audio_msg, toxav_msg;
124 extern volatile bool tox_thread_msg, audio_thread_msg, video_thread_msg;
125 
126 extern bool tox_connected;
127 extern char proxy_address[256]; /* Magic Number inside toxcore */
128 
129 void tox_after_load(Tox *tox);
130 
131 /* toxcore thread
132  */
133 void toxcore_thread(void *args);
134 
135 /* send a message to the toxcore thread
136  */
137 void postmessage_toxcore(uint8_t msg, uint32_t param1, uint32_t param2, void *data);
138 
139 void tox_settingschanged(void);
140 
141 /* convert tox id to string
142  *  notes: dest must be (TOX_FRIEND_ADDRESS_SIZE * 2) bytes large, src must be TOX_FRIEND_ADDRESS_SIZE bytes large
143  */
144 void id_to_string(char *dest, uint8_t *src);
145 
146 #endif
147