PageRenderTime 64ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/openhpi-3.0.0/clients/ohparam.c

#
C | 387 lines | 293 code | 44 blank | 50 comment | 77 complexity | 951db081a81db2eaec5418f2e56d483b MD5 | raw file
Possible License(s): BSD-3-Clause
  1. /* -*- linux-c -*-
  2. *
  3. * Copyright (C) Copyright Nokia Siemens Networks 2010
  4. * (C) Copyright Ulrich Kleber 2011
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This
  9. * file and program are licensed under a BSD style license. See
  10. * the Copying file included with the OpenHPI distribution for
  11. * full licensing terms.
  12. *
  13. * Authors:
  14. * Ulrich Kleber <ulikleber@users.sourceforge.net>
  15. *
  16. * Log:
  17. * Start from hpidomain.c
  18. * This routine can display and manipulate parameters of the
  19. * openHPI daemon as specified in openhpi.conf file, using
  20. * the OpenHPI extensions as described in ohpi.c
  21. *
  22. * Changes:
  23. * 03/02/2011 ulikleber Refactoring to use glib for option parsing and
  24. * introduce common options for all clients
  25. *
  26. */
  27. #include "oh_clients.h"
  28. #define OH_SVN_REV "$Revision: 7142 $"
  29. #define OHPARAM_HELP \
  30. "Command get: display info about all global parameters \n" \
  31. " no specific arguments \n" \
  32. "Command set: \n" \
  33. " one of the daemon's global parameters: \n" \
  34. " (without the OPENHPI prefix) \n" \
  35. " ON_EP, LOG_ON_SEV, EVT_QUEUE_LIMIT, \n" \
  36. " DEL_SIZE_LIMIT, DEL_SAVE \n" \
  37. " DAT_SIZE_LIMIT, DAT_USER_LIMIT, DAT_SAVE \n" \
  38. " PATH, VARPATH, CONF \n" \
  39. " and the desired new value. Example: \n" \
  40. " ohparam set DEL_SIZE_LIMIT 20000 "
  41. /*
  42. * Function prototypes
  43. */
  44. static SaErrorT execglobalparamget (void);
  45. static SaErrorT execglobalparamset (oHpiGlobalParamTypeT,char *);
  46. /*
  47. * Globals
  48. */
  49. static oHpiCommonOptionsT copt;
  50. SaHpiSessionIdT sessionid;
  51. /*
  52. * Main
  53. */
  54. int
  55. main(int argc, char **argv)
  56. {
  57. SaErrorT rv = SA_OK;
  58. oHpiGlobalParamTypeT paramtype = OHPI_CONF;
  59. char setparam[OH_PATH_PARAM_MAX_LENGTH];
  60. SaHpiBoolT printusage = FALSE;
  61. int i=1;
  62. GOptionContext *context;
  63. enum cmdT {eUndefined,
  64. eGlobalParamGet,
  65. eGlobalParamSet} cmd=eUndefined;
  66. /* Print version strings */
  67. oh_prog_version(argv[0]);
  68. /* Parsing options */
  69. static char usetext[]="command [specific arguments] - "
  70. "Control openhpi configuration parameters.\n "
  71. OH_SVN_REV "\n\n" OHPARAM_HELP ;
  72. OHC_PREPARE_REVISION(usetext);
  73. context = g_option_context_new (usetext);
  74. if (!ohc_option_parse(&argc, argv,
  75. context, &copt,
  76. OHC_ALL_OPTIONS
  77. - OHC_ENTITY_PATH_OPTION // not applicable
  78. - OHC_VERBOSE_OPTION )) { // no verbose mode
  79. printusage = TRUE;
  80. }
  81. g_option_context_free (context);
  82. /* Parse ohparam specific commands */
  83. while (i<argc && !printusage) {
  84. if (strcmp(argv[i],"get")==0) {
  85. cmd=eGlobalParamGet;
  86. }
  87. else if (strcmp(argv[i],"set")==0) {
  88. cmd=eGlobalParamSet;
  89. if (++i<argc) {
  90. if (strcmp(argv[i],"OPENHPI_ON_EP")==0)
  91. paramtype=OHPI_ON_EP;
  92. else if (strcmp(argv[i],"OPENHPI_LOG_ON_SEV")==0)
  93. paramtype=OHPI_LOG_ON_SEV;
  94. else if (strcmp(argv[i],"OPENHPI_EVT_QUEUE_LIMIT")==0)
  95. paramtype=OHPI_EVT_QUEUE_LIMIT;
  96. else if (strcmp(argv[i],"OPENHPI_DEL_SIZE_LIMIT")==0)
  97. paramtype=OHPI_DEL_SIZE_LIMIT;
  98. else if (strcmp(argv[i],"OPENHPI_DEL_SAVE")==0)
  99. paramtype=OHPI_DEL_SAVE;
  100. else if (strcmp(argv[i],"OPENHPI_DAT_SIZE_LIMIT")==0)
  101. paramtype=OHPI_DAT_SIZE_LIMIT;
  102. else if (strcmp(argv[i],"OPENHPI_DAT_USER_LIMIT")==0)
  103. paramtype=OHPI_DAT_USER_LIMIT;
  104. else if (strcmp(argv[i],"OPENHPI_DAT_SAVE")==0)
  105. paramtype=OHPI_DAT_SAVE;
  106. else if (strcmp(argv[i],"OPENHPI_PATH")==0)
  107. paramtype=OHPI_PATH;
  108. else if (strcmp(argv[i],"OPENHPI_VARPATH")==0)
  109. paramtype=OHPI_VARPATH;
  110. else if (strcmp(argv[i],"OPENHPI_CONF")==0)
  111. paramtype=OHPI_CONF;
  112. else printusage = TRUE;
  113. }
  114. else printusage = TRUE;
  115. if (++i<argc) strcpy(setparam, argv[i]);
  116. else if (i>=argc) printusage = TRUE;
  117. }
  118. else printusage = TRUE;
  119. i++;
  120. }
  121. if (printusage == TRUE || cmd == eUndefined)
  122. {
  123. printf("\n");
  124. printf("Usage: %s [Option...] command [specific arguments]\n\n",
  125. argv[0]);
  126. printf(OHPARAM_HELP"\n");
  127. printf(" Options: \n");
  128. printf(" -h, --help Show help options \n");
  129. printf(" -D, --domain=nn Select domain id nn \n");
  130. printf(" -X, --debug Display debug messages \n");
  131. printf(" -N, --host=\"host<:port>\" Open session to the domain served by the daemon \n");
  132. printf(" at the specified URL (host:port) \n");
  133. printf(" This option overrides the OPENHPI_DAEMON_HOST and \n");
  134. printf(" OPENHPI_DAEMON_PORT environment variables. \n");
  135. printf(" -C, --cfgfile=\"file\" Use passed file as client configuration file \n");
  136. printf(" This option overrides the OPENHPICLIENT_CONf \n");
  137. printf(" environment variable. \n\n");
  138. return 1;
  139. }
  140. rv = ohc_session_open_by_option ( &copt, &sessionid);
  141. if (rv != SA_OK) return -1;
  142. switch (cmd){
  143. case eGlobalParamGet:
  144. rv = execglobalparamget ( );
  145. break;
  146. case eGlobalParamSet:
  147. rv = execglobalparamset ( paramtype, setparam );
  148. break;
  149. default:
  150. printf("\n\nSorry, this function is not implemented yet\n\n");
  151. rv = SA_ERR_HPI_INVALID_PARAMS;
  152. }
  153. if (rv == SA_OK) {
  154. rv = saHpiSessionClose(sessionid);
  155. return 0;
  156. }
  157. printf("Param set failed with returncode %s\n", oh_lookup_error(rv));
  158. return rv;
  159. }
  160. /*
  161. *
  162. */
  163. static SaErrorT execglobalparamget ()
  164. {
  165. SaErrorT rv = SA_OK;
  166. oHpiGlobalParamT param;
  167. if (copt.debug) DBG("Go and read global parameters in domain %u", copt.domainid);
  168. param.Type = OHPI_ON_EP;
  169. rv = oHpiGlobalParamGet (sessionid, &param);
  170. if (rv!=SA_OK) {
  171. CRIT("oHpiGlobalParamGet(OHPI_ON_EP) returned %s", oh_lookup_error(rv));
  172. return rv;
  173. }
  174. printf("OPENHPI_ON_EP: ");
  175. oh_print_ep (&(param.u.OnEP),0);
  176. param.Type = OHPI_LOG_ON_SEV;
  177. rv = oHpiGlobalParamGet (sessionid, &param);
  178. if (rv!=SA_OK) {
  179. CRIT("oHpiGlobalParamGet(OHPI_LOG_ON_SEV) returned %s", oh_lookup_error(rv));
  180. return rv;
  181. }
  182. printf("OPENHPI_LOG_ON_SEV = %s\n", oh_lookup_severity (param.u.LogOnSev));
  183. param.Type =OHPI_EVT_QUEUE_LIMIT;
  184. rv = oHpiGlobalParamGet (sessionid, &param);
  185. if (rv!=SA_OK) {
  186. CRIT("oHpiGlobalParamGet(OHPI_EVT_QUEUE_LIMIT) returned %s",
  187. oh_lookup_error(rv));
  188. return rv;
  189. }
  190. printf("OPENHPI_EVT_QUEUE_LIMIT = %u\n", param.u.EvtQueueLimit);
  191. param.Type =OHPI_DEL_SIZE_LIMIT;
  192. rv = oHpiGlobalParamGet (sessionid, &param);
  193. if (rv!=SA_OK) {
  194. CRIT("oHpiGlobalParamGet(OHPI_DEL_SIZE_LIMIT) returned %s",
  195. oh_lookup_error(rv));
  196. return rv;
  197. }
  198. printf("OPENHPI_DEL_SIZE_LIMIT = %u\n", param.u.DelSizeLimit);
  199. param.Type =OHPI_DEL_SAVE;
  200. rv = oHpiGlobalParamGet (sessionid, &param);
  201. if (rv!=SA_OK) {
  202. CRIT("oHpiGlobalParamGet(OHPI_DEL_SAVE) returned %s",
  203. oh_lookup_error(rv));
  204. return rv;
  205. }
  206. printf("OPENHPI_DEL_SAVE = ");
  207. if (param.u.DelSave) printf("TRUE\n");
  208. else printf("FALSE\n");
  209. param.Type =OHPI_DAT_SIZE_LIMIT;
  210. rv = oHpiGlobalParamGet (sessionid, &param);
  211. if (rv!=SA_OK) {
  212. CRIT("oHpiGlobalParamGet(OHPI_DAT_SIZE_LIMIT) returned %s",
  213. oh_lookup_error(rv));
  214. return rv;
  215. }
  216. printf("OPENHPI_DAT_SIZE_LIMIT = %u\n", param.u.DatSizeLimit);
  217. param.Type =OHPI_DAT_USER_LIMIT;
  218. rv = oHpiGlobalParamGet (sessionid, &param);
  219. if (rv!=SA_OK) {
  220. CRIT("oHpiGlobalParamGet(OHPI_DAT_USER_LIMIT) returned %s",
  221. oh_lookup_error(rv));
  222. return rv;
  223. }
  224. printf("OPENHPI_DAT_USER_LIMIT = %u\n", param.u.DatUserLimit);
  225. param.Type =OHPI_DAT_SAVE;
  226. rv = oHpiGlobalParamGet (sessionid, &param);
  227. if (rv!=SA_OK) {
  228. CRIT("oHpiGlobalParamGet(OHPI_DAT_SAVE) returned %s",
  229. oh_lookup_error(rv));
  230. return rv;
  231. }
  232. printf("OPENHPI_DAT_SAVE = ");
  233. if (param.u.DatSave) printf("TRUE\n");
  234. else printf("FALSE\n");
  235. param.Type =OHPI_PATH;
  236. rv = oHpiGlobalParamGet (sessionid, &param);
  237. if (rv!=SA_OK) {
  238. CRIT("oHpiGlobalParamGet(OHPI_PATH) returned %s",
  239. oh_lookup_error(rv));
  240. return rv;
  241. }
  242. printf("OPENHPI_PATH = %s\n",param.u.Path);
  243. param.Type =OHPI_VARPATH;
  244. rv = oHpiGlobalParamGet (sessionid, &param);
  245. if (rv!=SA_OK) {
  246. CRIT("oHpiGlobalParamGet(OHPI_VARPATH) returned %s",
  247. oh_lookup_error(rv));
  248. return rv;
  249. }
  250. printf("OPENHPI_VARPATH = %s\n",param.u.VarPath);
  251. param.Type =OHPI_CONF;
  252. rv = oHpiGlobalParamGet (sessionid, &param);
  253. if (rv!=SA_OK) {
  254. CRIT("oHpiGlobalParamGet(OHPI_CONF) returned %s",
  255. oh_lookup_error(rv));
  256. return rv;
  257. }
  258. printf("OPENHPI_CONF = %s\n",param.u.Conf);
  259. return SA_OK;
  260. }
  261. /*
  262. *
  263. */
  264. static SaErrorT execglobalparamset (oHpiGlobalParamTypeT ptype, char *setparam)
  265. {
  266. SaErrorT rv = SA_OK;
  267. oHpiGlobalParamT param;
  268. SaHpiTextBufferT buffer;
  269. if (copt.debug) DBG("Go and set global parameter %u in domain %u to %s",
  270. ptype, copt.domainid, setparam);
  271. param.Type = ptype;
  272. switch (ptype){
  273. //strings
  274. case OHPI_PATH: strcpy(param.u.Path, setparam);break;
  275. case OHPI_VARPATH: strcpy(param.u.VarPath, setparam);break;
  276. case OHPI_CONF: strcpy(param.u.Conf, setparam);break;
  277. //ep
  278. case OHPI_ON_EP:
  279. if (oh_encode_entitypath(setparam,&param.u.OnEP)!=SA_OK)
  280. return SA_ERR_HPI_INVALID_PARAMS;
  281. break;
  282. //severity
  283. case OHPI_LOG_ON_SEV:
  284. strncpy((char *)buffer.Data, setparam, SAHPI_MAX_TEXT_BUFFER_LENGTH);
  285. if (oh_encode_severity(&buffer, &param.u.LogOnSev)!=SA_OK)
  286. return SA_ERR_HPI_INVALID_PARAMS;
  287. break;
  288. //integers
  289. case OHPI_EVT_QUEUE_LIMIT: param.u.EvtQueueLimit = atoi(setparam);break;
  290. case OHPI_DEL_SIZE_LIMIT: param.u.DelSizeLimit = atoi(setparam);break;
  291. case OHPI_DAT_SIZE_LIMIT: param.u.DatSizeLimit = atoi(setparam);break;
  292. case OHPI_DAT_USER_LIMIT: param.u.DatUserLimit = atoi(setparam);break;
  293. //bools
  294. case OHPI_DEL_SAVE:
  295. if (strcmp(setparam,"TRUE")==0) param.u.DelSave = SAHPI_TRUE;
  296. else if (strcmp(setparam,"FALSE")==0) param.u.DelSave = SAHPI_FALSE;
  297. else return SA_ERR_HPI_INVALID_PARAMS;
  298. break;
  299. case OHPI_DAT_SAVE:
  300. if (strcmp(setparam,"TRUE")==0) param.u.DatSave = SAHPI_TRUE;
  301. else if (strcmp(setparam,"FALSE")==0) param.u.DatSave = SAHPI_FALSE;
  302. else return SA_ERR_HPI_INVALID_PARAMS;
  303. break;
  304. }
  305. rv = oHpiGlobalParamSet (sessionid, &param);
  306. if (rv!=SA_OK) {
  307. CRIT("oHpiGlobalParamSet returned %s", oh_lookup_error(rv));
  308. return rv;
  309. }
  310. switch (param.Type){
  311. case OHPI_ON_EP: printf("OPENHPI_ON_EP: ");
  312. oh_print_ep (&(param.u.OnEP),0);
  313. break;
  314. case OHPI_LOG_ON_SEV: printf("OPENHPI_LOG_ON_SEV = %s\n",
  315. oh_lookup_severity (param.u.LogOnSev));
  316. break;
  317. case OHPI_EVT_QUEUE_LIMIT: printf("OPENHPI_EVT_QUEUE_LIMIT = %u\n",
  318. param.u.EvtQueueLimit);
  319. break;
  320. case OHPI_DEL_SIZE_LIMIT: printf("OPENHPI_DEL_SIZE_LIMIT = %u\n",
  321. param.u.DelSizeLimit);
  322. break;
  323. case OHPI_DEL_SAVE: printf("OPENHPI_DEL_SAVE = ");
  324. if (param.u.DelSave) printf("TRUE\n");
  325. else printf("FALSE\n");
  326. break;
  327. case OHPI_DAT_SIZE_LIMIT: printf("OPENHPI_DAT_SIZE_LIMIT = %u\n",
  328. param.u.DatSizeLimit);
  329. break;
  330. case OHPI_DAT_USER_LIMIT: printf("OPENHPI_DAT_USER_LIMIT = %u\n",
  331. param.u.DatUserLimit);
  332. break;
  333. case OHPI_DAT_SAVE: printf("OPENHPI_DAT_SAVE = ");
  334. if (param.u.DatSave) printf("TRUE\n");
  335. else printf("FALSE\n");
  336. break;
  337. case OHPI_PATH: printf("OHPENPI_PATH = %s\n",param.u.Path);break;
  338. case OHPI_VARPATH: printf("OPENHPI_VARPATH = %s\n",param.u.VarPath);break;
  339. case OHPI_CONF: printf("OPENHPI_CONF = %s\n",param.u.Conf);break;
  340. }
  341. return SA_OK;
  342. }
  343. /* end ohparam.c */