-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathchat-internal.c
83 lines (70 loc) · 2.36 KB
/
chat-internal.c
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
#ifndef CHAT_INTERNAL_C
#define CHAT_INTERNAL_C
#include "interface/chat.h"
/**
* @brief Function pointer for feedback
*
* Function pointer for feedback. You can make the chat API feedback
* your code by registering a function using.
*/
typedef int (*input_handler_ptr)(const char *str, void *cc);
/**
* @brief Initialise the struct with hostname and port number.
*
* This function sets up the struct, using hostname and port number.
*
* @param hostname - name of the server to connect to
* @param port - port number of the server to tonnect to
* @return a pointer to the implementing software's own structure
*/
typedef void* (*chat_init_ptr)(const char *str, int port);
/**
* @brief Closes the chat session pointed to by the struct.
*
* This function closes the chat associated with the struct.
*
* @param data a pointer to the implementing software's own structure
* @return void
*/
typedef void (*chat_close_ptr)(void *data);
/**
* @brief Start the chat
*
* This function starts up the chat client. It will listen for input
* from user on stdin and provide feedback to the user via stdout.
*
* @param data a pointer to the implementing software's own structure
* @return an integer idicating success (CHAT_CLIENT_OK e(0)) or error
*/
typedef int (*chat_loop_ptr)(void *data);
/**
* @brief Sets the feedback funtion used to give feedback to the user.
*
* You can change the built in printer (stdout) to any function you want.
*
* @param data a pointer to the implementing software's own structure
* @param fun - a pointer to a function (input_handler - see above)
* @return void
*/
typedef void (*chat_set_feedback_fun_ptr)(void *data, input_handler_ptr fun);
/**
* @brief handle user input
*
* This function either writes a message to the chat server or handles
* internal commands:
* .quit - for leaving the chat session
*
* @param data a pointer to the implementing software's own structure
* @param msg - string to handle
* @return an integer idicating success (CHAT_CLIENT_OK e(0)) or error
*/
typedef int (*chat_handle_input_ptr)(void *data, char *msg);
typedef struct _chat_functions {
input_handler_ptr input_handler;
chat_init_ptr chat_init;
chat_close_ptr chat_close;
chat_handle_input_ptr chat_handle_input;
chat_set_feedback_fun_ptr chat_set_feedback_fun;
chat_loop_ptr chat_loop;
} chat_functions;
#endif /* CHAT_INTERNAL_C */