2019-02-27 21:10:52 +02:00
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Protocol Parallel Job
|
|
|
|
***********************************************************************************************************************************/
|
2019-04-26 08:08:23 -04:00
|
|
|
#include "build.auto.h"
|
|
|
|
|
2019-02-27 21:10:52 +02:00
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/log.h"
|
|
|
|
#include "protocol/command.h"
|
|
|
|
#include "protocol/parallelJob.h"
|
|
|
|
|
|
|
|
/***********************************************************************************************************************************
|
|
|
|
Object type
|
|
|
|
***********************************************************************************************************************************/
|
|
|
|
struct ProtocolParallelJob
|
|
|
|
{
|
2021-04-08 16:46:42 -04:00
|
|
|
ProtocolParallelJobPub pub; // Publicly accessible variables
|
2019-02-27 21:10:52 +02:00
|
|
|
};
|
|
|
|
|
2020-04-03 18:01:28 -04:00
|
|
|
/**********************************************************************************************************************************/
|
2019-02-27 21:10:52 +02:00
|
|
|
ProtocolParallelJob *
|
|
|
|
protocolParallelJobNew(const Variant *key, ProtocolCommand *command)
|
|
|
|
{
|
|
|
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
|
|
|
FUNCTION_LOG_PARAM(VARIANT, key);
|
|
|
|
FUNCTION_LOG_PARAM(PROTOCOL_COMMAND, command);
|
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ProtocolParallelJob *this = NULL;
|
|
|
|
|
2022-05-18 10:52:01 -04:00
|
|
|
OBJ_NEW_BEGIN(ProtocolParallelJob, .childQty = MEM_CONTEXT_QTY_MAX)
|
2019-02-27 21:10:52 +02:00
|
|
|
{
|
2021-09-01 11:10:35 -04:00
|
|
|
this = OBJ_NEW_ALLOC();
|
2019-02-27 21:10:52 +02:00
|
|
|
|
2020-01-23 14:15:58 -07:00
|
|
|
*this = (ProtocolParallelJob)
|
|
|
|
{
|
2021-04-08 16:46:42 -04:00
|
|
|
.pub =
|
|
|
|
{
|
|
|
|
.state = protocolParallelJobStatePending,
|
|
|
|
.key = varDup(key),
|
|
|
|
},
|
2020-01-23 14:15:58 -07:00
|
|
|
};
|
2020-01-27 17:50:07 -07:00
|
|
|
|
2021-09-01 11:10:35 -04:00
|
|
|
this->pub.command = protocolCommandMove(command, objMemContext(this));
|
2019-02-27 21:10:52 +02:00
|
|
|
}
|
2021-09-01 11:10:35 -04:00
|
|
|
OBJ_NEW_END();
|
2019-02-27 21:10:52 +02:00
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN(PROTOCOL_PARALLEL_JOB, this);
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:01:28 -04:00
|
|
|
/**********************************************************************************************************************************/
|
2019-02-27 21:10:52 +02:00
|
|
|
void
|
|
|
|
protocolParallelJobErrorSet(ProtocolParallelJob *this, int code, const String *message)
|
|
|
|
{
|
|
|
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
|
|
|
FUNCTION_LOG_PARAM(PROTOCOL_PARALLEL_JOB, this);
|
|
|
|
FUNCTION_LOG_PARAM(INT, code);
|
|
|
|
FUNCTION_LOG_PARAM(STRING, message);
|
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ASSERT(this != NULL);
|
|
|
|
ASSERT(code != 0);
|
|
|
|
ASSERT(message != NULL);
|
|
|
|
|
2022-04-25 09:12:25 -04:00
|
|
|
MEM_CONTEXT_OBJ_BEGIN(this)
|
2019-02-27 21:10:52 +02:00
|
|
|
{
|
2021-04-08 16:46:42 -04:00
|
|
|
this->pub.code = code;
|
|
|
|
this->pub.message = strDup(message);
|
2019-02-27 21:10:52 +02:00
|
|
|
}
|
2022-04-25 09:12:25 -04:00
|
|
|
MEM_CONTEXT_OBJ_END();
|
2019-02-27 21:10:52 +02:00
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:01:28 -04:00
|
|
|
/**********************************************************************************************************************************/
|
2019-04-09 11:01:35 -04:00
|
|
|
void
|
|
|
|
protocolParallelJobProcessIdSet(ProtocolParallelJob *this, unsigned int processId)
|
|
|
|
{
|
|
|
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
|
|
|
FUNCTION_LOG_PARAM(PROTOCOL_PARALLEL_JOB, this);
|
|
|
|
FUNCTION_LOG_PARAM(UINT, processId);
|
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ASSERT(this != NULL);
|
|
|
|
ASSERT(processId > 0);
|
|
|
|
|
2021-04-08 16:46:42 -04:00
|
|
|
this->pub.processId = processId;
|
2019-04-09 11:01:35 -04:00
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:01:28 -04:00
|
|
|
/**********************************************************************************************************************************/
|
2019-02-27 21:10:52 +02:00
|
|
|
void
|
2021-06-24 13:31:16 -04:00
|
|
|
protocolParallelJobResultSet(ProtocolParallelJob *const this, PackRead *const result)
|
2019-02-27 21:10:52 +02:00
|
|
|
{
|
|
|
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
|
|
|
FUNCTION_LOG_PARAM(PROTOCOL_PARALLEL_JOB, this);
|
2021-06-24 13:31:16 -04:00
|
|
|
FUNCTION_LOG_PARAM(PACK_READ, result);
|
2019-02-27 21:10:52 +02:00
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ASSERT(this != NULL);
|
2021-04-08 16:46:42 -04:00
|
|
|
ASSERT(protocolParallelJobErrorCode(this) == 0);
|
2019-02-27 21:10:52 +02:00
|
|
|
|
2021-09-01 11:10:35 -04:00
|
|
|
this->pub.result = pckReadMove(result, objMemContext(this));
|
2019-02-27 21:10:52 +02:00
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
2020-04-03 18:01:28 -04:00
|
|
|
/**********************************************************************************************************************************/
|
2019-02-27 21:10:52 +02:00
|
|
|
void
|
|
|
|
protocolParallelJobStateSet(ProtocolParallelJob *this, ProtocolParallelJobState state)
|
|
|
|
{
|
|
|
|
FUNCTION_LOG_BEGIN(logLevelTrace);
|
|
|
|
FUNCTION_LOG_PARAM(PROTOCOL_PARALLEL_JOB, this);
|
2021-04-28 11:43:08 -04:00
|
|
|
FUNCTION_LOG_PARAM(STRING_ID, state);
|
2019-02-27 21:10:52 +02:00
|
|
|
FUNCTION_LOG_END();
|
|
|
|
|
|
|
|
ASSERT(this != NULL);
|
|
|
|
|
2021-04-08 16:46:42 -04:00
|
|
|
if (this->pub.state == protocolParallelJobStatePending && state == protocolParallelJobStateRunning)
|
|
|
|
this->pub.state = protocolParallelJobStateRunning;
|
|
|
|
else if (this->pub.state == protocolParallelJobStateRunning && state == protocolParallelJobStateDone)
|
|
|
|
this->pub.state = protocolParallelJobStateDone;
|
2019-02-27 21:10:52 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
THROW_FMT(
|
2021-04-28 11:43:08 -04:00
|
|
|
AssertError, "invalid state transition from '%s' to '%s'", strZ(strIdToStr(protocolParallelJobState(this))),
|
|
|
|
strZ(strIdToStr(state)));
|
2019-02-27 21:10:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
FUNCTION_LOG_RETURN_VOID();
|
|
|
|
}
|
|
|
|
|
|
|
|
String *
|
|
|
|
protocolParallelJobToLog(const ProtocolParallelJob *this)
|
|
|
|
{
|
|
|
|
return strNewFmt(
|
2021-04-08 16:46:42 -04:00
|
|
|
"{state: %s, key: %s, command: %s, code: %d, message: %s, result: %s}",
|
2021-04-28 11:43:08 -04:00
|
|
|
strZ(strIdToStr(protocolParallelJobState(this))), strZ(varToLog(protocolParallelJobKey(this))),
|
2021-04-08 16:46:42 -04:00
|
|
|
strZ(protocolCommandToLog(protocolParallelJobCommand(this))), protocolParallelJobErrorCode(this),
|
2021-06-24 13:31:16 -04:00
|
|
|
strZ(strToLog(protocolParallelJobErrorMessage(this))),
|
|
|
|
protocolParallelJobResult(this) == NULL ? NULL_Z : strZ(pckReadToLog(protocolParallelJobResult(this))));
|
2019-02-27 21:10:52 +02:00
|
|
|
}
|