static RsslRet snapshotSessionSendSymbolListRequest(SnapshotSession *pSession)
{
	RsslRet ret;
	RsslError error;
	RsslBuffer* msgBuf = 0;

	/* get a buffer for the item request*/
	msgBuf = rsslGetBuffer(pSession->pRsslChannel, 128, RSSL_FALSE, &error);

	if (msgBuf != NULL)
	{
		/*encode symbol list request*/
		if (encodeSymbolListRequest(pSession, msgBuf, SYMBOL_LIST_STREAM_ID) != RSSL_RET_SUCCESS)
		{
			rsslReleaseBuffer(msgBuf, &error);
			printf("\n<%s> Symbol List encodeSymbolListRequest() failed\n", pSession->name);
			return RSSL_RET_FAILURE;
		}

		if ((ret = snapshotSessionWrite(pSession, msgBuf)) != RSSL_RET_SUCCESS)
			return ret;
	}
	else
	{
		printf("<%s> rsslGetBuffer(): Failed <%s>\n", pSession->name, error.text);
		return RSSL_RET_FAILURE;
	}

	return RSSL_RET_SUCCESS;
}
/*
 * Close an item stream for a specific stream id.
 * chnl - The channel to send an item close to
 * streamId - The stream id of the item close
 */
static RsslRet closeMPItemStream(RsslChannel* chnl, RsslInt32 streamId)
{
	RsslError error;
	RsslBuffer* msgBuf = 0;

	/* get a buffer for the item close */
	msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

	if (msgBuf != NULL)
	{
		/* encode item close */
		if (encodeItemClose(chnl, msgBuf, streamId) != RSSL_RET_SUCCESS)
		{
			rsslReleaseBuffer(msgBuf, &error); 
			printf("\nMarket Price encodeItemClose() failed\n");
			return RSSL_RET_FAILURE;
		}

		/* send close */
		if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
			return RSSL_RET_FAILURE;
	}
	else
	{
		printf("rsslGetBuffer(): Failed <%s>\n", error.text);
		return RSSL_RET_FAILURE;
	}

	return RSSL_RET_SUCCESS;
}
Example #3
0
RsslRet UPAProvider::SendAck(RsslChannel *chnl, RsslPostMsg *postMsg, RsslUInt8 nakCode, char *errText)
{
    RsslBuffer *ackBuf;
    RsslError error;
    RsslRet ret;

    // send an ack if it was requested
    if (postMsg->flags & RSSL_PSMF_ACK)
    {
        if ((ackBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error)) == NULL)
        {
            t42log_error(" UPAProvider::SendAc - rsslGetBuffer() Failed (rsslErrorId = %d)\n", error.rsslErrorId);
            return RSSL_RET_FAILURE;
        }

        if ((ret = EncodeAck(chnl, ackBuf, postMsg, nakCode, errText)) < RSSL_RET_SUCCESS)
        {
            rsslReleaseBuffer(ackBuf, &error); 
            t42log_error(" UPAProvider::SendAck - encodeAck() Failed (ret = %d)\n", ret);
            return RSSL_RET_FAILURE;
        }

        if (SendUPAMessage(chnl, ackBuf) != RSSL_RET_SUCCESS)
            return RSSL_RET_FAILURE;
    }

    return RSSL_RET_SUCCESS;
}
/* Sends a basic Login Request on the given streamID, using the RDM package. */
RsslRet sendLoginRequest(ChannelHandler *pChannelHandler, ChannelInfo *pChannelInfo, RsslInt32 streamId, RsslError *error)
{
	RsslRDMLoginRequest loginRequest;
	RsslRet ret;
	RsslBuffer *msgBuf;
	RsslErrorInfo errorInfo;
	RsslEncodeIterator eIter;
	RsslChannelInfo chanInfo;
	RsslChannel *pChannel = pChannelInfo->pChannel;

	if ((ret = rsslGetChannelInfo(pChannel, &chanInfo, error)) != RSSL_RET_SUCCESS)
	{
		printf("rsslGetChannelInfo() failed: %d(%s)\n", ret, error->text);
		return RSSL_RET_FAILURE;
	}

	/* Send Login Request */
	if ((ret = rsslInitDefaultRDMLoginRequest(&loginRequest, streamId)) != RSSL_RET_SUCCESS)
	{
		printf("rsslInitDefaultRDMLoginRequest() failed: %d\n", ret);
		return RSSL_RET_FAILURE;
	}

	if (strlen(niProvPerfConfig.username))
	{
		loginRequest.userName.data = niProvPerfConfig.username;
		loginRequest.userName.length = (RsslUInt32)strlen(niProvPerfConfig.username);
	}

	loginRequest.flags |= RDM_LG_RQF_HAS_ROLE | RDM_LG_RQF_HAS_APPLICATION_NAME;
	loginRequest.role = RDM_LOGIN_ROLE_PROV;
	loginRequest.applicationName = applicationName;

	if (!(msgBuf = rsslGetBuffer(pChannel, chanInfo.maxFragmentSize, RSSL_FALSE, error)))
	{
		printf("rsslGetBuffer() failed: (%d) %s\n", error->rsslErrorId, error->text);
		 return ret;
	}

	rsslClearEncodeIterator(&eIter);
	rsslSetEncodeIteratorRWFVersion(&eIter, pChannel->majorVersion, pChannel->minorVersion);
	if ( (ret = rsslSetEncodeIteratorBuffer(&eIter, msgBuf)) != RSSL_RET_SUCCESS)
	{
		printf("rsslSetEncodeIteratorBuffer() failed: %d(%s)\n", ret, errorInfo.rsslError.text);
		 return ret;
	}

	if ((ret = rsslEncodeRDMLoginMsg(&eIter, (RsslRDMLoginMsg*)&loginRequest, &msgBuf->length, &errorInfo)) != RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeRDMLoginMsg() failed: %d(%s)\n", ret, errorInfo.rsslError.text);
		 return ret;
	}

	return channelHandlerWriteChannel(pChannelHandler, pChannelInfo, msgBuf, 0);

}
RsslRet snapshotSessionProcessChannelActive(SnapshotSession *pSession)
{
	RsslEncodeIterator encodeIter;
	RsslRDMLoginRequest loginRequest;
	RsslBuffer *pBuffer;
	RsslErrorInfo rsslErrorInfo;
	RsslError rsslError;
	RsslRet ret = RSSL_RET_FAILURE;


	/* Get a buffer from the channel for writing. */
	if (!(pBuffer = rsslGetBuffer(pSession->pRsslChannel, 1024, RSSL_FALSE, &rsslError)))
	{
		printf("<%s> rsslGetBuffer() failed while sending login request: %d (%s -- %s).\n\n",
				pSession->name,
				rsslError.rsslErrorId, rsslRetCodeToString(rsslError.rsslErrorId), rsslError.text);
		return rsslError.rsslErrorId;
	}

	/* Populate the login request with some default information. */
	if ((ret = rsslInitDefaultRDMLoginRequest(&loginRequest, LOGIN_STREAM_ID)) != RSSL_RET_SUCCESS)
	{
		printf("<%s> rsslInitDefaultRDMLoginRequest() failed: %d(%s).\n\n",
				pSession->name, ret, rsslRetCodeToString(ret));
		rsslReleaseBuffer(pBuffer, &rsslError);
		return ret;
	}

	/* Encode the login request using the RDM package encoder utility. This will
	 * translate the login request structure to an encoded message and set the proper length
	 * on the buffer. */
	rsslClearEncodeIterator(&encodeIter);
	rsslSetEncodeIteratorRWFVersion(&encodeIter, pSession->pRsslChannel->majorVersion,
			pSession->pRsslChannel->minorVersion);
	rsslSetEncodeIteratorBuffer(&encodeIter, pBuffer);
	if ((ret = rsslEncodeRDMLoginMsg(&encodeIter, (RsslRDMLoginMsg*)&loginRequest, &pBuffer->length,
					&rsslErrorInfo)) != RSSL_RET_SUCCESS)
	{
		printf("<%s> rsslEncodeRDMLoginMsg() failed: %d (%s -- %s).\n\n",
				pSession->name,
				ret, rsslRetCodeToString(ret), rsslErrorInfo.rsslError.text);
		rsslReleaseBuffer(pBuffer, &rsslError);
		return ret;
	}

	/* Write the message. */
	if ((ret = snapshotSessionWrite(pSession, pBuffer)) != RSSL_RET_SUCCESS)
		return ret;

	pSession->state = SNAPSHOT_STATE_LOGIN_REQUESTED;

	return RSSL_RET_SUCCESS;

}
RsslRet publishDirectoryRefresh(ChannelHandler *pChannelHandler, ChannelInfo *pChannelInfo, RsslInt32 streamId)
{
	RsslError error;
	RsslBuffer* msgBuf = 0;
	RsslRet ret;
	RsslChannel *pChannel = pChannelInfo->pChannel;

	/* get a buffer for the source directory response */
	msgBuf = rsslGetBuffer(pChannel, 512, RSSL_FALSE, &error);

	if (msgBuf != NULL)
	{
		RsslEncodeIterator eIter;
		RsslErrorInfo errorInfo;

		RsslRDMDirectoryRefresh directoryRefresh;


		rsslClearRDMDirectoryRefresh(&directoryRefresh);

		directoryRefresh.flags = RDM_DR_RFF_HAS_SERVICE_ID | RDM_DR_RFF_CLEAR_CACHE;
		directoryRefresh.filter = RDM_DIRECTORY_SERVICE_INFO_FILTER | RDM_DIRECTORY_SERVICE_STATE_FILTER | RDM_DIRECTORY_SERVICE_GROUP_FILTER;

		/* StreamId */
		directoryRefresh.rdmMsgBase.streamId = streamId;

		directoryRefresh.serviceList = &service;
		directoryRefresh.serviceCount = 1;

		rsslClearEncodeIterator(&eIter);
		rsslSetEncodeIteratorRWFVersion(&eIter, pChannel->majorVersion, pChannel->minorVersion);
		rsslSetEncodeIteratorBuffer(&eIter, msgBuf);

		if ((ret = rsslEncodeRDMDirectoryMsg(&eIter, (RsslRDMDirectoryMsg*)&directoryRefresh, &msgBuf->length, &errorInfo)) != RSSL_RET_SUCCESS)
		{
			printf("rsslEncodeRDMDirectoryMsg() failed: %d(%s)", ret, errorInfo.rsslError.text);
			return ret;
		}

		return channelHandlerWriteChannel(pChannelHandler, pChannelInfo, msgBuf, 0);
	}
	else
	{
		printf("rsslGetBuffer(): Failed <%s>\n", error.text);
		return error.rsslErrorId;
	}
}
/*
 * Redirect a request to a private stream.
 * streamId - The stream id to be redirected to private stream
 */
RsslRet redirectToMarketPricePrivateStream(RsslChannel *chnl, RsslInt32 streamId)
{
	RsslError error;
	RsslBuffer* msgBuf = 0;

	/* add item name to private stream list */
	addMarketPriceItemName(marketPriceItemInfoList[streamId - MARKETPRICE_STREAM_ID_START].itemname, RSSL_TRUE);

	/* remove non-private stream entry from list */
	removeMarketPriceItemEntry(chnl, streamId, RSSL_FALSE);

	/* get a buffer for the item request */
	msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

	if (msgBuf != NULL)
	{
		/* encode item request */
		if (encodeItemRequest(chnl, msgBuf, nextPrivateStreamId - 1, RSSL_TRUE) != RSSL_RET_SUCCESS)
		{
			rsslReleaseBuffer(msgBuf, &error); 
			printf("\nMarket Price encodeItemRequest() failed\n");
			return RSSL_RET_FAILURE;
		}

		/* send item request */
		if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
			return RSSL_RET_FAILURE;
	}
	else
	{
		printf("rsslGetBuffer(): Failed <%s>\n", error.text);
		return RSSL_RET_FAILURE;
	}

	return RSSL_RET_SUCCESS;
}
RsslRet processDirectoryRequest(ChannelHandler *pChannelHandler, ChannelInfo *pChannelInfo, RsslMsg* msg, RsslDecodeIterator* dIter)
{
	RsslRet ret;
	RsslState *pState = 0;
	RsslRDMDirectoryMsg directoryMsg;
	char directoryMsgChar[4000];
	RsslBuffer memoryBuffer = { 4000, directoryMsgChar };
	RsslErrorInfo errorInfo;
	RsslChannel *pChannel = pChannelInfo->pChannel;

	if ((ret = rsslDecodeRDMDirectoryMsg(dIter, msg, &directoryMsg, &memoryBuffer, &errorInfo)) != RSSL_RET_SUCCESS)
	{
		printf("rsslDecodeRDMDirectoryMsg() failed: %d(%s)\n", ret, errorInfo.rsslError.text);
		return ret;
	}

	switch(directoryMsg.rdmMsgBase.rdmMsgType)
	{
	case RDM_DR_MT_REQUEST:
	{
		RsslError error;
		RsslBuffer* msgBuf = 0;
		RsslChannel *pChannel = pChannelInfo->pChannel;
		RsslEncodeIterator eIter;
		RsslRDMDirectoryRefresh directoryRefresh;

		printf("Received Directory Request.\n\n");

		if ((msgBuf = rsslGetBuffer(pChannel, 512, RSSL_FALSE, &error)) == NULL)
		{
			printf("processDirectoryRequest(): rsslGetBuffer() failed: %d(%s)\n",
					error.rsslErrorId, error.text);
			return error.rsslErrorId;
		}

		rsslClearRDMDirectoryRefresh(&directoryRefresh);

		directoryRefresh.flags = RDM_DR_RFF_SOLICITED | RDM_DR_RFF_CLEAR_CACHE;
		directoryRefresh.filter = directoryMsg.request.filter;


		/* StreamId */
		directoryRefresh.rdmMsgBase.streamId = directoryMsg.request.rdmMsgBase.streamId;

		/* ServiceId */
		if (directoryMsg.request.flags & RDM_DR_RQF_HAS_SERVICE_ID)
		{
			/* Match the ServiceID if requested */
			directoryRefresh.flags |= RDM_DR_RFF_HAS_SERVICE_ID;
			directoryRefresh.serviceId = directoryMsg.request.serviceId;

			if (directoryMsg.request.serviceId == service.serviceId)
			{
				directoryRefresh.serviceList = &service;
				directoryRefresh.serviceCount = 1;
			}
		}
		else
		{
			directoryRefresh.serviceList = &service;
			directoryRefresh.serviceCount = 1;
		}

		rsslClearEncodeIterator(&eIter);
		rsslSetEncodeIteratorRWFVersion(&eIter, pChannel->majorVersion, pChannel->minorVersion);
		rsslSetEncodeIteratorBuffer(&eIter, msgBuf);

		if ((ret = rsslEncodeRDMDirectoryMsg(&eIter, (RsslRDMDirectoryMsg*)&directoryRefresh, &msgBuf->length, &errorInfo)) != RSSL_RET_SUCCESS)
		{
			printf("rsslEncodeRDMDirectoryMsg() failed: %d(%s)", ret, errorInfo.rsslError.text);
			return ret;
		}

		return channelHandlerWriteChannel(pChannelHandler, pChannelInfo, msgBuf, 0);
	}

	case RDM_DR_MT_CLOSE:
		printf("\nReceived Source Directory Close for StreamId %d\n", directoryMsg.rdmMsgBase.streamId);
		return RSSL_RET_SUCCESS;

	default:
		printf("\nReceived Unhandled Source Directory Msg Class: %d\n", msg->msgBase.msgClass);
		return RSSL_RET_FAILURE;
	}
}
//APIQA
RsslRet sendGenericMsgOnLogin(RsslChannel* chnl)
{
	RsslRet ret = 0;
	RsslGenericMsg msg = RSSL_INIT_GENERIC_MSG;
	RsslMap map = RSSL_INIT_MAP;
	RsslMapEntry mEntry = RSSL_INIT_MAP_ENTRY;
	RsslElementList rsslElementList = RSSL_INIT_ELEMENT_LIST;
	RsslBuffer serviceNameBuffer;
	RsslEncodeIterator encodeIter;
	RsslElementEntry element = RSSL_INIT_ELEMENT_ENTRY;
	RsslBuffer* msgBuf;
	RsslError error;
	RsslUInt warmStandByMode = 1;

	serviceNameBuffer.length = 11;
	serviceNameBuffer.data = "DIRECT_FEED";

	/* clear encode iterator */
	rsslClearEncodeIterator(&encodeIter);

	/* set-up message */
	msg.msgBase.msgClass = RSSL_MC_GENERIC;
	msg.msgBase.domainType = RSSL_DMT_LOGIN;
	msg.msgBase.containerType = RSSL_DT_MAP;
	msg.msgBase.msgKey.name.length = 24;
	msg.msgBase.msgKey.name.data = "ConsumerConnectionStatus";
	msg.msgBase.msgKey.flags = RSSL_MKF_HAS_NAME;
	msg.flags = RSSL_GNMF_HAS_MSG_KEY | RSSL_GNMF_MESSAGE_COMPLETE;

	/* get a buffer for the login request */
	msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

	/* StreamId */
	msg.msgBase.streamId = LOGIN_STREAM_ID;

	/* encode message */
	if ((ret = rsslSetEncodeIteratorBuffer(&encodeIter, msgBuf)) < RSSL_RET_SUCCESS)
	{
		printf("rsslSetEncodeIteratorBuffer() failed with return code: %d\n", ret);
		return ret;
	}
	rsslSetEncodeIteratorRWFVersion(&encodeIter, chnl->majorVersion, chnl->minorVersion);
	if ((ret = rsslEncodeMsgInit(&encodeIter, (RsslMsg*)&msg, 0)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeMsgInit() failed with return code: %d\n", ret);
		return ret;
	}

	/* encode map */
	map.keyPrimitiveType = RSSL_DT_ASCII_STRING;
	map.containerType = RSSL_DT_ELEMENT_LIST;
	if ((ret = rsslEncodeMapInit(&encodeIter, &map, 0, 0)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeMapInit() failed with return code: %d\n", ret);
		return ret;
	}

	/* encode map entry */
	mEntry.action = RSSL_MPEA_ADD_ENTRY;
	if ((ret = rsslEncodeMapEntryInit(&encodeIter, &mEntry, &serviceNameBuffer, 0)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeMapEntry() failed with return code: %d\n", ret);
		return ret;
	}

	/* encode the element list */
	rsslElementList.flags = RSSL_ELF_HAS_STANDARD_DATA;
	if ((ret = rsslEncodeElementListInit(&encodeIter, &rsslElementList, 0, 0)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeElementListInit() failed with return code: %d\n", ret);
		return ret;
	}

	/* WarmStandbyMode */
	element.dataType = RSSL_DT_UINT;
	element.name = RSSL_ENAME_WARMSTANDBY_MODE;
	if ((ret = rsslEncodeElementEntry(&encodeIter, &element, &warmStandByMode)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeElementEntry() failed with return code: %d\n", ret);
		return ret;
	}

	/* complete encode element list */
	if ((ret = rsslEncodeElementListComplete(&encodeIter, RSSL_TRUE)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeElementListComplete() failed with return code: %d\n", ret);
		return ret;
	}

	/* complete encode map entry */
	if ((ret = rsslEncodeMapEntryComplete(&encodeIter, RSSL_TRUE)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeMapEntryComplete() failed with return code: %d\n", ret);
		return ret;
	}

	/* complete encode map */
	if ((ret = rsslEncodeMapComplete(&encodeIter, RSSL_TRUE)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeMapComplete() failed with return code: %d\n", ret);
		return ret;
	}

	/* complete encode message */
	if ((ret = rsslEncodeMsgComplete(&encodeIter, RSSL_TRUE)) < RSSL_RET_SUCCESS)
	{
		printf("rsslEncodeMsgComplete() failed with return code: %d\n", ret);
		return ret;
	}
	msgBuf->length = rsslGetEncodedBufferLength(&encodeIter);

	if (ret != RSSL_RET_SUCCESS)
	{
		rsslReleaseBuffer(msgBuf, &error);
		printf("\nsendGenericMsgOnLogin() failed with return code: %d\n", ret);
		return ret;
	}

	/* send login request */
	if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
		return RSSL_RET_FAILURE;

	return RSSL_RET_SUCCESS;
}
RsslRet snapshotSessionRequestItems(SnapshotSession *pSession)
{
	RsslUInt32 i;
	RsslEncodeIterator encodeIter;
	RsslRequestMsg requestMsg;
	RsslBuffer *pBuffer;
	RsslError rsslError;
	RsslRet ret;

	for (i = 0; i < itemList.itemCount; ++i)
	{
		Item *pItem = &itemList.items[i];

		if (!(pBuffer = rsslGetBuffer(pSession->pRsslChannel, 128, RSSL_FALSE, &rsslError)))
		{
			printf("<%s> rsslGetBuffer() failed while sending item request: %d (%s -- %s).\n\n",
					pSession->name,
					rsslError.rsslErrorId, rsslRetCodeToString(rsslError.rsslErrorId), rsslError.text);
			return ret;
		}

		rsslClearRequestMsg(&requestMsg);
		requestMsg.flags = RSSL_RQMF_HAS_QOS;
		requestMsg.msgBase.streamId = pItem->snapshotServerStreamId;
		requestMsg.msgBase.domainType = pItem->domainType;
		requestMsg.msgBase.containerType = RSSL_DT_NO_DATA;
		requestMsg.qos.rate = RSSL_QOS_RATE_TICK_BY_TICK;
		requestMsg.qos.timeliness = RSSL_QOS_TIME_REALTIME;

		/* This system uses the real-time feed's stream ID as the name. */
		requestMsg.msgBase.msgKey.flags = RSSL_MKF_HAS_SERVICE_ID | RSSL_MKF_HAS_IDENTIFIER;
		requestMsg.msgBase.msgKey.identifier = pItem->feedStreamId;
		requestMsg.msgBase.msgKey.serviceId = exampleConfig.serviceId;

		rsslClearEncodeIterator(&encodeIter);
		rsslSetEncodeIteratorRWFVersion(&encodeIter, pSession->pRsslChannel->majorVersion,
				pSession->pRsslChannel->minorVersion);
		rsslSetEncodeIteratorBuffer(&encodeIter, pBuffer);
		if ((ret = rsslEncodeMsg(&encodeIter, (RsslMsg*)&requestMsg)) != RSSL_RET_SUCCESS)
		{
			printf("<%s> rsslEncodeMsg() failed while sending item request: %d (%s).\n\n",
					pSession->name,
					ret, rsslRetCodeToString(ret));
			rsslReleaseBuffer(pBuffer, &rsslError);
			return ret;
		}

		pBuffer->length = rsslGetEncodedBufferLength(&encodeIter);

		/* Write the message. */
		if ((ret = snapshotSessionWrite(pSession, pBuffer)) != RSSL_RET_SUCCESS)
			return ret;

		printf("<%s> Sent request for item %s, %s on stream %d.\n\n",
				pSession->name, pItem->symbolName,
				rsslDomainTypeToString(pItem->domainType), pItem->snapshotServerStreamId);

	}

	return RSSL_RET_SUCCESS;
}
/*
 * Publically visable market price request function 
 *
 * Sends item requests to a channel.  For each item, this
 * consists of getting a message buffer, encoding the item
 * request, and sending the item request to the server.
 * chnl - The channel to send an item request to
 */
RsslRet sendMarketPriceItemRequests(RsslChannel* chnl)
{
	RsslError error;
	RsslBuffer* msgBuf = 0;
	RsslLoginResponseInfo* loginInfo = getLoginResponseInfo();
	int i;

	/* Do not send a request if there are no items in the item list. */
	if(itemCount == 0 && privateStreamItemCount == 0)
		return RSSL_RET_SUCCESS;

	/* check to see if the provider supports the market price domain */
	if(getSourceDirectoryCapabilities(RSSL_DMT_MARKET_PRICE) == RSSL_FALSE)
	{
		printf("RSSL_DMT_MARKET_PRICE is not supported by the indicated provider\n");
		return RSSL_RET_SUCCESS;
	}

	for (i = 0; i < (MAX_STREAM_ID_RANGE_PER_DOMAIN/2) ; i++)
	{
		/* initialize state management array */
		/* these will be updated as refresh and status messages are received */
		marketPriceItemInfoList[i].itemState.dataState = RSSL_DATA_NO_CHANGE;
		marketPriceItemInfoList[i].itemState.streamState = RSSL_STREAM_UNSPECIFIED;
	}

	for (i = 0; i < (MAX_STREAM_ID_RANGE_PER_DOMAIN/2) ; i++)
	{
		/* initialize state management array */
		/* these will be updated as refresh and status messages are received */
		marketPricePSItemInfoList[i].itemState.dataState = RSSL_DATA_NO_CHANGE;
		marketPricePSItemInfoList[i].itemState.streamState = RSSL_STREAM_UNSPECIFIED;
	}

	/* send out two sets of requests - one for private stream and one for non-private stream */

	/* non-private stream request(s) */
	if (itemCount > 0)
	{
		/* If there is only one item in the itemList, it is a waste of bandwidth to send a batch request */
		if((loginInfo->SupportBatchRequests & RDM_LOGIN_BATCH_SUPPORT_REQUESTS) && (itemCount > 1))
		{
			msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);
		
			if (msgBuf != NULL)
			{
				if(encodeBatchItemRequest(chnl, msgBuf, MARKETPRICE_BATCH_STREAM_ID_START, RSSL_FALSE) != RSSL_RET_SUCCESS)
				{
					rsslReleaseBuffer(msgBuf, &error); 
					printf("\nMarket Price encodeBatchItemRequest() failed\n");
					return RSSL_RET_FAILURE;
				}
				
				if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			else
			{
				printf("rsslGetBuffer(): Failed <%s>\n", error.text);
				return RSSL_RET_FAILURE;
			}
		} 
		else 
		{
			if (itemCount > 1)
				printf("\nConnected Provider does not support Batch Requests. Sending Market Price requests as individual request messages.\n");

			for (i = 0; i < itemCount; i++)
			{
				/* get a buffer for the item request */
				msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

				if (msgBuf != NULL)
				{
					/* encode item request */
					if (encodeItemRequest(chnl, msgBuf, (i + MARKETPRICE_STREAM_ID_START), RSSL_FALSE) != RSSL_RET_SUCCESS)
					{
						rsslReleaseBuffer(msgBuf, &error); 
						printf("\nMarket Price encodeItemRequest() failed\n");
						return RSSL_RET_FAILURE;
					}

					/* send item request */
					if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
						return RSSL_RET_FAILURE;
				}
				else
				{
					printf("rsslGetBuffer(): Failed <%s>\n", error.text);
					return RSSL_RET_FAILURE;
				}
			}
		}
	}

	/* private stream request(s) */
	if (privateStreamItemCount > 0)
	{
		/* If there is only one item in the itemList, it is a waste of bandwidth to send a batch request */
		if((loginInfo->SupportBatchRequests & RDM_LOGIN_BATCH_SUPPORT_REQUESTS) && (privateStreamItemCount > 1))
		{
			msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);
		
			if (msgBuf != NULL)
			{
				if(encodeBatchItemRequest(chnl, msgBuf, MARKETPRICE_BATCH_PRIVATE_STREAM_ID_START, RSSL_TRUE) != RSSL_RET_SUCCESS)
				{
					rsslReleaseBuffer(msgBuf, &error); 
					printf("\nMarket Price encodeBatchItemRequest() failed\n");
					return RSSL_RET_FAILURE;
				}
				
				if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
			else
			{
				printf("rsslGetBuffer(): Failed <%s>\n", error.text);
				return RSSL_RET_FAILURE;
			}
		} 
		else 
		{
			if (privateStreamItemCount > 1)
				printf("\nConnected Provider does not support Batch Requests. Sending Private Stream Market Price requests as individual request messages.\n");

			for (i = 0; i < privateStreamItemCount; i++)
			{
				/* get a buffer for the item request */
				msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

				if (msgBuf != NULL)
				{
					/* encode item request */
					if (encodeItemRequest(chnl, msgBuf, (i + MARKETPRICE_PRIVATE_STREAM_ID_START), RSSL_TRUE) != RSSL_RET_SUCCESS)
					{
						rsslReleaseBuffer(msgBuf, &error); 
						printf("\nMarket Price encodeItemRequest() failed\n");
						return RSSL_RET_FAILURE;
					}

					/* send item request */
					if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
						return RSSL_RET_FAILURE;
				}
				else
				{
					printf("rsslGetBuffer(): Failed <%s>\n", error.text);
					return RSSL_RET_FAILURE;
				}
			}
		}
	}

	return RSSL_RET_SUCCESS;
}
/*
 * Publically visable - used to close all market price streams
 *
 * Close all item streams.
 * chnl - The channel to send an item close to
 */
RsslRet closeMarketPriceItemStreams(RsslChannel* chnl)
{
	RsslBuffer* msgBuf = 0;
	RsslError error;
	int i;
	RsslInt32 batchCloseStreamId;

	RsslLoginResponseInfo* loginInfo = getLoginResponseInfo();

	/* If provider supports batch close, will use batch close */
	if((loginInfo->SupportBatchRequests & RDM_LOGIN_BATCH_SUPPORT_CLOSES) && (itemCount + privateStreamItemCount) > 1)
	{
		/* get a buffer for the item request */
		msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

		if (msgBuf != NULL)
		{
			batchCloseStreamId = nextStreamId++;

			/* encode batch close */
			if (encodeBatchItemClose(chnl, msgBuf, batchCloseStreamId) != RSSL_RET_SUCCESS)
			{
				rsslReleaseBuffer(msgBuf, &error); 
				printf("\nMarket Price encodeBatchItemClose() failed\n");
				return RSSL_RET_FAILURE;
			}

			/* send batch close */
			if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
				return RSSL_RET_FAILURE;
		}
		else
		{
			printf("rsslGetBuffer(): Failed <%s>\n", error.text);
			return RSSL_RET_FAILURE;
		}
	}
	else
	{
		if ((itemCount + privateStreamItemCount) > 1)
			printf("\nConnected Provider does not support Batch Closes. Sending Market Price closes as individual close messages.\n");

		/* non-private streams */
		for (i = 0; i < itemCount; i++)
		{
			/* we only want to close a stream if it was not already closed (e.g. rejected by provider, closed via refresh or status, or redirected) */
			if (!rsslIsFinalState(&marketPriceItemInfoList[i].itemState))
			{
				if (closeMPItemStream(chnl, i + MARKETPRICE_STREAM_ID_START) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
		}

		/* private streams */
		for (i = 0; i < privateStreamItemCount; i++)
		{
			/* we only want to close a stream if it was not already closed (e.g. rejected by provider, closed via refresh or status, or redirected) */
			if (!rsslIsFinalState(&marketPricePSItemInfoList[i].itemState))
			{
				if (closeMPItemStream(chnl, i + MARKETPRICE_PRIVATE_STREAM_ID_START) != RSSL_RET_SUCCESS)
					return RSSL_RET_FAILURE;
			}
		}
	}

	return RSSL_RET_SUCCESS;
}
/*
 * Sends a source directory response to a channel.  This consists
 * of getting a message buffer, setting the source directory response
 * information, encoding the source directory response, and sending
 * the source directory response to the server.
 * chnl - The channel to send a source directory response to
 */
RsslRet sendSourceDirectoryResponse(RsslChannel* chnl)
{
	RsslError error;
	RsslBuffer* msgBuf = 0;
	RsslSourceDirectoryResponseInfo srcDirRespInfo;
	RsslUInt16 refreshFlags = 0;
	RsslMsgKey key = RSSL_INIT_MSG_KEY;

	/* initialize source directory response info */
	initSourceDirRespInfo(&srcDirRespInfo);

	/* get a buffer for the source directory response */
	msgBuf = rsslGetBuffer(chnl, MAX_MSG_SIZE, RSSL_FALSE, &error);

	if (msgBuf != NULL)
	{
		/* provide source directory response information */
		/* set refresh flags */
		refreshFlags = RSSL_RFMF_HAS_MSG_KEY | RSSL_RFMF_REFRESH_COMPLETE | RSSL_RFMF_CLEAR_CACHE;
		/* set filter flags */
		key.filter = RDM_DIRECTORY_SERVICE_INFO_FILTER | \
					RDM_DIRECTORY_SERVICE_STATE_FILTER| \
					/*RDM_DIRECTORY_SERVICE_GROUP_FILTER | \ not applicable for refresh message - here for reference*/
					RDM_DIRECTORY_SERVICE_LOAD_FILTER | \
					/*RDM_DIRECTORY_SERVICE_DATA_FILTER | \ not applicable for non-ANSI Page based provider - here for reference*/
					RDM_DIRECTORY_SERVICE_LINK_FILTER;
		/* StreamId */
		srcDirRespInfo.StreamId = SRCDIR_STREAM_ID;
		/* ServiceId */
		srcDirRespInfo.ServiceId = getServiceId();
		/* ServiceName */
		snprintf(srcDirRespInfo.ServiceGeneralInfo.ServiceName, 256, "%s", serviceName);
		/* Vendor */
		snprintf(srcDirRespInfo.ServiceGeneralInfo.Vendor, 256, "%s", vendorName);
		/* Capabilities */
		srcDirRespInfo.ServiceGeneralInfo.Capabilities[0] = RSSL_DMT_DICTIONARY;
		srcDirRespInfo.ServiceGeneralInfo.Capabilities[1] = RSSL_DMT_MARKET_PRICE;
		srcDirRespInfo.ServiceGeneralInfo.Capabilities[2] = RSSL_DMT_MARKET_BY_ORDER;
		/* DictionariesProvided */
		snprintf(srcDirRespInfo.ServiceGeneralInfo.DictionariesProvided[0], 256, "%s", fieldDictionaryName);
		snprintf(srcDirRespInfo.ServiceGeneralInfo.DictionariesProvided[1], 256, "%s", enumTypeDictionaryName);
		/* DictionariesUsed */
		snprintf(srcDirRespInfo.ServiceGeneralInfo.DictionariesUsed[0], 256, "%s", fieldDictionaryName);
		snprintf(srcDirRespInfo.ServiceGeneralInfo.DictionariesUsed[1], 256, "%s", enumTypeDictionaryName);
		/* Qos */
		srcDirRespInfo.ServiceGeneralInfo.QoS[0].dynamic = RSSL_FALSE;
		srcDirRespInfo.ServiceGeneralInfo.QoS[0].rate = RSSL_QOS_RATE_TICK_BY_TICK;
		srcDirRespInfo.ServiceGeneralInfo.QoS[0].timeliness = RSSL_QOS_TIME_REALTIME;
		/* ItemList */
		snprintf(srcDirRespInfo.ServiceGeneralInfo.ItemList, 256, "");
		/* Service StateInfo Status */
		srcDirRespInfo.ServiceStateInfo.Status.streamState = RSSL_STREAM_OPEN;
		srcDirRespInfo.ServiceStateInfo.Status.dataState = RSSL_DATA_OK;
		srcDirRespInfo.ServiceStateInfo.Status.code = RSSL_SC_NONE;
		srcDirRespInfo.ServiceStateInfo.Status.text.data = (char *)"OK";
		srcDirRespInfo.ServiceStateInfo.Status.text.length = (RsslUInt32)strlen("OK");
		/* OpenLimit */
		srcDirRespInfo.ServiceLoadInfo.OpenLimit = OPEN_LIMIT;
		srcDirRespInfo.ServiceLoadInfo.OpenWindow = 0;	 /* Don't send OpenWindow. */
		/* Link Name */
		snprintf(srcDirRespInfo.ServiceLinkInfo[0].LinkName, 256, "%s", linkName);
		/* Link Text */
		snprintf(srcDirRespInfo.ServiceLinkInfo[0].Text, 256, "Link state is up");
		/* keep default values for all others */

		/* encode source directory response */
		if (encodeSourceDirectoryResponse(chnl, &srcDirRespInfo, &key, msgBuf, refreshFlags) != RSSL_RET_SUCCESS)
		{
			rsslReleaseBuffer(msgBuf, &error); 
			printf("\nencodeSourceDirectoryResponse() failed\n");
			return RSSL_RET_FAILURE;
		}

		/* send source directory response */
		if (sendMessage(chnl, msgBuf) != RSSL_RET_SUCCESS)
			return RSSL_RET_FAILURE;
	}
	else
	{
		printf("rsslGetBuffer(): Failed <%s>\n", error.text);
		return RSSL_RET_FAILURE;
	}

	return RSSL_RET_SUCCESS;
}