169a7e4f2b2fca10ac439a1531766b54db474f78
[demo.git] / vnfs / VES5.0 / evel / evel-library / code / evel_training / 04-basic-lifecycle / hello_evel_world.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "evel.h"
6
7 int main(int argc, char ** argv)
8 {
9   EVEL_ERR_CODES evel_rc = EVEL_SUCCESS;
10   EVENT_HEADER * heartbeat = NULL;
11
12   printf("\nHello AT&T Vendor Event world!\n");
13   fflush(stdout);
14
15   if (argc != 3)
16   {
17     fprintf(stderr, "Usage: %s <FQDN>|<IP address> <port>\n", argv[0]);
18     exit(-1);
19   }
20
21   /***************************************************************************/
22   /* Initialize                                                              */
23   /***************************************************************************/
24   if (evel_initialize(argv[1],                      /* FQDN                  */
25                       atoi(argv[2]),                /* Port                  */
26                       NULL,                         /* optional path         */
27                       NULL,                         /* optional topic        */
28                       0,                            /* HTTPS?                */
29                       "",                           /* Username              */
30                       "",                           /* Password              */
31                       EVEL_SOURCE_VIRTUAL_MACHINE,  /* Source type           */
32                       "EVEL training demo",         /* Role                  */
33                       0))                           /* Verbosity             */
34   {
35     fprintf(stderr, "\nFailed to initialize the EVEL library!!!\n");
36     exit(-1);
37   }
38   else
39   {
40     printf("Initialization completed\n");
41   }
42
43   /***************************************************************************/
44   /* Send a heartbeat just to show we're alive!                              */
45   /***************************************************************************/
46   heartbeat = evel_new_heartbeat();
47   if (heartbeat != NULL)
48   {
49     evel_rc = evel_post_event(heartbeat);
50     if (evel_rc != EVEL_SUCCESS)
51     {
52       printf("Post failed %d (%s)", evel_rc, evel_error_string());
53     }
54   }
55   else
56   {
57     printf("New heartbeat failed");
58   }
59
60   /***************************************************************************/
61   /* Terminate                                                               */
62   /***************************************************************************/
63   sleep(1);
64   evel_terminate();
65   printf("Terminated\n");
66
67   return 0;
68 }
69