⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmstools.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * cms_cmstools.c: cmstools utility * * Copyright (c) 2004 Intel Corp. * * Author: Zou Yixiong (yixiong.zou@intel.com) * Author: Zhu Yi (yi.zhu@intel.com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */#include <stdio.h>#include <unistd.h> /* sleep() */#include <stdlib.h>#include <string.h>#include <errno.h>#include <clplumbing/cl_log.h>#include <clplumbing/ipc.h>#include <clplumbing/GSource.h>#include <saf/ais.h>#include "cmstools.h"#define CMDS_MAX_LENGTH		32#define dprintf(arg...)		do { if (option_verbose) fprintf(stderr, \					##arg); } while (0)typedef struct {	const char * name;	SaErrorT (*func)(SaMsgHandleT *, int, char **, const char *);	const char * optstr;} command_t;static SaErrorT queue_open(SaMsgHandleT *, int, char **, const char *);static SaErrorT queue_status(SaMsgHandleT *, int, char **, const char *);static SaErrorT queue_create(SaMsgHandleT *, int, char **, const char *);static SaErrorT queue_close(SaMsgHandleT *, int, char **, const char *);static SaErrorT queue_unlink(SaMsgHandleT *, int, char **, const char *);static SaErrorT group_create(SaMsgHandleT *, int, char **, const char *);static SaErrorT group_delete(SaMsgHandleT *, int, char **, const char *);static SaErrorT group_insert(SaMsgHandleT *, int, char **, const char *);static SaErrorT group_remove(SaMsgHandleT *, int, char **, const char *);static SaErrorT group_track(SaMsgHandleT *, int, char **, const char *);static SaErrorT group_trackstop(SaMsgHandleT *, int, char **, const char *);static SaErrorT message_send(SaMsgHandleT *, int, char **,const char *);static SaErrorT message_get(SaMsgHandleT *, int, char **,const char *);static const command_t commands[] = {	{ "openqueue",		queue_open,	"vc:n:" },	{ "createqueue",	queue_create,	"vc:n:pr:s:t:" },	{ "status",		queue_status,	"vc:n:" },	{ "closequeue",		queue_close,	"vc:n:" },	{ "unlink",		queue_unlink,	"vc:n:" },	{ "creategroup",	group_create,	"vc:n:" },	{ "deletegroup",	group_delete,	"vc:n:" },	{ "insert",		group_insert,	"vc:q:g:" },	{ "remove",		group_remove,	"vc:q:g:" },	{ "track",		group_track,	"vc:n:" },	{ "trackstop",		group_trackstop,"vc:n:" },	{ "send",		message_send,	"vc:n:m:p" },	{ "get",		message_get,	"vc:n:a:" },	{ NULL,			NULL,		NULL },};static const char * option_help ="Usage: cmstools -c <command> [<options> [<parameters>]] ...\n";int option_verbose;int option_sleep;const char * next_command;SaMsgQueueHandleT mqueue_handle;static voidusage(void){	fprintf(stderr, "%s", option_help);	exit(0);}static SaErrorTqueue_open(SaMsgHandleT * handle, int argc, char **argv, const char * optstr){	const char * name = DEFAULT_MQUEUE_NAME;	SaNameT saname;	char c;	SaMsgQueueCreationFlagsT flag;	SaErrorT ret;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;		}	}	strcpy(saname.value, name);	saname.length = strlen(saname.value);	flag = SA_MSG_QUEUE_SELECTION_OBJECT_SET;	if ((ret = saMsgQueueOpen(handle, &saname, NULL, flag, SA_TIME_END,			&mqueue_handle)) != SA_OK)		dprintf("saMsgQueueOpen failed, error = [%d]\n", ret);	else		dprintf("saMsgQueueOpen Succeed!\n");	return ret;}static SaErrorTqueue_create(SaMsgHandleT * handle, int argc, char **argv, const char * optstr){	const char * name = DEFAULT_MQUEUE_NAME;	SaNameT saname;	char c;	SaMsgQueueCreationFlagsT flag;	SaMsgQueueCreationAttributesT attr;	SaErrorT ret;	SaTimeT timeout;	int i;	flag = SA_MSG_QUEUE_SELECTION_OBJECT_SET | SA_MSG_QUEUE_CREATE;	attr.creationFlags = DEFAULT_CREATION_FLAGS;	timeout = DEFAULT_TIMEOUT;	for (i = 0; i <= SA_MSG_MESSAGE_LOWEST_PRIORITY; i++)		attr.size[i] = DEFAULT_MQUEUE_SIZE;	attr.retentionTime = DEFAULT_RETENTION_TIME;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			case 'p':				attr.creationFlags = SA_MSG_QUEUE_PERSISTENT;				break;			case 'r':				attr.retentionTime = atoi(optarg) * 1E9;				attr.creationFlags = 0;				break;			case 's':				for (i = 0; i <= SA_MSG_MESSAGE_LOWEST_PRIORITY				;	i++)					attr.size[i] = atoi(optarg);				break;			case 't':				timeout = atoi(optarg) * 1E9;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;		}	}	strcpy(saname.value, name);	saname.length = strlen(saname.value);	if ((ret = saMsgQueueOpen(handle, &saname, &attr, flag, timeout,			&mqueue_handle)) != SA_OK)		dprintf("saMsgQueueOpen failed, error = [%d]\n", ret);	else		dprintf("saMsgQueueOpen Succeed!\n");	return ret;}static SaErrorTqueue_status(SaMsgHandleT * handle, int argc, char ** argv, const char *optstr){	const char * name = DEFAULT_MQUEUE_NAME;	SaNameT saname;	char c;	SaErrorT ret;	int i;	SaMsgQueueStatusT qst;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;		}	}	strcpy(saname.value, name);	saname.length = strlen(saname.value);	/* dump mqueue status */	if ((ret = saMsgQueueStatusGet(handle, &saname, &qst)) != SA_OK) {		dprintf("saMsgQueueStatus failed, error = [%d]\n", ret);		return ret;	}	dprintf("saMsgQueueStatus is [%d]\n", qst.sendingState);	dprintf("sendingState %d\n", qst.sendingState);	dprintf("creationFlags %lu\n", qst.creationFlags);	dprintf("openFlags %lu\n", qst.openFlags);	dprintf("retentionTime %lld\n", qst.retentionTime);	dprintf("closeTime %lld\n", qst.closeTime);	dprintf("headerLength %d\n", qst.headerLength);	for (i = SA_MSG_MESSAGE_HIGHEST_PRIORITY	;	i <= SA_MSG_MESSAGE_LOWEST_PRIORITY	;	i++) {		dprintf("saMsgQueueUsage[%d].queueSize %lu\n"		,	i, qst.saMsgQueueUsage[i].queueSize);		dprintf("saMsgQueueUsage[%d].queueUsed %d\n"		,	i, qst.saMsgQueueUsage[i].queueUsed);		dprintf("saMsgQueueUsage[%d].numberOfMessages %lu\n"		,	i, qst.saMsgQueueUsage[i].numberOfMessages);	}	return ret;}static SaErrorTqueue_close(SaMsgHandleT * handle, int argc, char **argv, const char * optstr){	const char * name = DEFAULT_MQUEUE_NAME;	SaNameT saname;	char c;	SaErrorT ret;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;		}	}	strcpy(saname.value, name);	saname.length = strlen(saname.value);	if ((ret = saMsgQueueClose(&mqueue_handle)) != SA_OK)		dprintf("saMsgQueueClose failed, error = [%d]\n", ret);        else        	dprintf("saMsgQueueClose Succeed!\n");	return ret;}static SaErrorTqueue_unlink(SaMsgHandleT * handle, int argc, char **argv, const char * optstr){	const char * name = DEFAULT_MQUEUE_NAME;	SaNameT saname;	char c;	SaErrorT ret;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;		}	}	strcpy(saname.value, name);	saname.length = strlen(saname.value);	if ((ret = saMsgQueueUnlink(handle, &saname)) != SA_OK)		dprintf("saMsgQueueUnlink failed, error = [%d]\n", ret);        else        	dprintf("saMsgQueueUnlink Succeed!\n");	return ret;}static SaErrorTgroup_create(SaMsgHandleT * handle, int argc, char **argv,		  const char * optstr){	const char * name = DEFAULT_MQGROUP_NAME;	SaNameT saname;	char c;	SaMsgQueueCreationFlagsT flag;	SaErrorT ret;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;		}	}	strcpy(saname.value, name);	saname.length = strlen(saname.value);	flag = SA_MSG_QUEUE_SELECTION_OBJECT_SET;	if ((ret = saMsgQueueGroupCreate(handle, &saname	,	SA_MSG_QUEUE_GROUP_ROUND_ROBIN)) != SA_OK) {				dprintf("saMsgQueueGroupCreate failed, error = [%d]\n", ret);		return ret;	}	dprintf("saMsgQueueGroupCreate Succeed!\n");	return ret;}static SaErrorTgroup_delete(SaMsgHandleT * handle, int argc, char **argv,		  const char * optstr){	const char * name = DEFAULT_MQGROUP_NAME;	SaNameT saname;	char c;	SaMsgQueueCreationFlagsT flag;	SaErrorT ret;	next_command = NULL;	while (!next_command) {		c = getopt(argc, argv, optstr);		if (c == -1) {			next_command = NULL;			break;		}		switch (c) {			case 'v':				option_verbose = 1;				break;			case 'c':				next_command = optarg;				break;			case 'n':				name = optarg;				break;			default:				dprintf("Error: unknown option %c\n", c);				return -1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -