Casting
Messages |
 |
Both IsupSMProbe::receive() and IsupSMProbe::receive() return an instance of the base message class, IsupMsg.
To exactly identify which type of message
has been received, you must use the IsupMsg::getMsgType() method.
From the message type indicator returned by IsupMsg::getMsgType(), you must select the appropriate cast method. Each
message class has its own safe casting method, which creates an
instance of the message
class from the contents of the received message.
Unlike the send() methods, you must delete the received message when the receive()call has been successful and you have finished processing its
contents using the accessors.
Table 13-10 Casting Methods
Type | Method | Arguments | Comment |
|---|
static IsupXXX | castMsg | (const IsupMsg* msg) const; | where, IsupXXX denotes a specific message class listed in “Supported Parameters
List”. |
IsupMsg::Type | getMsgType | (); | |
Example 13-5 Receiving
a Message from an IsupSMProbe Object
ISUP::RecvStatus recvStatus;
ISUP::MsgStatus status;
IsupSMProbe * isupSMProbe;
IsupSMProbe::PrimitiveType primitive;
ISUP::Address address;
IsupMsg *isupMsg, *acmMsg;
IsupMsg::Type msgType;
ISUPAdditional:: Info * info;
ISUP::Parmvalue* value;
int nbIndication;
do {
// receive message via isupSMProbe object
recvStatus = isupSMProbe->receive(primitive,address, isupMsg, info, nbIndication);
if (!recvStatus.isOk()){
cout << “receive failed- error=” << recvStatus << “\n” << flush;
// error recovery
}
// check if error message received
if (isupMsg==NULL)
cout <<“Warning: empty message received” << “\n” << flush;
// check message type
msgType= isup->getMsgType();
// process message contents
if (msgType == IsupMsg::ACM){IsupAcm* acmMsg = IsupAcm::castMsg(msgType);
// process contents
// delete contents
}
} while (nbIndication >0);