- MMS client: add asynchronous function for MMS status request service

pull/93/head
Michael Zillgith 7 years ago
parent aa7e89684e
commit 7600c0f3cf

@ -865,16 +865,23 @@ MmsServerIdentity_destroy(MmsServerIdentity* self);
* This function will return the status of the connected server by invoking the MMS status service. * This function will return the status of the connected server by invoking the MMS status service.
* The services returns the logical and physical states of the server. * The services returns the logical and physical states of the server.
* *
* \param self MmsConnection instance to operate on * \param[in] self MmsConnection instance to operate on
* \param mmsError user provided variable to store error code * \param[out] mmsError user provided variable to store error code
* \param vmdLogicalStatus user provided variable to store the logical state of the VMD * \param[out] vmdLogicalStatus user provided variable to store the logical state of the VMD
* \param vmdPhysicalStatus user provided variable to store the physical state of the VMD * \param[out] vmdPhysicalStatus user provided variable to store the physical state of the VMD
* \param extendedDerivation instructs the server to invoke self-diagnosis routines to determine server status * \param[in] extendedDerivation instructs the server to invoke self-diagnosis routines to determine server status
*/ */
void void
MmsConnection_getServerStatus(MmsConnection self, MmsError* mmsError, int* vmdLogicalStatus, int* vmdPhysicalStatus, MmsConnection_getServerStatus(MmsConnection self, MmsError* mmsError, int* vmdLogicalStatus, int* vmdPhysicalStatus,
bool extendedDerivation); bool extendedDerivation);
typedef void
(*MmsConnection_GetServerStatusHandler) (int invokeId, void* parameter, MmsError mmsError, int vmdLogicalStatus, int vmdPhysicalStatus);
uint32_t
MmsConnection_getServerStatusAsync(MmsConnection self, MmsError* mmsError, bool extendedDerivation,
MmsConnection_GetServerStatusHandler handler, void* parameter);
/******************************************************************************* /*******************************************************************************
* functions for MMS file services * functions for MMS file services
*******************************************************************************/ *******************************************************************************/

@ -70,7 +70,8 @@ typedef enum {
MMS_CALL_TYPE_READ_NVL_DIRECTORY, MMS_CALL_TYPE_READ_NVL_DIRECTORY,
MMS_CALL_TYPE_DEFINE_NVL, MMS_CALL_TYPE_DEFINE_NVL,
MMS_CALL_TYPE_DELETE_NVL, MMS_CALL_TYPE_DELETE_NVL,
MMS_CALL_TYPE_GET_VAR_ACCESS_ATTR MMS_CALL_TYPE_GET_VAR_ACCESS_ATTR,
MMS_CALL_TYPE_GET_SERVER_STATUS
} eMmsOutstandingCallType; } eMmsOutstandingCallType;
struct sMmsOutstandingCall struct sMmsOutstandingCall
@ -283,7 +284,7 @@ void
mmsClient_createStatusRequest(uint32_t invokeId, ByteBuffer* request, bool extendedDerivation); mmsClient_createStatusRequest(uint32_t invokeId, ByteBuffer* request, bool extendedDerivation);
bool bool
mmsClient_parseStatusResponse(MmsConnection self, int* vmdLogicalStatus, int* vmdPhysicalStatus); mmsClient_parseStatusResponse(MmsConnection self, ByteBuffer* response, int bufPos, int* vmdLogicalStatus, int* vmdPhysicalStatus);
void void
mmsClient_createFileOpenRequest(uint32_t invokeId, ByteBuffer* request, const char* fileName, uint32_t initialPosition); mmsClient_createFileOpenRequest(uint32_t invokeId, ByteBuffer* request, const char* fileName, uint32_t initialPosition);

