int main (void) {
	SaMsgHandleT handle;
	SaMsgQueueHandleT queue_handle;
	fd_set read_fds;
	SaSelectionObjectT select_fd;
	int result;
	SaNameT queue_name;
	SaNameT queue_group_name;

	signal (SIGINT, sigintr_handler);

	result = saMsgInitialize (&handle, &callbacks, &version);
	if (result != SA_AIS_OK) {
		printf ("Could not initialize Cluster Membership API instance error %d\n", result);
		exit (1);
	}

	saMsgSelectionObjectGet (handle, &select_fd);

	setSaNameT (&queue_name, "queue");

	result = saMsgQueueOpen (handle,
		&queue_name,
		&creation_attributes,
		SA_MSG_QUEUE_CREATE,
		SA_TIME_END,
		&queue_handle);
	printf ("saMsgQueueOpen result is %d (should be 1)\n", result);

	setSaNameT (&queue_group_name, "queue_group");

	result = saMsgQueueGroupCreate (
		handle,
		&queue_group_name,
		SA_MSG_QUEUE_GROUP_ROUND_ROBIN);
	printf ("saMsgQueueGroupCreate result is %d (should be 1)\n", result);

	result = saMsgQueueGroupCreate (
		handle,
		&queue_group_name,
		SA_MSG_QUEUE_GROUP_ROUND_ROBIN);
	printf ("saMsgQueueGroupCreate result is %d (should be 14)\n", result);

	result = saMsgQueueGroupInsert (
		handle,
		&queue_group_name,
		&queue_name);
	printf ("saMsgQueueGroupInsert result is %d (should be 1)\n", result);


	FD_ZERO (&read_fds);
	do {
		FD_SET (select_fd, &read_fds);
		FD_SET (STDIN_FILENO, &read_fds);
		result = select (select_fd + 1, &read_fds, 0, 0, 0);
		if (result == -1) {
			perror ("select\n");
		}
		if (FD_ISSET (STDIN_FILENO, &read_fds)) {
			break;
		}
		saMsgDispatch (handle, SA_DISPATCH_ALL);
	} while (result);

	result = saMsgQueueGroupRemove (
		handle,
		&queue_group_name,
		&queue_name);
	printf ("saMsgQueueGroupRemove result is %d (should be 1)\n", result);

	result = saMsgQueueGroupDelete (handle,
		&queue_group_name);
	printf ("saMsgQueueGroupDelete result is %d (should be 1)\n", result);

	result = saMsgQueueClose (queue_handle);
	printf ("saMsgQueueClose result is %d (should be 1)\n", result);

	result = saMsgFinalize (handle);
	printf ("Finalize result is %d (should be 1)\n", result);
	return (0);
}
Ejemplo n.º 2
0
int main (void) {
	SaMsgHandleT handle;
	SaMsgMessageT message;
	SaMsgQueueHandleT queue_handle;
	SaSelectionObjectT select_fd;
	SaInvocationT invocation = 3;

	int result;

	SaNameT async_name;
	SaNameT queue_name;
	SaNameT queue_group_name;
	SaTimeT msg_time;
	SaMsgSenderIdT id;
	SaMsgMessageT msg_a;
	SaMsgMessageT msg_b;
	SaMsgMessageT msg_c;

	memset (&msg_a, 0, sizeof (SaMsgMessageT));
	memset (&msg_b, 0, sizeof (SaMsgMessageT));
	memset (&msg_c, 0, sizeof (SaMsgMessageT));

	signal (SIGINT, sigintr_handler);

	result = saMsgInitialize (&handle, &callbacks, &version);
	if (result != SA_AIS_OK) {
		printf ("Could not initialize Cluster Membership API instance error %d\n", result);
		exit (1);
	}

	saMsgSelectionObjectGet (handle, &select_fd);

	setSaNameT (&async_name, "async");
	setSaNameT (&queue_name, "queue");

	result = saMsgQueueOpen (handle,
		&queue_name,
		&creation_attributes,
		SA_MSG_QUEUE_CREATE,
		SA_TIME_END,
		&queue_handle);
	printf ("saMsgQueueOpen result is %d (should be 1)\n", result);
	printf ("saMsgQueueOpen { queue_handle = %llx }\n", queue_handle);

	result = saMsgQueueOpenAsync (handle,
				      invocation,
				      &async_name,
				      &creation_attributes,
				      SA_MSG_QUEUE_CREATE);
	printf ("saMsgQueueOpenAsync result is %d (should be 1)\n", result);
	printf ("saMsgQueueOpen { async_handle = %llx }\n", async_handle);

	setSaNameT (&queue_group_name, "queue_group");

	result = saMsgQueueGroupCreate (
		handle,
		&queue_group_name,
		SA_MSG_QUEUE_GROUP_ROUND_ROBIN);
	printf ("saMsgQueueGroupCreate result is %d (should be 1)\n", result);

	result = saMsgQueueGroupCreate (
		handle,
		&queue_group_name,
		SA_MSG_QUEUE_GROUP_ROUND_ROBIN);
	printf ("saMsgQueueGroupCreate result is %d (should be 14)\n", result);

	result = saMsgQueueGroupInsert (
		handle,
		&queue_group_name,
		&queue_name);
	printf ("saMsgQueueGroupInsert result is %d (should be 1)\n", result);

	saMsgDispatch (handle, SA_DISPATCH_ALL);

	/*
	FD_ZERO (&read_fds);
	do {
		FD_SET (select_fd, &read_fds);
		FD_SET (STDIN_FILENO, &read_fds);
		result = select (select_fd + 1, &read_fds, 0, 0, 0);
		if (result == -1) {
			perror ("select\n");
		}
		if (FD_ISSET (STDIN_FILENO, &read_fds)) {
			break;
		}
		saMsgDispatch (handle, SA_DISPATCH_ALL);
	} while (result);
	*/

	setSaMsgMessageT (&message, "test_msg_01");
	result = saMsgMessageSend (handle, &queue_name, &message, SA_TIME_ONE_SECOND);
	printf ("saMsgMessageSend [1] result is %d (should be 1)\n", result);

	setSaMsgMessageT (&message, "test_msg_02");
	result = saMsgMessageSend (handle, &queue_name, &message, SA_TIME_ONE_SECOND);
	printf ("saMsgMessageSend [2] result is %d (should be 1)\n", result);

	setSaMsgMessageT (&message, "test_msg_03");
	result = saMsgMessageSend (handle, &queue_name, &message, SA_TIME_ONE_SECOND);
	printf ("saMsgMessageSend [3] result is %d (should be 1)\n", result);

	setSaMsgMessageT (&message, "test_msg_04");
	result = saMsgMessageSendAsync (handle, invocation, &queue_name, &message,
		SA_MSG_MESSAGE_DELIVERED_ACK);
	printf ("saMsgMessageSendAsync [4] result is %d (should be 1)\n", result);

	setSaMsgMessageT (&message, "test_msg_05");
	result = saMsgMessageSendAsync (handle, invocation, &queue_name, &message,
		SA_MSG_MESSAGE_DELIVERED_ACK);
	printf ("saMsgMessageSendAsync [5] result is %d (should be 1)\n", result);

	saMsgDispatch (handle, SA_DISPATCH_ALL);

	result = saMsgMessageGet (queue_handle, &msg_a, &msg_time, &id, SA_TIME_ONE_MINUTE);
	printf ("saMsgMessageGet [a] result is %d (should be 1)\n", result);

	result = saMsgMessageGet (queue_handle, &msg_b, &msg_time, &id, SA_TIME_ONE_MINUTE);
	printf ("saMsgMessageGet [b] result is %d (should be 1)\n", result);

	result = saMsgMessageGet (queue_handle, &msg_c, &msg_time, &id, SA_TIME_ONE_MINUTE);
	printf ("saMsgMessageGet [c] result is %d (should be 1)\n", result);

	printf ("saMsgMessageGet { (a) data = %s }\n", (char *)(msg_a.data));
	printf ("saMsgMessageGet { (b) data = %s }\n", (char *)(msg_b.data));
	printf ("saMsgMessageGet { (c) data = %s }\n", (char *)(msg_c.data));

	result = saMsgQueueGroupRemove (handle,	&queue_group_name, &queue_name);
	printf ("saMsgQueueGroupRemove result is %d (should be 1)\n", result);

	result = saMsgQueueGroupDelete (handle,	&queue_group_name);
	printf ("saMsgQueueGroupDelete result is %d (should be 1)\n", result);

	printf ("saMsgQueueClose { queue_handle = %llx }\n", queue_handle);
	result = saMsgQueueClose (queue_handle);
	printf ("saMsgQueueClose result is %d (should be 1)\n", result);

	printf ("saMsgQueueClose { async_handle = %llx }\n", async_handle);
	result = saMsgQueueClose (async_handle);
	printf ("saMsgQueueClose result is %d (should be 1)\n", result);

	result = saMsgFinalize (handle);
	printf ("Finalize result is %d (should be 1)\n", result);
	return (0);
}