Skip to content

Commit

Permalink
Wrapper to send event messages is added
Browse files Browse the repository at this point in the history
  • Loading branch information
gbuddappagari committed Nov 14, 2018
1 parent 6701a5b commit a802dea
Show file tree
Hide file tree
Showing 6 changed files with 480 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Re-enabled the temporarily commented out setting that prevented cyclic building
- Switched from nanomsg (Release 1.1.2) to NNG (Release v1.0.1)
- Revert from NNG
- Wrapper to send event messages is added

## [1.0.0] - 2018-06-19
### Added
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,4 @@ if (BUILD_TESTING)
add_subdirectory(tests)
endif (BUILD_TESTING)

add_subdirectory(parodusNotifier)
36 changes: 36 additions & 0 deletions parodusNotifier/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright 2016 Comcast Cable Communications Management, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set(PROJ_PARODUS_NOTIFIER_LIB parodusNotifier)

file(GLOB HEADERS parodus_notifier.h)
set(SOURCES parodus_notifier.c)
#-------------------------------------------------------------------------------
# parodusNotifier library
#-------------------------------------------------------------------------------
add_library(${PROJ_PARODUS_NOTIFIER_LIB} STATIC ${HEADERS} ${SOURCES})
add_library(${PROJ_PARODUS_NOTIFIER_LIB}.shared SHARED ${HEADERS} ${SOURCES})
set_target_properties(${PROJ_PARODUS_NOTIFIER_LIB}.shared PROPERTIES COMPILE_FLAGS -DNOTIFIER_LIB)
set_target_properties(${PROJ_PARODUS_NOTIFIER_LIB}.shared PROPERTIES OUTPUT_NAME ${PROJ_PARODUS_NOTIFIER_LIB})
install (TARGETS ${PROJ_PARODUS_NOTIFIER_LIB} DESTINATION lib${LIB_SUFFIX})
install (TARGETS ${PROJ_PARODUS_NOTIFIER_LIB}.shared DESTINATION lib${LIB_SUFFIX})
install (FILES parodus_notifier.h DESTINATION include/${PROJ_PARODUS_NOTIFIER_LIB})
#-------------------------------------------------------------------------------
# parodusNotifier binary
#-------------------------------------------------------------------------------
set(BIN_SOURCES parodus_notifier.c main.c)
add_executable(parodusNotifiercli ${BIN_SOURCES} ${HEADERS})
target_link_libraries (parodusNotifiercli libparodus -lwrp-c -ltrower-base64 -lmsgpackc -lnanomsg -lpthread -lcimplog ${LOGGER_LIBS})
install (TARGETS parodusNotifiercli DESTINATION bin)

134 changes: 134 additions & 0 deletions parodusNotifier/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* Copyright 2016 Comcast Cable Communications Management, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <getopt.h>
#include "../src/libparodus.h"
#include "parodus_notifier.h"

static void print_usage();

int main( int argc, char **argv)
{
notifier_t *msg = NULL;
msg = (notifier_t *) malloc(sizeof(notifier_t));
memset(msg, 0, sizeof(notifier_t));
const char *option_string = "n:s:d:p:c:D::";
int debugEnable = 0;
char *status = NULL;

static const struct option long_options[] = {
{"service-name", required_argument, 0, 'n'},
{"source", required_argument, 0, 's'},
{"destination", required_argument, 0, 'd'},
{"payload", required_argument, 0, 'p'},
{"content-type", required_argument, 0, 'c'},
{"DEBUG", no_argument, 0, 'D'},
{0, 0, 0, 0}
};

int c;
optind = 1;

while(1)
{
/* getopt_long stores the option index here. */
int option_index = 0;
c = getopt_long (argc, argv, option_string, long_options, &option_index);

/* Detect the end of the options. */
if (c == -1)
break;

switch (c)
{
case 'n':
msg->service_name = strdup(optarg);
break;

case 's':
msg->source = strdup(optarg);
break;

case 'd':
msg->destination = strdup(optarg);
break;

case 'p':
msg->payload = strdup(optarg);
break;

case 'c':
msg->content_type = strdup(optarg);
break;

case 'D':
debugEnable = 1;
printf("DEBUG mode is on\n");
break;

case '?':
/* getopt_long already printed an error message. */
break;

default:
fprintf(stderr,"Enter valid arguments..\n");
print_usage();
return -1;
}
}

/* Print any remaining command line arguments (not options). */
if (optind < argc)
{
fprintf(stderr,"non-option ARGV-elements: ");
while (optind < argc)
fprintf(stderr,"%s ", argv[optind++]);
putchar ('\n');
}

if(debugEnable)
{
printf("service_name: %s\nsource: %s\ndestination: %s\ncontent_type: %s\npayload: %s\n",msg->service_name, msg->source, msg->destination, msg->content_type, msg->payload);
}

int ret = send_event_to_parodus(msg);
get_status_message(ret, &status);
if(ret == 0)
{
fprintf(stdout,"%s\n",status);
}
else
{
fprintf(stderr,"%s\n",status);
if(ret > 0)
{
print_usage();
}
}
free(status);
free_notifier_struct(msg);
return ret;
}

static void print_usage()
{
fprintf(stderr, "Usage:\nparodusNotifiercli --service-name=<value> --source=<value> --destination=<value> --payload=<value> --content-type=<value> [--DEBUG]\n\n" );
}
Loading

0 comments on commit a802dea

Please sign in to comment.