version 1.2, 2015/04/20 18:10:13
|
version 1.3, 2015/04/20 18:19:55
|
|
|
#include "client.h" | #include "client.h" |
#include <base/packing.h> | #include <base/packing.h> |
#include <protocol/protocol.h> | #include <protocol/protocol.h> |
#include <base/time.h> |
#include <pal/sleep.h> |
#include <base/paths.h> | #include <base/paths.h> |
#include "thread.h" |
#include <pal/thread.h> |
|
#include <base/log.h> |
#define TRACE printf("TRACE: %s(%u)\n", __FILE__, __LINE__) |
|
| |
#if 0 | #if 0 |
# define D(X) X | # define D(X) X |
|
|
# define D(X) /* empty */ | # define D(X) /* empty */ |
#endif | #endif |
| |
|
STRAND_DEBUGNAME(OmiClient); |
|
|
MI_BEGIN_NAMESPACE | MI_BEGIN_NAMESPACE |
| |
//============================================================================== | //============================================================================== |
|
|
// | // |
//============================================================================== | //============================================================================== |
| |
Uint64 _NextMsgID() |
PAL_Uint64 _NextOperationId() |
{ | { |
static Mutex mutex; |
static volatile ptrdiff_t _operationId = 10000; |
mutex.Lock(); |
PAL_Uint64 x = Atomic_Inc(&_operationId); |
static Uint64 _msgID = 10000; |
|
Uint64 x = _msgID++; |
|
mutex.Unlock(); |
|
| |
return x; | return x; |
} | } |
|
|
return r; | return r; |
} | } |
| |
|
static String _StrToString(const char* str) |
|
{ |
|
String r; |
|
|
|
while (str) |
|
{ |
|
MI_Char c = *str++; |
|
r.Append(&c, 1); |
|
} |
|
|
|
return r; |
|
} |
|
|
//============================================================================== | //============================================================================== |
// | // |
// class EnvelopeHandler | // class EnvelopeHandler |
|
|
m_handler->HandleDisconnect(); | m_handler->HandleDisconnect(); |
} | } |
| |
virtual void HandleNoOp(Uint64 msgID) |
virtual void HandleNoOp(Uint64 operationId) |
{ | { |
if (m_handler) | if (m_handler) |
m_handler->HandleNoOp(msgID); |
m_handler->HandleNoOp(operationId); |
} | } |
| |
virtual void HandleInstance(Uint64 msgID, const DInstance& instance) |
virtual void HandleInstance(Uint64 operationId, const DInstance& instance) |
{ | { |
if (m_handler) | if (m_handler) |
m_handler->HandleInstance(msgID, instance); |
m_handler->HandleInstance(operationId, instance); |
} | } |
| |
virtual void HandleResult(Uint64 msgID, MI_Result result) |
virtual void HandleResult(Uint64 operationId, MI_Result result) |
{ | { |
if (m_handler) | if (m_handler) |
m_handler->HandleResult(msgID, result); |
m_handler->HandleResult(operationId, result); |
|
} |
|
virtual void HandleResult(Uint64 operationId, MI_Result result, const MI_Char *error, const DInstance* cimError) |
|
{ |
|
if (m_handler) |
|
m_handler->HandleResult(operationId, result, error, cimError); |
} | } |
| |
private: | private: |
|
|
| |
enum State { START, DONE, FAILED }; | enum State { START, DONE, FAILED }; |
| |
NoOpHandler(Handler* handler, Uint64 msgID) : |
NoOpHandler(Handler* handler, Uint64 operationId) : |
EnvelopeHandler(handler), m_state(START), m_msgID(msgID) |
EnvelopeHandler(handler), m_state(START), m_operationId(operationId) |
{ | { |
} | } |
| |
virtual void HandleNoOp(Uint64 msgID) |
virtual void HandleNoOp(Uint64 operationId) |
{ | { |
if (msgID != m_msgID) |
if (operationId != m_operationId) |
{ | { |
EnvelopeHandler::HandleNoOp(msgID); |
EnvelopeHandler::HandleNoOp(operationId); |
return; | return; |
} | } |
| |
|
|
} | } |
| |
State m_state; | State m_state; |
Uint64 m_msgID; |
Uint64 m_operationId; |
}; | }; |
| |
//============================================================================== | //============================================================================== |
|
|
| |
enum State { START, DONE, FAILED }; | enum State { START, DONE, FAILED }; |
| |
ResultHandler(Handler* handler, Uint64 msgID) : |
ResultHandler(Handler* handler, Uint64 operationId) : |
EnvelopeHandler(handler), | EnvelopeHandler(handler), |
m_state(START), | m_state(START), |
m_msgID(msgID), |
m_operationId(operationId), |
m_result(MI_RESULT_OK) |
m_result(MI_RESULT_OK), |
|
m_cimerror(NULL), |
|
m_errorMessage(NULL) |
{ | { |
} | } |
| |
virtual void HandleResult(Uint64 msgID, Result result) |
virtual void HandleResult(Uint64 operationId, Result result) |
{ | { |
if (msgID != m_msgID) |
if (operationId != m_operationId) |
{ | { |
EnvelopeHandler::HandleResult(msgID, result); |
EnvelopeHandler::HandleResult(operationId, result); |
return; | return; |
} | } |
| |
|
|
m_state = DONE; | m_state = DONE; |
} | } |
| |
|
virtual void HandleResult(Uint64 operationId, MI_Result result, const MI_Char *error, const DInstance* cimError) |
|
{ |
|
if (operationId != m_operationId) |
|
{ |
|
EnvelopeHandler::HandleResult(operationId, result, error, cimError); |
|
return; |
|
} |
|
|
|
if (m_state != START) |
|
{ |
|
m_state = FAILED; |
|
return; |
|
} |
|
|
|
m_result = result; |
|
m_cimerror = cimError; |
|
m_errorMessage = error; |
|
m_state = DONE; |
|
} |
|
|
State m_state; | State m_state; |
Uint64 m_msgID; |
Uint64 m_operationId; |
Result m_result; | Result m_result; |
|
const DInstance* m_cimerror; |
|
const MI_Char *m_errorMessage; |
}; | }; |
| |
//============================================================================== | //============================================================================== |
|
|
| |
InstanceHandler( | InstanceHandler( |
Handler* handler, | Handler* handler, |
Uint64 msgID, |
Uint64 operationId, |
DInstance& instance) | DInstance& instance) |
: | : |
EnvelopeHandler(handler), | EnvelopeHandler(handler), |
m_state(INSTANCE), | m_state(INSTANCE), |
m_msgID(msgID), |
m_operationId(operationId), |
m_instance(instance), | m_instance(instance), |
m_result(MI_RESULT_OK) |
m_result(MI_RESULT_OK), |
|
m_errorMessage(NULL), |
|
m_cimerror(NULL) |
{ | { |
} | } |
| |
virtual void HandleInstance(Uint64 msgID, const DInstance& instance) |
virtual void HandleInstance(Uint64 operationId, const DInstance& instance) |
{ | { |
if (msgID != m_msgID) |
if (operationId != m_operationId) |
{ | { |
EnvelopeHandler::HandleInstance(msgID, instance); |
EnvelopeHandler::HandleInstance(operationId, instance); |
return; | return; |
} | } |
| |
|
|
m_state = RESULT; | m_state = RESULT; |
} | } |
| |
virtual void HandleResult(Uint64 msgID, Result result) |
virtual void HandleResult(Uint64 operationId, Result result) |
{ | { |
if (msgID != m_msgID) |
if (operationId != m_operationId) |
{ | { |
EnvelopeHandler::HandleResult(msgID, result); |
EnvelopeHandler::HandleResult(operationId, result); |
return; | return; |
} | } |
| |
|
|
m_state = DONE; | m_state = DONE; |
} | } |
| |
|
virtual void HandleResult(Uint64 operationId, MI_Result result, const MI_Char *error, const DInstance* cimError) |
|
{ |
|
if (operationId != m_operationId) |
|
{ |
|
EnvelopeHandler::HandleResult(operationId, result, error, cimError); |
|
return; |
|
} |
|
|
|
if (m_state != INSTANCE && m_state != RESULT) |
|
{ |
|
m_state = FAILED; |
|
return; |
|
} |
|
|
|
m_result = result; |
|
m_cimerror = cimError; |
|
m_errorMessage = error; |
|
m_state = DONE; |
|
} |
|
|
State m_state; | State m_state; |
Uint64 m_msgID; |
Uint64 m_operationId; |
DInstance& m_instance; | DInstance& m_instance; |
Result m_result; | Result m_result; |
|
const MI_Char *m_errorMessage; |
|
const DInstance* m_cimerror; |
}; | }; |
| |
//============================================================================== | //============================================================================== |
|
|
| |
InstancesHandler( | InstancesHandler( |
Handler* handler, | Handler* handler, |
Uint64 msgID, |
Uint64 operationId, |
Array<DInstance>& instances) | Array<DInstance>& instances) |
: | : |
EnvelopeHandler(handler), | EnvelopeHandler(handler), |
m_state(INSTANCES), | m_state(INSTANCES), |
m_msgID(msgID), |
m_operationId(operationId), |
m_instances(instances), | m_instances(instances), |
m_result(MI_RESULT_OK) | m_result(MI_RESULT_OK) |
{ | { |
} | } |
| |
virtual void HandleInstance(Uint64 msgID, const DInstance& instance) |
virtual void HandleInstance(Uint64 operationId, const DInstance& instance) |
{ | { |
if (msgID != m_msgID) |
if (operationId != m_operationId) |
{ | { |
EnvelopeHandler::HandleInstance(msgID, instance); |
EnvelopeHandler::HandleInstance(operationId, instance); |
return; | return; |
} | } |
| |
|
|
m_instances.PushBack(instance); | m_instances.PushBack(instance); |
} | } |
| |
virtual void HandleResult(Uint64 msgID, Result result) |
virtual void HandleResult(Uint64 operationId, Result result) |
|
{ |
|
if (operationId != m_operationId) |
|
{ |
|
EnvelopeHandler::HandleResult(operationId, result); |
|
return; |
|
} |
|
|
|
if (m_state != INSTANCES) |
|
{ |
|
m_state = FAILED; |
|
return; |
|
} |
|
|
|
m_result = result; |
|
m_state = DONE; |
|
} |
|
|
|
virtual void HandleResult(Uint64 operationId, Result result, const MI_Char *error, const DInstance* cimError) |
{ | { |
if (msgID != m_msgID) |
if (operationId != m_operationId) |
{ | { |
EnvelopeHandler::HandleResult(msgID, result); |
EnvelopeHandler::HandleResult(operationId, result); |
return; | return; |
} | } |
| |
|
|
} | } |
| |
State m_state; | State m_state; |
Uint64 m_msgID; |
Uint64 m_operationId; |
Array<DInstance>& m_instances; | Array<DInstance>& m_instances; |
Result m_result; | Result m_result; |
}; | }; |
|
|
CONNECTSTATE_DISCONNECTED | CONNECTSTATE_DISCONNECTED |
}; | }; |
| |
Protocol* protocol; |
ProtocolSocketAndBase* protocol; |
|
Strand strand; // To manage interaction with ProtocolSocket |
Handler* handler; | Handler* handler; |
ConnectState connectState; | ConnectState connectState; |
| |
static void EventCallback( |
static void MessageCallback( |
Protocol* protocol, |
ClientRep * rep, |
ProtocolEvent event, |
Message* msg); |
void* data); |
|
|
|
static MI_Boolean MessageCallback( |
|
Protocol* protocol, |
|
Message* msg, |
|
void* data); |
|
| |
bool NoOpAsync( | bool NoOpAsync( |
Uint64 msgID); |
Uint64 operationId); |
| |
bool GetInstanceAsync( | bool GetInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
Uint64 msgID); |
Uint64 operationId); |
| |
bool CreateInstanceAsync( | bool CreateInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instance, | const DInstance& instance, |
Uint64 msgID); |
Uint64 operationId); |
| |
bool ModifyInstanceAsync( | bool ModifyInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instance, | const DInstance& instance, |
Uint64 msgID); |
Uint64 operationId); |
| |
bool DeleteInstanceAsync( | bool DeleteInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
Uint64 msgID); |
Uint64 operationId); |
| |
bool EnumerateInstancesAsync( | bool EnumerateInstancesAsync( |
const String& nameSpace, | const String& nameSpace, |
|
|
bool deepInheritance, | bool deepInheritance, |
const String& queryLanguage, | const String& queryLanguage, |
const String& queryExpression, | const String& queryExpression, |
Uint64 msgID); |
Uint64 operationId); |
| |
bool InvokeAsync( | bool InvokeAsync( |
const String& nameSpace, | const String& nameSpace, |
|
|
const String& methodName, | const String& methodName, |
const DInstance& inParameters, | const DInstance& inParameters, |
DInstance& outParameters, | DInstance& outParameters, |
Uint64 msgID); |
Uint64 operationId); |
| |
bool AssociatorInstancesAsync( | bool AssociatorInstancesAsync( |
const String& nameSpace, | const String& nameSpace, |
|
|
const String& resultClass, | const String& resultClass, |
const String& role, | const String& role, |
const String& resultRole, | const String& resultRole, |
Uint64& msgID); |
Uint64& operationId); |
| |
bool ReferenceInstancesAsync( | bool ReferenceInstancesAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
const String& assocClass, |
const String& resultClass, |
const String& role, | const String& role, |
Uint64& msgID); |
Uint64& operationId); |
}; | }; |
| |
void ClientRep::EventCallback( |
void ClientRep::MessageCallback( |
Protocol* protocol, |
ClientRep * clientRep, |
ProtocolEvent event, |
Message* msg) |
void* data) |
|
{ |
|
ClientRep* clientRep = (ClientRep*)data; |
|
Handler* handler = clientRep->handler; |
|
|
|
D( printf("==== ClientRep::EventCallback()\n"); ) |
|
|
|
|
|
if (event == PROTOCOLEVENT_CONNECT) |
|
{ |
|
D( printf("==== EventCallback() PROTOCOLEVENT_CONNECT\n"); ) |
|
clientRep->connectState = ClientRep::CONNECTSTATE_CONNECTED; |
|
if (handler) |
|
handler->HandleConnect(); |
|
return; |
|
} |
|
|
|
if (event == PROTOCOLEVENT_CONNECT_FAILED) |
|
{ |
|
D( printf("==== EventCallback() PROTOCOLEVENT_CONNECT_FAILED\n"); ) |
|
if (handler) |
|
handler->HandleConnectFailed(); |
|
clientRep->connectState = ClientRep::CONNECTSTATE_FAILED; |
|
return; |
|
} |
|
|
|
if (event == PROTOCOLEVENT_DISCONNECT) |
|
{ |
|
D( printf("==== EventCallback() PROTOCOLEVENT_DISCONNECT\n"); ) |
|
if (handler) |
|
handler->HandleDisconnect(); |
|
clientRep->connectState = ClientRep::CONNECTSTATE_DISCONNECTED; |
|
return; |
|
} |
|
} |
|
|
|
MI_Boolean ClientRep::MessageCallback( |
|
Protocol* protocol, |
|
Message* msg, |
|
void* data) |
|
{ | { |
ClientRep* clientRep = (ClientRep*)data; |
|
Handler* handler = clientRep->handler; | Handler* handler = clientRep->handler; |
| |
DEBUG_ASSERT(msg != 0); | DEBUG_ASSERT(msg != 0); |
|
|
NoOpRsp* rsp = (NoOpRsp*)msg; | NoOpRsp* rsp = (NoOpRsp*)msg; |
MI_UNUSED(rsp); | MI_UNUSED(rsp); |
if (handler) | if (handler) |
handler->HandleNoOp(rsp->base.msgID); |
handler->HandleNoOp(rsp->base.operationId); |
break; | break; |
} | } |
case PostInstanceMsgTag: | case PostInstanceMsgTag: |
|
|
{ | { |
DInstance di(rsp->instance, DInstance::CLONE); | DInstance di(rsp->instance, DInstance::CLONE); |
if (handler) | if (handler) |
handler->HandleInstance(rsp->base.msgID, di); |
handler->HandleInstance(rsp->base.operationId, di); |
} | } |
| |
break; | break; |
} | } |
case SubscribeResTag: |
|
{ |
|
D( printf("ClientRep::MessageCallback(): SubscribeResTag\n"); ) |
|
SubscribeRes* rsp = (SubscribeRes*)msg; |
|
MI_UNUSED(rsp); |
|
break; |
|
} |
|
case PostResultMsgTag: | case PostResultMsgTag: |
{ | { |
D( printf("ClientRep::MessageCallback(): PostResultMsgTag\n"); ) | D( printf("ClientRep::MessageCallback(): PostResultMsgTag\n"); ) |
PostResultMsg* rsp = (PostResultMsg*)msg; | PostResultMsg* rsp = (PostResultMsg*)msg; |
if (handler) | if (handler) |
handler->HandleResult(rsp->base.msgID, rsp->result); |
{ |
|
if (rsp->cimError) |
|
{ |
|
DInstance di((MI_Instance*)(rsp->cimError), DInstance::CLONE); |
|
handler->HandleResult(rsp->base.operationId, rsp->result, rsp->errorMessage, &di); |
|
} |
|
else |
|
{ |
|
handler->HandleResult(rsp->base.operationId, rsp->result, rsp->errorMessage, NULL); |
|
} |
|
} |
break; | break; |
} | } |
default: | default: |
|
|
break; | break; |
} | } |
} | } |
return MI_TRUE; |
|
} | } |
| |
bool ClientRep::NoOpAsync( | bool ClientRep::NoOpAsync( |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
NoOpReq* req = 0; | NoOpReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected: | // Fail if not connected: |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create request message: | // Create request message: |
{ | { |
req = NoOpReq_New(msgID); |
req = NoOpReq_New(operationId); |
| |
if (!req) | if (!req) |
{ | { |
|
|
| |
// Send the message: | // Send the message: |
{ | { |
Result r = Protocol_Send(protocol, &req->base); |
Strand_SchedulePost(&strand,&req->base.base); |
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} | } |
| |
done: | done: |
|
|
bool ClientRep::GetInstanceAsync( | bool ClientRep::GetInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
GetInstanceReq* req = 0; | GetInstanceReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = GetInstanceReq_New(msgID, BinaryProtocolFlag); |
req = GetInstanceReq_New(operationId, BinaryProtocolFlag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Pack the instance name into the message's batch. | // Pack the instance name into the message's batch. |
{ | { |
|
|
instanceName.m_self, | instanceName.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstanceNamePtr, | &req->packedInstanceNamePtr, |
&req->packedInstanceNameSize); | &req->packedInstanceNameSize); |
| |
|
|
| |
// Send the messages: | // Send the messages: |
{ | { |
Result r = Protocol_Send(protocol, &req->base); |
Strand_SchedulePost(&strand,&req->base.base); |
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} | } |
| |
done: | done: |
|
|
bool ClientRep::CreateInstanceAsync( | bool ClientRep::CreateInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instance, | const DInstance& instance, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
CreateInstanceReq* req = 0; | CreateInstanceReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = CreateInstanceReq_New(msgID, BinaryProtocolFlag); |
req = CreateInstanceReq_New(operationId, BinaryProtocolFlag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Pack the instance name into the message's batch. | // Pack the instance name into the message's batch. |
{ | { |
|
|
instance.m_self, | instance.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstancePtr, | &req->packedInstancePtr, |
&req->packedInstanceSize); | &req->packedInstanceSize); |
| |
|
|
| |
// Send the messages: | // Send the messages: |
{ | { |
Result r = Protocol_Send(protocol, &req->base); |
Strand_SchedulePost(&strand,&req->base.base); |
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} | } |
| |
done: | done: |
|
|
bool ClientRep::ModifyInstanceAsync( | bool ClientRep::ModifyInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instance, | const DInstance& instance, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
ModifyInstanceReq* req = 0; | ModifyInstanceReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = ModifyInstanceReq_New(msgID, BinaryProtocolFlag); |
req = ModifyInstanceReq_New(operationId, BinaryProtocolFlag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Pack the instance name into the message's batch. | // Pack the instance name into the message's batch. |
{ | { |
|
|
instance.m_self, | instance.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstancePtr, | &req->packedInstancePtr, |
&req->packedInstanceSize); | &req->packedInstanceSize); |
| |
|
|
} | } |
| |
// Send the messages: | // Send the messages: |
{ |
Strand_SchedulePost(&strand,&req->base.base); |
Result r = Protocol_Send(protocol, &req->base); |
|
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
|
| |
done: | done: |
if (req) | if (req) |
|
|
bool ClientRep::DeleteInstanceAsync( | bool ClientRep::DeleteInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
DeleteInstanceReq* req = 0; | DeleteInstanceReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = DeleteInstanceReq_New(msgID, BinaryProtocolFlag); |
req = DeleteInstanceReq_New(operationId, BinaryProtocolFlag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Pack the instance name into the message's batch. | // Pack the instance name into the message's batch. |
{ | { |
|
|
instanceName.m_self, | instanceName.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstanceNamePtr, | &req->packedInstanceNamePtr, |
&req->packedInstanceNameSize); | &req->packedInstanceNameSize); |
| |
|
|
} | } |
| |
// Send the messages: | // Send the messages: |
{ |
Strand_SchedulePost(&strand,&req->base.base); |
Result r = Protocol_Send(protocol, &req->base); |
|
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
|
| |
done: | done: |
if (req) | if (req) |
|
|
bool deepInheritance, | bool deepInheritance, |
const String& queryLanguage, | const String& queryLanguage, |
const String& queryExpression, | const String& queryExpression, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
EnumerateInstancesReq* req = 0; | EnumerateInstancesReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = EnumerateInstancesReq_New(msgID, BinaryProtocolFlag); |
req = EnumerateInstancesReq_New(operationId, BinaryProtocolFlag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
| |
// Populate the fields of the request message: | // Populate the fields of the request message: |
{ | { |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
req->className = Batch_Zdup(req->base.batch, className.Str()); |
req->className = Batch_Tcsdup(req->base.base.batch, className.Str()); |
|
|
|
if (!req->nameSpace || !req->className) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
if (queryLanguage.GetSize()) | if (queryLanguage.GetSize()) |
{ | { |
req->queryLanguage = | req->queryLanguage = |
Batch_Zdup(req->base.batch, queryLanguage.Str()); |
Batch_Tcsdup(req->base.base.batch, queryLanguage.Str()); |
|
if (!req->queryLanguage) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
} | } |
| |
if (queryExpression.GetSize()) | if (queryExpression.GetSize()) |
{ | { |
req->queryExpression = | req->queryExpression = |
Batch_Zdup(req->base.batch, queryExpression.Str()); |
Batch_Tcsdup(req->base.base.batch, queryExpression.Str()); |
|
if (!req->queryExpression) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
} | } |
| |
req->deepInheritance = deepInheritance; | req->deepInheritance = deepInheritance; |
} | } |
| |
// Send the messages: | // Send the messages: |
{ |
Strand_SchedulePost(&strand,&req->base.base); |
Result r = Protocol_Send(protocol, &req->base); |
|
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
|
| |
done: | done: |
if (req) | if (req) |
|
|
const String& methodName, | const String& methodName, |
const DInstance& inParameters, | const DInstance& inParameters, |
DInstance& outParameters, | DInstance& outParameters, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
InvokeReq* req = 0; | InvokeReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = InvokeReq_New(msgID, BinaryProtocolFlag); |
req = InvokeReq_New(operationId, BinaryProtocolFlag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Set className: | // Set className: |
req->className = Batch_Zdup(req->base.batch, |
req->className = Batch_Tcsdup(req->base.base.batch, |
instanceName.GetClassName().Str()); | instanceName.GetClassName().Str()); |
|
if (!req->className) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Set methodName: | // Set methodName: |
req->function = Batch_Zdup(req->base.batch, methodName.Str()); |
req->function = Batch_Tcsdup(req->base.base.batch, methodName.Str()); |
|
if (!req->function) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Pack instanceName: | // Pack instanceName: |
if (instanceName.Count()) | if (instanceName.Count()) |
|
|
instanceName.m_self, | instanceName.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstancePtr, | &req->packedInstancePtr, |
&req->packedInstanceSize); | &req->packedInstanceSize); |
| |
|
|
inParameters.m_self, | inParameters.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstanceParamsPtr, | &req->packedInstanceParamsPtr, |
&req->packedInstanceParamsSize); | &req->packedInstanceParamsSize); |
| |
|
|
} | } |
| |
// Send the messages: | // Send the messages: |
{ |
Strand_SchedulePost(&strand,&req->base.base); |
Result r = Protocol_Send(protocol, &req->base); |
|
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
|
| |
done: | done: |
if (req) | if (req) |
|
|
const String& resultClass, | const String& resultClass, |
const String& role, | const String& role, |
const String& resultRole, | const String& resultRole, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
AssociatorsOfReq* req = 0; |
AssociationsOfReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = AssociatorsOfReq_New(msgID, BinaryProtocolFlag); |
req = AssociationsOfReq_New(operationId, BinaryProtocolFlag, AssociatorsOfReqTag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Set assocClass: | // Set assocClass: |
if (assocClass.GetSize()) | if (assocClass.GetSize()) |
req->assocClass = Batch_Zdup(req->base.batch, assocClass.Str()); |
{ |
|
req->assocClass = Batch_Tcsdup(req->base.base.batch, assocClass.Str()); |
|
if (!req->assocClass) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
| |
// Set resultClass: | // Set resultClass: |
if (resultClass.GetSize()) | if (resultClass.GetSize()) |
req->resultClass = Batch_Zdup(req->base.batch,resultClass.Str()); |
{ |
|
req->resultClass = Batch_Tcsdup(req->base.base.batch,resultClass.Str()); |
|
if (!req->resultClass) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
| |
// Set role: | // Set role: |
if (role.GetSize()) | if (role.GetSize()) |
req->role = Batch_Zdup(req->base.batch, role.Str()); |
{ |
|
req->role = Batch_Tcsdup(req->base.base.batch, role.Str()); |
|
if (!req->role) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
| |
// Set resultRole: | // Set resultRole: |
if (resultRole.GetSize()) | if (resultRole.GetSize()) |
req->resultRole = Batch_Zdup(req->base.batch, resultRole.Str()); |
{ |
|
req->resultRole = Batch_Tcsdup(req->base.base.batch, resultRole.Str()); |
|
if (!req->resultRole) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
| |
// Pack the instance name into the message's batch. | // Pack the instance name into the message's batch. |
{ | { |
|
|
instanceName.m_self, | instanceName.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstancePtr, | &req->packedInstancePtr, |
&req->packedInstanceSize); | &req->packedInstanceSize); |
| |
|
|
} | } |
| |
// Send the messages: | // Send the messages: |
{ |
Strand_SchedulePost(&strand,&req->base.base); |
Result r = Protocol_Send(protocol, &req->base); |
|
|
|
if (r != MI_RESULT_OK) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
|
| |
done: | done: |
if (req) | if (req) |
{ | { |
AssociatorsOfReq_Release(req); |
AssociationsOfReq_Release(req); |
} | } |
| |
return result; | return result; |
|
|
bool ClientRep::ReferenceInstancesAsync( | bool ClientRep::ReferenceInstancesAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
const String& assocClass, |
const String& resultClass, |
const String& role, | const String& role, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
ReferencesOfReq* req = 0; |
AssociationsOfReq* req = 0; |
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!protocol) |
if( !protocol || !strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Create the request message: | // Create the request message: |
{ | { |
req = ReferencesOfReq_New(msgID, BinaryProtocolFlag); |
req = AssociationsOfReq_New(operationId, BinaryProtocolFlag, ReferencesOfReqTag); |
| |
if (!req) | if (!req) |
{ | { |
|
|
} | } |
| |
// Set nameSpace: | // Set nameSpace: |
req->nameSpace = Batch_Zdup(req->base.batch, nameSpace.Str()); |
req->nameSpace = Batch_Tcsdup(req->base.base.batch, nameSpace.Str()); |
|
if (!req->nameSpace) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
| |
// Set assocClass: | // Set assocClass: |
if (assocClass.GetSize()) |
if (resultClass.GetSize()) |
req->assocClass = Batch_Zdup(req->base.batch, assocClass.Str()); |
{ |
|
req->resultClass = Batch_Tcsdup(req->base.base.batch, resultClass.Str()); |
|
if (!req->resultClass) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
| |
// Set role: | // Set role: |
if (role.GetSize()) | if (role.GetSize()) |
req->role = Batch_Zdup(req->base.batch, role.Str()); |
{ |
|
req->role = Batch_Tcsdup(req->base.base.batch, role.Str()); |
|
if (!req->role) |
|
{ |
|
result = false; |
|
goto done; |
|
} |
|
} |
| |
// Pack the instance name into the message's batch. | // Pack the instance name into the message's batch. |
{ | { |
|
|
instanceName.m_self, | instanceName.m_self, |
NULL, | NULL, |
NULL, | NULL, |
req->base.batch, |
req->base.base.batch, |
&req->packedInstancePtr, | &req->packedInstancePtr, |
&req->packedInstanceSize); | &req->packedInstanceSize); |
| |
|
|
} | } |
| |
// Send the messages: | // Send the messages: |
|
Strand_SchedulePost(&strand,&req->base.base); |
|
|
|
done: |
|
if (req) |
|
AssociationsOfReq_Release(req); |
|
|
|
return result; |
|
} |
|
|
|
//============================================================================== |
|
|
|
MI_EXTERN_C void _Client_Post( _In_ Strand* self_, _In_ Message* msg) |
{ | { |
Result r = Protocol_Send(protocol, &req->base); |
ClientRep* rep = FromOffset(ClientRep,strand,self_); |
| |
if (r != MI_RESULT_OK) |
trace_Client_Post( |
|
msg, |
|
msg->tag, |
|
MessageName(msg->tag), |
|
msg->operationId ); |
|
|
|
ClientRep::MessageCallback( rep, msg ); |
|
|
|
Strand_Ack(self_); // return an Ack to protocol |
|
} |
|
|
|
MI_EXTERN_C void _Client_PostControl( _In_ Strand* self_, _In_ Message* msg) |
{ | { |
result = false; |
ClientRep* rep = FromOffset(ClientRep,strand,self_); |
goto done; |
ProtocolEventConnect* eventMsg = (ProtocolEventConnect*)msg; |
|
Handler* handler = rep->handler; |
|
|
|
DEBUG_ASSERT( ProtocolEventConnectTag == msg->tag ); |
|
|
|
if( eventMsg->success ) |
|
{ |
|
D( printf("==== EventCallback() PROTOCOLEVENT_CONNECT\n"); ) |
|
rep->connectState = ClientRep::CONNECTSTATE_CONNECTED; |
|
if (handler) |
|
handler->HandleConnect(); |
|
} |
|
else |
|
{ |
|
D( printf("==== EventCallback() PROTOCOLEVENT_CONNECT_FAILED\n"); ) |
|
if (handler) |
|
handler->HandleConnectFailed(); |
|
rep->connectState = ClientRep::CONNECTSTATE_FAILED; |
} | } |
} | } |
| |
done: |
MI_EXTERN_C void _Client_Ack( _In_ Strand* self ) |
if (req) |
{ |
ReferencesOfReq_Release(req); |
trace_Client_Ack(); |
|
// We are not streaming any results, so no need to manage flow control on Ack |
|
} |
| |
return result; |
MI_EXTERN_C void _Client_Cancel( _In_ Strand* self ) |
|
{ |
|
DEBUG_ASSERT( MI_FALSE ); // not used yet |
|
} |
|
|
|
MI_EXTERN_C void _Client_Close( _In_ Strand* self_ ) |
|
{ |
|
ClientRep* rep = FromOffset(ClientRep,strand,self_); |
|
Handler* handler = rep->handler; |
|
|
|
trace_Client_Close(); |
|
// most management done by strand implementation |
|
|
|
if (handler) |
|
handler->HandleDisconnect(); |
|
rep->connectState = ClientRep::CONNECTSTATE_DISCONNECTED; |
|
} |
|
|
|
MI_EXTERN_C void _Client_Finish( _In_ Strand* self_ ) |
|
{ |
|
trace_Client_Finish(); |
|
// nothing to do here, (class take care of deleting itself) |
} | } |
| |
|
/* |
|
Object that implements the C++ client endpoint. |
|
It opens an interaction to the binary protocol below |
|
to communicate on a TCP Socket. |
|
|
|
Behavior: |
|
- Post just passed the operation to tries to ClientRep::MessageCallback |
|
if that fails it sends the Ack immediately |
|
- Post control is used to notify connected state (connect succeeded/failed) |
|
- Ack does not do anything at this point (as there are no secondary messages) |
|
- Cancel is not used |
|
- Puts it on disconnected state if not there already |
|
- Shutdown: |
|
The Client objects are shutdown/deleted thru the normal |
|
Strand logic (once the interaction is closed). |
|
*/ |
|
StrandFT _Client_InteractionFT = |
|
{ |
|
_Client_Post, |
|
_Client_PostControl, |
|
_Client_Ack, |
|
_Client_Cancel, |
|
_Client_Close, |
|
_Client_Finish, |
|
NULL, |
|
NULL, |
|
NULL, |
|
NULL, |
|
NULL, |
|
NULL |
|
}; |
|
|
//============================================================================== | //============================================================================== |
// | // |
// class Client | // class Client |
|
|
m_rep->protocol = 0; | m_rep->protocol = 0; |
m_rep->connectState = ClientRep::CONNECTSTATE_DISCONNECTED; | m_rep->connectState = ClientRep::CONNECTSTATE_DISCONNECTED; |
m_rep->handler = handler; | m_rep->handler = handler; |
|
|
|
//Log_OpenStdErr(); |
|
//Log_SetLevel(LOG_DEBUG); |
|
|
|
Strand_Init( STRAND_DEBUG(OmiClient) &m_rep->strand, &_Client_InteractionFT, STRAND_FLAG_ENTERSTRAND, NULL ); // this is the one that Opens the interaction (not the one that receives the open) |
} | } |
| |
Client::~Client() | Client::~Client() |
|
|
if (locator.GetSize() == 0) | if (locator.GetSize() == 0) |
{ | { |
#ifdef CONFIG_POSIX | #ifdef CONFIG_POSIX |
locator = GetPath(ID_SOCKETFILE); |
locator = _StrToString(OMI_GetPath(ID_SOCKETFILE)); |
#else | #else |
locator = MI_T("localhost:7777"); | locator = MI_T("localhost:7777"); |
#endif | #endif |
|
|
| |
// Establish connection with server: | // Establish connection with server: |
{ | { |
Protocol* protocol = NULL; |
InteractionOpenParams params; |
r = Protocol_New_Connector( |
ProtocolSocketAndBase* protocol = NULL; |
|
|
|
Strand_OpenPrepare(&m_rep->strand,¶ms,NULL,NULL,MI_TRUE); |
|
|
|
r = ProtocolSocketAndBase_New_Connector( |
&protocol, | &protocol, |
NULL, | NULL, |
locator_, | locator_, |
(ProtocolCallback)ClientRep::MessageCallback, |
¶ms, |
m_rep, |
|
(ProtocolEventCallback)ClientRep::EventCallback, |
|
m_rep, |
|
user_, | user_, |
password_); | password_); |
| |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
|
|
// Wait for connection establishment or timeout. | // Wait for connection establishment or timeout. |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (m_rep->connectState != ClientRep::CONNECTSTATE_PENDING) | if (m_rep->connectState != ClientRep::CONNECTSTATE_PENDING) |
break; | break; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
bool result = true; | bool result = true; |
| |
// Fail if not connected: | // Fail if not connected: |
if (!m_rep->protocol) |
if( !m_rep->protocol || !m_rep->strand.info.opened ) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
} | } |
| |
// Delete the protocol object. |
if ( m_rep->strand.info.opened ) |
{ | { |
Result r = Protocol_Delete(m_rep->protocol); |
Strand_ScheduleClose( &m_rep->strand ); |
|
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
|
} |
| |
if (r != MI_RESULT_OK) |
// Delete the protocol object. |
{ | { |
result = false; |
ProtocolSocketAndBase_ReadyToFinish(m_rep->protocol); |
goto done; |
|
} |
|
| |
m_rep->protocol = 0; | m_rep->protocol = 0; |
} | } |
|
|
| |
bool Client::Connected() const | bool Client::Connected() const |
{ | { |
return m_rep->protocol ? true : false; |
return m_rep->protocol && m_rep->strand.info.opened ? true : false; |
} | } |
| |
bool Client::Run(Uint64 timeOutUsec) | bool Client::Run(Uint64 timeOutUsec) |
|
|
bool result = true; | bool result = true; |
| |
// Fail if not connected. | // Fail if not connected. |
if (!m_rep->protocol) |
if (!m_rep->protocol || !m_rep->strand.info.opened) |
{ | { |
result = false; | result = false; |
goto done; | goto done; |
|
|
| |
// Process events. | // Process events. |
// ATTN: what can this return? | // ATTN: what can this return? |
Protocol_Run(m_rep->protocol, timeOutUsec); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, timeOutUsec); |
| |
done: | done: |
return result; | return result; |
} | } |
| |
bool Client::NoOpAsync( | bool Client::NoOpAsync( |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->NoOpAsync(msgID); |
return m_rep->NoOpAsync(operationId); |
} | } |
| |
bool Client::GetInstanceAsync( | bool Client::GetInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->GetInstanceAsync(nameSpace, instanceName, msgID); |
return m_rep->GetInstanceAsync(nameSpace, instanceName, operationId); |
} | } |
| |
bool Client::CreateInstanceAsync( | bool Client::CreateInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instance, | const DInstance& instance, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->CreateInstanceAsync(nameSpace, instance, msgID); |
return m_rep->CreateInstanceAsync(nameSpace, instance, operationId); |
} | } |
| |
bool Client::ModifyInstanceAsync( | bool Client::ModifyInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instance, | const DInstance& instance, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->ModifyInstanceAsync(nameSpace, instance, msgID); |
return m_rep->ModifyInstanceAsync(nameSpace, instance, operationId); |
} | } |
| |
bool Client::DeleteInstanceAsync( | bool Client::DeleteInstanceAsync( |
const String& nameSpace, | const String& nameSpace, |
const DInstance& instanceName, | const DInstance& instanceName, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->DeleteInstanceAsync(nameSpace, instanceName, msgID); |
return m_rep->DeleteInstanceAsync(nameSpace, instanceName, operationId); |
} | } |
| |
bool Client::EnumerateInstancesAsync( | bool Client::EnumerateInstancesAsync( |
|
|
bool deepInheritance, | bool deepInheritance, |
const String& queryLanguage, | const String& queryLanguage, |
const String& queryExpression, | const String& queryExpression, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->EnumerateInstancesAsync(nameSpace, className, | return m_rep->EnumerateInstancesAsync(nameSpace, className, |
deepInheritance, queryLanguage, queryExpression, msgID); |
deepInheritance, queryLanguage, queryExpression, operationId); |
} | } |
| |
bool Client::InvokeAsync( | bool Client::InvokeAsync( |
|
|
const String& methodName, | const String& methodName, |
const DInstance& inParameters, | const DInstance& inParameters, |
DInstance& outParameters, | DInstance& outParameters, |
Uint64 msgID) |
Uint64 operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->InvokeAsync(nameSpace, instanceName, methodName, inParameters, | return m_rep->InvokeAsync(nameSpace, instanceName, methodName, inParameters, |
outParameters, msgID); |
outParameters, operationId); |
} | } |
| |
bool Client::AssociatorInstancesAsync( | bool Client::AssociatorInstancesAsync( |
|
|
const String& resultClass, | const String& resultClass, |
const String& role, | const String& role, |
const String& resultRole, | const String& resultRole, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->AssociatorInstancesAsync(nameSpace, instanceName, assocClass, | return m_rep->AssociatorInstancesAsync(nameSpace, instanceName, assocClass, |
resultClass, role, resultRole, msgID); |
resultClass, role, resultRole, operationId); |
} | } |
| |
bool Client::ReferenceInstancesAsync( | bool Client::ReferenceInstancesAsync( |
|
|
const DInstance& instanceName, | const DInstance& instanceName, |
const String& assocClass, | const String& assocClass, |
const String& role, | const String& role, |
Uint64& msgID) |
Uint64& operationId) |
{ | { |
msgID = _NextMsgID(); |
operationId = _NextOperationId(); |
return m_rep->ReferenceInstancesAsync(nameSpace, instanceName, assocClass, | return m_rep->ReferenceInstancesAsync(nameSpace, instanceName, assocClass, |
role, msgID); |
role, operationId); |
} | } |
| |
bool Client::GetInstance( | bool Client::GetInstance( |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
InstanceHandler handler(oldHandler, msgID, instance); |
InstanceHandler handler(oldHandler, operationId, instance); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->GetInstanceAsync(nameSpace, instanceName, msgID)) |
if (!m_rep->GetInstanceAsync(nameSpace, instanceName, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == InstanceHandler::FAILED || | if (handler.m_state == InstanceHandler::FAILED || |
handler.m_state == InstanceHandler::DONE) | handler.m_state == InstanceHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
InstanceHandler handler(oldHandler, msgID, instanceName); |
InstanceHandler handler(oldHandler, operationId, instanceName); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->CreateInstanceAsync(nameSpace, instance, msgID)) |
if (!m_rep->CreateInstanceAsync(nameSpace, instance, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == InstanceHandler::FAILED || | if (handler.m_state == InstanceHandler::FAILED || |
handler.m_state == InstanceHandler::DONE) | handler.m_state == InstanceHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
ResultHandler handler(oldHandler, msgID); |
ResultHandler handler(oldHandler, operationId); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->ModifyInstanceAsync(nameSpace, instance, msgID)) |
if (!m_rep->ModifyInstanceAsync(nameSpace, instance, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == ResultHandler::FAILED || | if (handler.m_state == ResultHandler::FAILED || |
handler.m_state == ResultHandler::DONE) | handler.m_state == ResultHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
ResultHandler handler(oldHandler, msgID); |
ResultHandler handler(oldHandler, operationId); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->DeleteInstanceAsync(nameSpace, instanceName, msgID)) |
if (!m_rep->DeleteInstanceAsync(nameSpace, instanceName, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == ResultHandler::FAILED || | if (handler.m_state == ResultHandler::FAILED || |
handler.m_state == ResultHandler::DONE) | handler.m_state == ResultHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
bool Client::NoOp(Uint64 timeOutUsec) | bool Client::NoOp(Uint64 timeOutUsec) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
NoOpHandler handler(oldHandler, msgID); |
NoOpHandler handler(oldHandler, operationId); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->NoOpAsync(msgID)) |
if (!m_rep->NoOpAsync(operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == NoOpHandler::FAILED || | if (handler.m_state == NoOpHandler::FAILED || |
handler.m_state == NoOpHandler::DONE) | handler.m_state == NoOpHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
InstancesHandler handler(oldHandler, msgID, instances); |
InstancesHandler handler(oldHandler, operationId, instances); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->EnumerateInstancesAsync(nameSpace, className, deepInheritance, | if (!m_rep->EnumerateInstancesAsync(nameSpace, className, deepInheritance, |
queryLanguage, queryExpression, msgID)) |
queryLanguage, queryExpression, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == InstancesHandler::FAILED || | if (handler.m_state == InstancesHandler::FAILED || |
handler.m_state == InstancesHandler::DONE) | handler.m_state == InstancesHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
InstanceHandler handler(oldHandler, msgID, outParameters); |
InstanceHandler handler(oldHandler, operationId, outParameters); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->InvokeAsync(nameSpace, instanceName, methodName, inParameters, | if (!m_rep->InvokeAsync(nameSpace, instanceName, methodName, inParameters, |
outParameters, msgID)) |
outParameters, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == InstanceHandler::FAILED || | if (handler.m_state == InstanceHandler::FAILED || |
handler.m_state == InstanceHandler::DONE) | handler.m_state == InstanceHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
InstancesHandler handler(oldHandler, msgID, instances); |
InstancesHandler handler(oldHandler, operationId, instances); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->AssociatorInstancesAsync(nameSpace, instanceName, assocClass, | if (!m_rep->AssociatorInstancesAsync(nameSpace, instanceName, assocClass, |
resultClass, role, resultRole, msgID)) |
resultClass, role, resultRole, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == InstancesHandler::FAILED || | if (handler.m_state == InstancesHandler::FAILED || |
handler.m_state == InstancesHandler::DONE) | handler.m_state == InstancesHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |
|
|
Result& result) | Result& result) |
{ | { |
Handler* oldHandler = m_rep->handler; | Handler* oldHandler = m_rep->handler; |
Uint64 msgID = _NextMsgID(); |
Uint64 operationId = _NextOperationId(); |
InstancesHandler handler(oldHandler, msgID, instances); |
InstancesHandler handler(oldHandler, operationId, instances); |
m_rep->handler = &handler; | m_rep->handler = &handler; |
bool flag = true; | bool flag = true; |
| |
if (!m_rep->ReferenceInstancesAsync(nameSpace, instanceName, assocClass, | if (!m_rep->ReferenceInstancesAsync(nameSpace, instanceName, assocClass, |
role, msgID)) |
role, operationId)) |
{ | { |
flag = false; | flag = false; |
goto done; | goto done; |
|
|
| |
Uint64 endTime, now; | Uint64 endTime, now; |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
return false; | return false; |
| |
endTime = now + timeOutUsec; | endTime = now + timeOutUsec; |
| |
for (;endTime >= now;) | for (;endTime >= now;) |
{ | { |
Protocol_Run(m_rep->protocol, 1000); |
Protocol_Run(&m_rep->protocol->internalProtocolBase, SELECT_BASE_TIMEOUT_MSEC * 1000); |
| |
if (handler.m_state == InstancesHandler::FAILED || | if (handler.m_state == InstancesHandler::FAILED || |
handler.m_state == InstancesHandler::DONE) | handler.m_state == InstancesHandler::DONE) |
|
|
break; | break; |
} | } |
| |
if (Time_Now(&now) != MI_RESULT_OK) |
if (PAL_Time(&now) != PAL_TRUE) |
break; | break; |
} | } |
| |