1 /***********************************************************************************************************************************
2 Io Client Interface
3 
4 Create sessions for protocol clients. For example, a TLS client can be created with tlsClientNew() and then new TLS sessions can be
5 opened with ioClientOpen().
6 ***********************************************************************************************************************************/
7 #ifndef COMMON_IO_CLIENT_H
8 #define COMMON_IO_CLIENT_H
9 
10 /***********************************************************************************************************************************
11 Object type
12 ***********************************************************************************************************************************/
13 typedef struct IoClient IoClient;
14 
15 #include "common/io/client.intern.h"
16 #include "common/io/session.h"
17 #include "common/type/object.h"
18 
19 /***********************************************************************************************************************************
20 Getters/Setters
21 ***********************************************************************************************************************************/
22 typedef struct IoClientPub
23 {
24     MemContext *memContext;                                         // Mem context
25     void *driver;                                                   // Driver object
26     const IoClientInterface *interface;                             // Driver interface
27 } IoClientPub;
28 
29 // Name that identifies the client
30 __attribute__((always_inline)) static inline const String *
ioClientName(const IoClient * const this)31 ioClientName(const IoClient *const this)
32 {
33     return THIS_PUB(IoClient)->interface->name(THIS_PUB(IoClient)->driver);
34 }
35 
36 /***********************************************************************************************************************************
37 Functions
38 ***********************************************************************************************************************************/
39 // Move to a new parent mem context
40 __attribute__((always_inline)) static inline IoClient *
ioClientMove(IoClient * const this,MemContext * const parentNew)41 ioClientMove(IoClient *const this, MemContext *const parentNew)
42 {
43     return objMove(this, parentNew);
44 }
45 
46 // Open session
47 __attribute__((always_inline)) static inline IoSession *
ioClientOpen(IoClient * const this)48 ioClientOpen(IoClient *const this)
49 {
50     return THIS_PUB(IoClient)->interface->open(THIS_PUB(IoClient)->driver);
51 }
52 
53 /***********************************************************************************************************************************
54 Destructor
55 ***********************************************************************************************************************************/
56 __attribute__((always_inline)) static inline void
ioClientFree(IoClient * const this)57 ioClientFree(IoClient *const this)
58 {
59     objFree(this);
60 }
61 
62 /***********************************************************************************************************************************
63 Macros for function logging
64 ***********************************************************************************************************************************/
65 String *ioClientToLog(const IoClient *this);
66 
67 #define FUNCTION_LOG_IO_CLIENT_TYPE                                                                                                \
68     IoClient *
69 #define FUNCTION_LOG_IO_CLIENT_FORMAT(value, buffer, bufferSize)                                                                   \
70     FUNCTION_LOG_STRING_OBJECT_FORMAT(value, ioClientToLog, buffer, bufferSize)
71 
72 #endif
73