#include #include #include #include #include #include #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 = "li:v:p:s:w:th"; /*! * CLI long options */ const struct option long_opt[] = { {"port", required_argument, NULL, 'l'}, {"interval", required_argument, NULL, 'i'}, {"outlevel", required_argument, NULL, 'v'}, {"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} }; //// Interrupt handler //void intHandler(int dummy) { // (void)dummy; // statsPrint (&stats); // exit (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 'l': s->port = atoi(optarg); break; case 'i': s->msgInterval = atoi (optarg); break; case 'v': 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"); break; 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); // if (signal(SIGTERM, intHandler) == SIG_ERR) //catching interrupt // log_error("Error: Can not catch SIGINT\n"); // 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; }