concept/mproof: Fixed an old minor bug in the concept.
[neuro.git] / include / neuro / nnet / network.h
blobf948a7f535988c15e03541585efb20f9c5c97ac7
1 /* sv_core.h */
3 #ifndef __SVCORE_H
4 #define __SVCORE_H
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
10 #include <neuro/config.h>
11 #include <neuro/NEURO.h>
13 enum CONNECT_TYPE
15 TYPE_SERVER,
16 TYPE_CLIENT
19 enum PROTOCOL_TYPE
21 PROTO_TCP,
22 PROTO_UDP
25 typedef struct Master NNET_MASTER;
27 typedef struct Slave NNET_SLAVE;
29 /* Status types :
30 * NoData - No data is available to read
31 * DataAvail - data is available to read
32 * NewClient - for a server only
33 * ClientDisconnect - for a server only
35 enum
37 State_Start = 0,
39 State_NoData,
40 State_DataAvail,
41 State_Disconnect,
42 State_NewClient,
43 State_ClientDisconnect,
45 State_End
48 typedef struct Status NNET_STATUS;
50 extern void NNet_Destroy(NNET_MASTER *msr);
52 extern NNET_MASTER *NNet_Create(u32 connection_type);
54 /* special feature
56 * this function actually toggles if the connection include a 32 bit
57 * packet header for each of the packets sent containing the
58 * size of the packet for parity check. This can be toggled
59 * on or off and the return value returns 0 or 1 if it's off and on
60 * accordingly.
62 * NOTE - This is only to be used when libneuronet is used
63 * as a client AND server!!
64 * never activate this for when libneuronet is used for other
65 * kind of connections.
67 extern int NNet_SetSendPacketSize(NNET_MASTER *msr);
69 /* see the enum PROTOCOL_TYPE for valid values for Protocol_Type.
70 * This function sets which protocol to create a client or server.
71 * By default, the protocol is TCP.
73 extern void NNet_SetProtocolType(NNET_MASTER *msr, u32 Protocol_Type);
75 extern void NNet_SetQuitFlag(NNET_MASTER *msr);
77 /* Sets a callback which will recieve all Status events;
78 * If set using this function, the callback function will
79 * receive all statuses voiding the NNet_Poll return of
80 * statuses (it is not possible to use both at once. Anyway,
81 * this would break the whole point).
83 * customData is simply a pointer which is sent to the callback.
84 * The end program can use it as their main struct or variable
85 * for keeping a state.
87 extern void NNet_SetResponderCB(NNET_MASTER *msr, void *customData, int (*callback)(void *customData, NNET_STATUS *sta));
89 extern NNET_STATUS *NNet_Poll(NNET_MASTER *msr);
91 /* a client */
92 extern NNET_SLAVE *NNet_Connect(NNET_MASTER *msr, const char *host, int port);
94 /* a server */
95 extern NNET_SLAVE *NNet_Listen(NNET_MASTER *msr, char *listen_ip, int port);
97 extern void NNet_SetTimeOut(NNET_SLAVE *slv, t_tick ts);
99 extern void NNet_DisconnectClient(NNET_SLAVE *client);
101 extern int NNet_Send(NNET_SLAVE *src, const char *message, u32 len);
102 extern char *NNet_GetIP(NNET_SLAVE *slv);
104 extern u32 NNet_GetStatus(const NNET_STATUS *sta);
105 extern char *NNet_GetPacket(const NNET_STATUS *sta);
106 extern int NNet_GetPacketLen(const NNET_STATUS *sta);
107 extern NNET_SLAVE *NNet_GetSlave(const NNET_STATUS *sta);
108 extern NNET_MASTER *NNet_GetMaster(const NNET_STATUS *sta);
110 /* set user defined data set with a NNET_SLAVE element */
111 extern void NNet_SetData(NNET_SLAVE *slv, void *ptr);
112 extern void *NNet_GetData(const NNET_SLAVE *slv);
114 /* to set the debugging filter for this library */
115 extern void NNet_SetDebugFilter(const char *filter);
117 #ifdef __cplusplus
119 #endif
121 #endif /* NOT __SVCORE_H */