1 /***********************************************************************************************************************************
2 Protocol Parallel Job
3 ***********************************************************************************************************************************/
4 #ifndef PROTOCOL_PARALLEL_JOB_H
5 #define PROTOCOL_PARALLEL_JOB_H
6 
7 #include "common/type/stringId.h"
8 
9 /***********************************************************************************************************************************
10 Object type
11 ***********************************************************************************************************************************/
12 typedef struct ProtocolParallelJob ProtocolParallelJob;
13 
14 /***********************************************************************************************************************************
15 Job state enum
16 ***********************************************************************************************************************************/
17 typedef enum
18 {
19     protocolParallelJobStatePending = STRID5("pending", 0x1dc9238b00),
20     protocolParallelJobStateRunning = STRID5("running", 0x1dc973ab20),
21     protocolParallelJobStateDone = STRID5("done", 0x2b9e40),
22 } ProtocolParallelJobState;
23 
24 #include "common/time.h"
25 #include "common/type/object.h"
26 #include "common/type/pack.h"
27 #include "protocol/client.h"
28 
29 /***********************************************************************************************************************************
30 Constructors
31 ***********************************************************************************************************************************/
32 ProtocolParallelJob *protocolParallelJobNew(const Variant *key, ProtocolCommand *command);
33 
34 /***********************************************************************************************************************************
35 Getters/Setters
36 ***********************************************************************************************************************************/
37 typedef struct ProtocolParallelJobPub
38 {
39     MemContext *memContext;                                         // Mem context
40     const Variant *key;                                             // Unique key used to identify the job
41     ProtocolCommand *command;                                       // Command to be executed
42     unsigned int processId;                                         // Process that executed this job
43     ProtocolParallelJobState state;                                 // Current state of the job
44     int code;                                                       // Non-zero result indicates an error
45     String *message;                                                // Message if there was a error
46     PackRead *result;                                               // Result if job was successful
47 } ProtocolParallelJobPub;
48 
49 // Job command
50 __attribute__((always_inline)) static inline ProtocolCommand *
protocolParallelJobCommand(const ProtocolParallelJob * const this)51 protocolParallelJobCommand(const ProtocolParallelJob *const this)
52 {
53     return THIS_PUB(ProtocolParallelJob)->command;
54 }
55 
56 // Job error
57 __attribute__((always_inline)) static inline int
protocolParallelJobErrorCode(const ProtocolParallelJob * const this)58 protocolParallelJobErrorCode(const ProtocolParallelJob *const this)
59 {
60     return THIS_PUB(ProtocolParallelJob)->code;
61 }
62 
63 __attribute__((always_inline)) static inline const String *
protocolParallelJobErrorMessage(const ProtocolParallelJob * const this)64 protocolParallelJobErrorMessage(const ProtocolParallelJob *const this)
65 {
66     return THIS_PUB(ProtocolParallelJob)->message;
67 }
68 
69 void protocolParallelJobErrorSet(ProtocolParallelJob *this, int code, const String *message);
70 
71 // Job key
72 __attribute__((always_inline)) static inline const Variant *
protocolParallelJobKey(const ProtocolParallelJob * const this)73 protocolParallelJobKey(const ProtocolParallelJob *const this)
74 {
75     return THIS_PUB(ProtocolParallelJob)->key;
76 }
77 
78 // Process Id
79 __attribute__((always_inline)) static inline unsigned int
protocolParallelJobProcessId(const ProtocolParallelJob * const this)80 protocolParallelJobProcessId(const ProtocolParallelJob *const this)
81 {
82     return THIS_PUB(ProtocolParallelJob)->processId;
83 }
84 
85 void protocolParallelJobProcessIdSet(ProtocolParallelJob *this, unsigned int processId);
86 
87 // Job result
88 __attribute__((always_inline)) static inline PackRead *
protocolParallelJobResult(const ProtocolParallelJob * const this)89 protocolParallelJobResult(const ProtocolParallelJob *const this)
90 {
91     return THIS_PUB(ProtocolParallelJob)->result;
92 }
93 
94 void protocolParallelJobResultSet(ProtocolParallelJob *const this, PackRead *const result);
95 
96 // Job state
97 __attribute__((always_inline)) static inline ProtocolParallelJobState
protocolParallelJobState(const ProtocolParallelJob * const this)98 protocolParallelJobState(const ProtocolParallelJob *const this)
99 {
100     return THIS_PUB(ProtocolParallelJob)->state;
101 }
102 
103 void protocolParallelJobStateSet(ProtocolParallelJob *this, ProtocolParallelJobState state);
104 
105 /***********************************************************************************************************************************
106 Functions
107 ***********************************************************************************************************************************/
108 // Move to new parent mem context
109 __attribute__((always_inline)) static inline ProtocolParallelJob *
protocolParallelJobMove(ProtocolParallelJob * const this,MemContext * const parentNew)110 protocolParallelJobMove(ProtocolParallelJob *const this, MemContext *const parentNew)
111 {
112     return objMove(this, parentNew);
113 }
114 
115 /***********************************************************************************************************************************
116 Destructor
117 ***********************************************************************************************************************************/
118 __attribute__((always_inline)) static inline void
protocolParallelJobFree(ProtocolParallelJob * const this)119 protocolParallelJobFree(ProtocolParallelJob *const this)
120 {
121     objFree(this);
122 }
123 
124 /***********************************************************************************************************************************
125 Macros for function logging
126 ***********************************************************************************************************************************/
127 String *protocolParallelJobToLog(const ProtocolParallelJob *this);
128 
129 #define FUNCTION_LOG_PROTOCOL_PARALLEL_JOB_TYPE                                                                                    \
130     ProtocolParallelJob *
131 #define FUNCTION_LOG_PROTOCOL_PARALLEL_JOB_FORMAT(value, buffer, bufferSize)                                                       \
132     FUNCTION_LOG_STRING_OBJECT_FORMAT(value, protocolParallelJobToLog, buffer, bufferSize)
133 
134 #endif
135