@ -913,7 +913,23 @@ handleAsyncResponse(MmsConnection self, ByteBuffer* response, uint32_t bufPos, M
handler(outstandingCall->invokeId, outstandingCall->userParameter, err, typeSpec); handler(outstandingCall->invokeId, outstandingCall->userParameter, err, typeSpec);
} }
}
else if (outstandingCall->type == MMS_CALL_TYPE_GET_SERVER_STATUS) {
MmsConnection_GetServerStatusHandler handler =
(MmsConnection_GetServerStatusHandler) outstandingCall->userCallback;
if (err != MMS_ERROR_NONE) {
handler(outstandingCall->invokeId, outstandingCall->userParameter, err, 0, 0);
}
else {
int vmdLogicalStatus;
int vmdPhysicalStatus;
if (mmsClient_parseStatusResponse(self, response, bufPos, &vmdLogicalStatus, &vmdPhysicalStatus) == false)
err = MMS_ERROR_PARSING_RESPONSE;
handler(outstandingCall->invokeId, outstandingCall->userParameter, err, vmdLogicalStatus, vmdPhysicalStatus);
}
} }
removeFromOutstandingCalls(self, outstandingCall->invokeId); removeFromOutstandingCalls(self, outstandingCall->invokeId);
@ -2690,26 +2706,91 @@ MmsConnection_identify(MmsConnection self, MmsError* mmsError)
return identity; return identity;
} }
struct getServerStatusParameters
{
Semaphore waitForResponse;
MmsError err;
int vmdLogicalStatus;
int vmdPhysicalStatus;
};
static void
getServerStatusHandler(int invokeId, void* parameter, MmsError mmsError, int vmdLogicalStatus, int vmdPhysicalStatus)
{
struct getServerStatusParameters* parameters = (struct getServerStatusParameters*) parameter;
parameters->err = mmsError;
parameters->vmdLogicalStatus = vmdLogicalStatus;
parameters->vmdPhysicalStatus = vmdPhysicalStatus;
/* unblock user thread */
Semaphore_post(parameters->waitForResponse);
}
void void
MmsConnection_getServerStatus(MmsConnection self, MmsError* mmsError, int* vmdLogicalStatus, int* vmdPhysicalStatus, MmsConnection_getServerStatus(MmsConnection self, MmsError* mmsError, int* vmdLogicalStatus, int* vmdPhysicalStatus,
bool extendedDerivation) bool extendedDerivation)
{
struct getServerStatusParameters parameter;
MmsError err = MMS_ERROR_NONE;
parameter.waitForResponse = Semaphore_create(1);
parameter.err = MMS_ERROR_NONE;
parameter.vmdLogicalStatus = 0;
parameter.vmdPhysicalStatus = 0;
Semaphore_wait(parameter.waitForResponse);
MmsConnection_getServerStatusAsync(self, &err, extendedDerivation, getServerStatusHandler, &parameter);
if (err == MMS_ERROR_NONE) {
Semaphore_wait(parameter.waitForResponse);
err = parameter.err;
if (vmdLogicalStatus)
*vmdLogicalStatus = parameter.vmdLogicalStatus;
if (vmdPhysicalStatus)
*vmdPhysicalStatus = parameter.vmdPhysicalStatus;
}
Semaphore_destroy(parameter.waitForResponse);
if (mmsError)
*mmsError = err;
}
uint32_t
MmsConnection_getServerStatusAsync(MmsConnection self, MmsError* mmsError, bool extendedDerivation,
MmsConnection_GetServerStatusHandler handler, void* parameter)
{ {
uint32_t invokeId = 0;
if (getAssociationState(self) != MMS_STATE_CONNECTED) {
if (mmsError)
*mmsError = MMS_ERROR_CONNECTION_LOST;
goto exit_function;
}
ByteBuffer* payload = IsoClientConnection_allocateTransmitBuffer(self->isoClient); ByteBuffer* payload = IsoClientConnection_allocateTransmitBuffer(self->isoClient);
uint32_t invokeId = getNextInvokeId(self); invokeId = getNextInvokeId(self);
mmsClient_createStatusRequest(invokeId, payload, extendedDerivation); mmsClient_createStatusRequest(invokeId, payload, extendedDerivation);
ByteBuffer* responseMessage = sendRequestAndWaitForResponse(self, invokeId, payload, mmsError); MmsError err = sendAsyncRequest(self, invokeId, payload, MMS_CALL_TYPE_GET_SERVER_STATUS, handler, parameter);
if (responseMessage != NULL) { if (mmsError)
if (mmsClient_parseStatusResponse(self, vmdLogicalStatus, vmdPhysicalStatus) == false) *mmsError = err;
*mmsError = MMS_ERROR_PARSING_RESPONSE;
}
releaseResponse(self); exit_function:
return invokeId;
} }
static LinkedList static LinkedList
readJournal(MmsConnection self, MmsError* mmsError, uint32_t invokeId, ByteBuffer* payload, bool* moreFollows) readJournal(MmsConnection self, MmsError* mmsError, uint32_t invokeId, ByteBuffer* payload, bool* moreFollows)
{ {

@ -50,11 +50,10 @@ mmsClient_createStatusRequest(uint32_t invokeId, ByteBuffer* request, bool exten
} }
bool bool
mmsClient_parseStatusResponse(MmsConnection self, int* vmdLogicalStatus, int* vmdPhysicalStatus) mmsClient_parseStatusResponse(MmsConnection self, ByteBuffer* response, int bufPos, int* vmdLogicalStatus, int* vmdPhysicalStatus)
{ {
uint8_t* buffer = self->lastResponse->buffer; uint8_t* buffer = ByteBuffer_getBuffer(response);
int maxBufPos = self->lastResponse->size; int maxBufPos = ByteBuffer_getSize(response);
int bufPos = self->lastResponseBufPos;
int length; int length;
uint8_t tag = buffer[bufPos++]; uint8_t tag = buffer[bufPos++];

Loading…
Cancel
Save