|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- #include <stdio.h>
- #include <stdlib.h>
- #include <getopt.h>
- #include <pthread.h>
-
- #include "listener.h"
- #include "client.h"
-
-
- /*!
- * Global data
- */
- //! @{
-
- settings_t settings_init (settings);
- devList_t devList_init (devList[AEMLIST_SIZE]);
- stats_t stats;
-
- //! @}
-
- /*!
- * CLI short options
- */
- const char *short_opt = "nd:i:l:p:s:w:th";
-
- /*!
- * CLI long options
- */
- const struct option long_opt[] = {
- {"port", required_argument, NULL, 'n'},
- {"duration", required_argument, NULL, 'd'},
- {"interval", required_argument, NULL, 'i'},
- {"outlevel", required_argument, NULL, 'l'},
- {"pingtimeout",required_argument, NULL, 'p'},
- {"sendtimeout",required_argument, NULL, 's'},
- {"who", required_argument, NULL, 'w'},
- {"tracktime", no_argument, NULL, 't'},
- {"help", no_argument, NULL, 'h'},
- {NULL, 0, NULL, 0}
- };
-
- /*!
- * \brief
- * Parse input argument and fill the kcli_input_t struct
- * \param in Pointer to \ref kcli_input_t structure to fill
- * \param argc The argument count as passed to the main()
- * \param argv Argument array as passed to the main()
- * \return The status of the operation
- * \arg 0 Success
- * \arg 1 Fail
- */
- int parse_args (settings_t *s, int argc, char const *argv[]) {
- int c;
-
- while ((c = getopt_long (argc, (char *const *)argv, short_opt, long_opt, NULL)) != -1) {
- switch (c) {
- case -1: /* no more arguments */
- case 0: /* long options toggles */
- break;
- case 'n': s->port = atoi(optarg); break;
- case 'd': s->duration = atoi (optarg); break;
- case 'i': s->msgInterval = atoi (optarg); break;
- case 'l':
- s->outLevel = atoi (optarg);
- if (s->outLevel >= OUTLEVEL_2) s->outLevel = OUTLEVEL_2;
- if (s->outLevel < OUTLEVEL_0) s->outLevel = OUTLEVEL_0;
- break;
- case 'p': s->pingTimeout = atoi (optarg); break;
- case 's': s->sendTimeout.tv_sec = atoi (optarg); break;
- case 'w': s->me = atoi (optarg); break;
- case 't': s->trackTime = true; break;
- case 'h': printf ("This will be the help text\n");
- case ':':
- default:
- case '?':
- fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c);
- fprintf (stderr, "Try `%s --help' for more information.\n", argv[0]);
- exit(1);
- }
- }
- return 0;
- }
-
-
- int main(int argc, char const *argv[]) {
-
- parse_args (&settings, argc, argv);
- log_init ();
- stats_init (&stats);
- msgList_init (&msgList);
-
- // Create threads
- pthread_t ptL, ptC;
- pthread_create (&ptL, NULL, pthListener, NULL);
- pthread_create (&ptC, NULL, pthClient, NULL);
-
- // block here
- pthread_join (ptL, NULL);
- pthread_join (ptC, NULL);
- return 0;
- }
|