Skip to content

Commit

Permalink
feat: Parse command line argument of remote worker
Browse files Browse the repository at this point in the history
Add command line argument parsing in remote worker
for allowing user to assign the IP address of the RabbitMQ broker.

Close #185.
  • Loading branch information
marktwtn committed Aug 29, 2019
1 parent d94878c commit da9b541
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/remote_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,45 @@
* "LICENSE" at the root of this distribution.
*/

#include <getopt.h>
#include "common.h"
#include "constants.h"
#include "dcurl.h"
#include "remote_common.h"

int main(int argc, char const *const *argv)
int main(int argc, char *const *argv)
{
char trytes[TRANSACTION_TRYTES_LENGTH];
char buf[4];
int mwm;
int cmdOpt;
int optIdx;
const struct option longOpt[] = {{"broker", required_argument, NULL, 'b'},
{NULL, 0, NULL, 0}};

amqp_connection_state_t conn;
amqp_envelope_t envelope;
char *hostIP = NULL;

/* Parse the command line options */
/* TODO: Support macOS since getopt_long() is GNU extension */
while (1) {
cmdOpt = getopt_long(argc, argv, "b:", longOpt, &optIdx);
if (cmdOpt == -1)
break;

/* Invalid option */
if (cmdOpt == '?')
break;

if (cmdOpt == 'b') {
hostIP = optarg;
}
}

dcurl_init();

if (!connect_broker(&conn, NULL))
if (!connect_broker(&conn, hostIP))
goto fail;

if (!set_consuming_queue(&conn, 1, "incoming_queue"))
Expand Down

0 comments on commit da9b541

Please sign in to comment.