Code Sample: using the 
Conversation Factory


Description

Here is an example of how to use the Conversation Factory.
Most functions of the Factory toolbox are used.


Commented code



CaiErr 				cai_err		= CAI_OK;
CAI_Conversation		*conversation 	= NULL;
CAI_FlatConversation		flat_conversation;
CAI_Dump			API_Dump;
CAI_Connection			connection;
CAI_Authentication		authentication;
CAI_OpenType			open_type;
CAI_CustomSign			customsign;
CAI_ConversationFactory		*factory 	= NULL;
CAI_XML_BUFFER 			reply;
CAI_Version			version;
CAI_ConversationInfo    	conversation_info;


/* Initialization part */
CAI_initCustomSign(&customsign);
CAI_initConnection(&connection);
CAI_initAuthentication(&authentication);
CAI_initOpenType(&open_type);

/*initialize the connection parameters*/
connection.tcp_server = (unsigned char *) "123.123.123.123";
connection.port_number = 20002;

/*initialize the authentication parameters*/
authentication.corporate_id = (unsigned char *) "guest";
authentication.user_id =      (unsigned char *) "guest";
authentication.password =     (unsigned char *) "guest";

/*initialize the open_type parameters*/
open_type.bind_host_resource=0; 		/* Fast Open */
open_type.custom_sign = &customsign;


/* Create the factory, open conversation, ... */

printf("Creating the conversation Factory ...\n");
cai_err = CAI_createConversationFactory(&connection,
			&authentication,
			&factory);

check_APIv2Err(cai_err, "createConversationFactory",
			NULL, &factory);


printf("*****************************************************\n");


printf("Opening a conversation from the Factory ...\n");
cai_err = CAI_openConversationFromFactory(factory,
			&open_type,
			&conversation);

check_APIv2Err(cai_err, "openConversationFromFactory",
			&conversation, &factory);


printf("*****************************************************\n");


printf("Serializing the conversation from the Factory ...\n");
CAI_initFlatConversation(&flat_conversation);
cai_err = CAI_serializeConversationFromFactory(factory,
			&conversation,
			&flat_conversation);

check_APIv2Err(cai_err, "serializeConversation",
			&conversation, &factory);


printf("*****************************************************\n");


printf("Unserializing the conversation from the Factory ...\n");
cai_err = CAI_unserializeConversationFromFactory(factory,
			&conversation,
			&flat_conversation);
check_APIv2Err(cai_err, "unserializeConversation",
			&conversation, &factory);


printf("*****************************************************\n");

CAI_releaseFlatConversation(&flat_conversation);

printf("Closing the conversation from the Factory ...\n");
cai_err = CAI_closeConversationFromFactory(factory,
			&conversation);

check_APIv2Err(cai_err, "closeConversationFromFactory",
			NULL, &factory);


printf("*****************************************************\n");

CAI_releaseConversationFactory(&factory);