Commit a6867712 authored by Lucas Russo's avatar Lucas Russo

examples/client.c: add minimalistic command-line options

Now, we have the option of setting the broker endpoint
on command-line with the -b option
parent df5b6af2
......@@ -4,9 +4,12 @@
*/
#include <mdp.h>
#include <czmq.h>
#include <inttypes.h>
#define LEDS_OPERATION 0
#define DFLT_BIND_FOLDER "/tmp/bpm"
#define DFLT_BIND_ADDR "0"
#define LEDS_OPERATION 0
/* Our tructure */
typedef struct _bpm_client_t {
......@@ -46,12 +49,55 @@ int bpm_blink_leds (bpm_client_t *self, char *service, uint32_t leds)
return 0;
}
void print_help (char *program_name)
{
printf( "Usage: %s [options]\n"
"\t-h This help message\n"
"\t-v Verbose output\n"
"\t-b <broker_endpoint> Broker endpoint\n", program_name);
}
int main (int argc, char *argv [])
{
int verbose = (argc > 1 && streq (argv [1], "-v"));
bpm_client_t *bpm_client = bpm_client_new ("ipc:///tmp/bpm/0", verbose);
int verbose = 0;
char *broker_endp = NULL;
char **str_p;
if (argc < 2) {
print_help (argv[0]);
exit (1);
}
/* FIXME: This is rather buggy! */
/* Simple handling of command-line options. This should be done
* with getopt, for instance*/
int i;
for (i = 1; i < argc; i++)
{
if (streq(argv[i], "-v")) {
verbose = 1;
}
else if (streq(argv[i], "-h"))
{
print_help (argv [0]);
exit (1);
}
else if (streq (argv[i], "-b")) {
str_p = &broker_endp;
}
/* Fallout for options with parameters */
else {
*str_p = strdup (argv[i]);
}
}
/* Set default broker address */
if (broker_endp == NULL) {
broker_endp = strdup ("ipc://"DFLT_BIND_FOLDER"/"DFLT_BIND_ADDR);
}
bpm_client_t *bpm_client = bpm_client_new (broker_endp, verbose);
unsigned i;
for (i = 0; i < 32768; ++i) {
uint32_t leds = (1 << 1);
unsigned int j;
......@@ -65,5 +111,8 @@ int main (int argc, char *argv [])
}
bpm_client_destroy (&bpm_client);
str_p = &broker_endp;
free (*str_p);
broker_endp = NULL;
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment