diff options
author | iphydf <iphydf@users.noreply.github.com> | 2016-08-30 17:50:59 +0100 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2016-08-30 19:31:40 +0100 |
commit | fa3b51266bdc13a6b5fafdc2518f89b03e5f084f (patch) | |
tree | 582c9e7a2ca197aab4fc90b1ec26821ae1765e30 /toxcore/tox_group.h | |
parent | 4692cea75e82d05c4facf97c8853819281f376cf (diff) |
Add missing #includes to headers and rename tox_old to tox_group.
Also, no longer #include the group code into tox.c. Instead, compile it
separately in tox_group.c. This is a bit less surprising to someone looking
around the code. Having some implementations in a .h file is certainly a bit
surprising to a disciplined C programmer, especially when there is no technical
reason to do it.
Diffstat (limited to 'toxcore/tox_group.h')
-rw-r--r-- | toxcore/tox_group.h | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/toxcore/tox_group.h b/toxcore/tox_group.h new file mode 100644 index 00000000..51beb570 --- /dev/null +++ b/toxcore/tox_group.h | |||
@@ -0,0 +1,179 @@ | |||
1 | #ifndef TOX_GROUP_H | ||
2 | #define TOX_GROUP_H | ||
3 | |||
4 | #include "tox.h" | ||
5 | |||
6 | /**********GROUP CHAT FUNCTIONS ************/ | ||
7 | |||
8 | /* Group chat types for tox_callback_group_invite function. | ||
9 | * | ||
10 | * TOX_GROUPCHAT_TYPE_TEXT groupchats must be accepted with the tox_join_groupchat() function. | ||
11 | * The function to accept TOX_GROUPCHAT_TYPE_AV is in toxav. | ||
12 | */ | ||
13 | enum { | ||
14 | TOX_GROUPCHAT_TYPE_TEXT, | ||
15 | TOX_GROUPCHAT_TYPE_AV | ||
16 | }; | ||
17 | |||
18 | /* Set the callback for group invites. | ||
19 | * | ||
20 | * Function(Tox *tox, int32_t friendnumber, uint8_t type, const uint8_t *data, uint16_t length, void *userdata) | ||
21 | * | ||
22 | * data of length is what needs to be passed to join_groupchat(). | ||
23 | * | ||
24 | * for what type means see the enum right above this comment. | ||
25 | */ | ||
26 | void tox_callback_group_invite(Tox *tox, void (*function)(Tox *tox, int32_t, uint8_t, const uint8_t *, uint16_t, | ||
27 | void *), void *userdata); | ||
28 | |||
29 | /* Set the callback for group messages. | ||
30 | * | ||
31 | * Function(Tox *tox, int groupnumber, int peernumber, const uint8_t * message, uint16_t length, void *userdata) | ||
32 | */ | ||
33 | void tox_callback_group_message(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), | ||
34 | void *userdata); | ||
35 | |||
36 | /* Set the callback for group actions. | ||
37 | * | ||
38 | * Function(Tox *tox, int groupnumber, int peernumber, const uint8_t * action, uint16_t length, void *userdata) | ||
39 | */ | ||
40 | void tox_callback_group_action(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint16_t, void *), | ||
41 | void *userdata); | ||
42 | |||
43 | /* Set callback function for title changes. | ||
44 | * | ||
45 | * Function(Tox *tox, int groupnumber, int peernumber, uint8_t * title, uint8_t length, void *userdata) | ||
46 | * if peernumber == -1, then author is unknown (e.g. initial joining the group) | ||
47 | */ | ||
48 | void tox_callback_group_title(Tox *tox, void (*function)(Tox *tox, int, int, const uint8_t *, uint8_t, | ||
49 | void *), void *userdata); | ||
50 | |||
51 | /* Set callback function for peer name list changes. | ||
52 | * | ||
53 | * It gets called every time the name list changes(new peer/name, deleted peer) | ||
54 | * Function(Tox *tox, int groupnumber, int peernumber, TOX_CHAT_CHANGE change, void *userdata) | ||
55 | */ | ||
56 | typedef enum { | ||
57 | TOX_CHAT_CHANGE_PEER_ADD, | ||
58 | TOX_CHAT_CHANGE_PEER_DEL, | ||
59 | TOX_CHAT_CHANGE_PEER_NAME, | ||
60 | } TOX_CHAT_CHANGE; | ||
61 | |||
62 | void tox_callback_group_namelist_change(Tox *tox, void (*function)(Tox *tox, int, int, uint8_t, void *), | ||
63 | void *userdata); | ||
64 | |||
65 | /* Creates a new groupchat and puts it in the chats array. | ||
66 | * | ||
67 | * return group number on success. | ||
68 | * return -1 on failure. | ||
69 | */ | ||
70 | int tox_add_groupchat(Tox *tox); | ||
71 | |||
72 | /* Delete a groupchat from the chats array. | ||
73 | * | ||
74 | * return 0 on success. | ||
75 | * return -1 if failure. | ||
76 | */ | ||
77 | int tox_del_groupchat(Tox *tox, int groupnumber); | ||
78 | |||
79 | /* Copy the name of peernumber who is in groupnumber to name. | ||
80 | * name must be at least TOX_MAX_NAME_LENGTH long. | ||
81 | * | ||
82 | * return length of name if success | ||
83 | * return -1 if failure | ||
84 | */ | ||
85 | int tox_group_peername(const Tox *tox, int groupnumber, int peernumber, uint8_t *name); | ||
86 | |||
87 | /* Copy the public key of peernumber who is in groupnumber to public_key. | ||
88 | * public_key must be TOX_PUBLIC_KEY_SIZE long. | ||
89 | * | ||
90 | * returns 0 on success | ||
91 | * returns -1 on failure | ||
92 | */ | ||
93 | int tox_group_peer_pubkey(const Tox *tox, int groupnumber, int peernumber, uint8_t *public_key); | ||
94 | |||
95 | /* invite friendnumber to groupnumber | ||
96 | * return 0 on success | ||
97 | * return -1 on failure | ||
98 | */ | ||
99 | int tox_invite_friend(Tox *tox, int32_t friendnumber, int groupnumber); | ||
100 | |||
101 | /* Join a group (you need to have been invited first.) using data of length obtained | ||
102 | * in the group invite callback. | ||
103 | * | ||
104 | * returns group number on success | ||
105 | * returns -1 on failure. | ||
106 | */ | ||
107 | int tox_join_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length); | ||
108 | |||
109 | /* send a group message | ||
110 | * return 0 on success | ||
111 | * return -1 on failure | ||
112 | */ | ||
113 | int tox_group_message_send(Tox *tox, int groupnumber, const uint8_t *message, uint16_t length); | ||
114 | |||
115 | /* send a group action | ||
116 | * return 0 on success | ||
117 | * return -1 on failure | ||
118 | */ | ||
119 | int tox_group_action_send(Tox *tox, int groupnumber, const uint8_t *action, uint16_t length); | ||
120 | |||
121 | /* set the group's title, limited to MAX_NAME_LENGTH | ||
122 | * return 0 on success | ||
123 | * return -1 on failure | ||
124 | */ | ||
125 | int tox_group_set_title(Tox *tox, int groupnumber, const uint8_t *title, uint8_t length); | ||
126 | |||
127 | /* Get group title from groupnumber and put it in title. | ||
128 | * title needs to be a valid memory location with a max_length size of at least MAX_NAME_LENGTH (128) bytes. | ||
129 | * | ||
130 | * return length of copied title if success. | ||
131 | * return -1 if failure. | ||
132 | */ | ||
133 | int tox_group_get_title(Tox *tox, int groupnumber, uint8_t *title, uint32_t max_length); | ||
134 | |||
135 | /* Check if the current peernumber corresponds to ours. | ||
136 | * | ||
137 | * return 1 if the peernumber corresponds to ours. | ||
138 | * return 0 on failure. | ||
139 | */ | ||
140 | unsigned int tox_group_peernumber_is_ours(const Tox *tox, int groupnumber, int peernumber); | ||
141 | |||
142 | /* Return the number of peers in the group chat on success. | ||
143 | * return -1 on failure | ||
144 | */ | ||
145 | int tox_group_number_peers(const Tox *tox, int groupnumber); | ||
146 | |||
147 | /* List all the peers in the group chat. | ||
148 | * | ||
149 | * Copies the names of the peers to the name[length][TOX_MAX_NAME_LENGTH] array. | ||
150 | * | ||
151 | * Copies the lengths of the names to lengths[length] | ||
152 | * | ||
153 | * returns the number of peers on success. | ||
154 | * | ||
155 | * return -1 on failure. | ||
156 | */ | ||
157 | int tox_group_get_names(const Tox *tox, int groupnumber, uint8_t names[][TOX_MAX_NAME_LENGTH], uint16_t lengths[], | ||
158 | uint16_t length); | ||
159 | |||
160 | /* Return the number of chats in the instance m. | ||
161 | * You should use this to determine how much memory to allocate | ||
162 | * for copy_chatlist. */ | ||
163 | uint32_t tox_count_chatlist(const Tox *tox); | ||
164 | |||
165 | /* Copy a list of valid chat IDs into the array out_list. | ||
166 | * If out_list is NULL, returns 0. | ||
167 | * Otherwise, returns the number of elements copied. | ||
168 | * If the array was too small, the contents | ||
169 | * of out_list will be truncated to list_size. */ | ||
170 | uint32_t tox_get_chatlist(const Tox *tox, int32_t *out_list, uint32_t list_size); | ||
171 | |||
172 | /* return the type of groupchat (TOX_GROUPCHAT_TYPE_) that groupnumber is. | ||
173 | * | ||
174 | * return -1 on failure. | ||
175 | * return type on success. | ||
176 | */ | ||
177 | int tox_group_get_type(const Tox *tox, int groupnumber); | ||
178 | |||
179 | #endif /* TOX_GROUP_H */ | ||