Hi Praveen One comment below:
On 1/6/17, 9:46 pm, "Praveen" <praveen.malv...@oracle.com> wrote: --- samples/amf/sa_aware/Makefile.am | 13 +++- samples/amf/sa_aware/README | 8 +++ samples/amf/sa_aware/amf_sc_status_app.c | 115 +++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 samples/amf/sa_aware/amf_sc_status_app.c diff --git a/samples/amf/sa_aware/Makefile.am b/samples/amf/sa_aware/Makefile.am index c34f94a..d8dbbd1 100644 --- a/samples/amf/sa_aware/Makefile.am +++ b/samples/amf/sa_aware/Makefile.am @@ -24,7 +24,7 @@ EXTRA_DIST = \ AppConfig-nwayactive.xml \ README -bin_PROGRAMS = amf_demo +bin_PROGRAMS = amf_demo amfscstatusdemo amf_demo_CPPFLAGS = \ -DSA_EXTENDED_NAME_SOURCE \ @@ -36,10 +36,21 @@ amf_demo_SOURCES = \ amf_demo_LDADD = \ @SAF_AIS_AMF_LIBS@ +amfscstatusdemo_CPPFLAGS = \ + -DSA_EXTENDED_NAME_SOURCE \ + $(AM_CPPFLAGS) + +amfscstatusdemo_SOURCES = \ + amf_sc_status_app.c + +amfscstatusdemo_LDADD = \ + @SAF_AIS_AMF_LIBS@ + install-data-hook: mkdir -p /opt/amf_demo cp amf_demo /opt/amf_demo cp amf_demo_script /opt/amf_demo + cp amfscstatusdemo /opt/amf_demo [GL] I had to replace with ‘cp amfscstatusdemo $(DESTDIR)/opt/amf_demo’ to reflect the latest version. uninstall-hook: rm -rf /opt/amf_demo diff --git a/samples/amf/sa_aware/README b/samples/amf/sa_aware/README index e8e4539..94a639a 100644 --- a/samples/amf/sa_aware/README +++ b/samples/amf/sa_aware/README @@ -34,3 +34,11 @@ Some steps to follow: 6. Run below command for invocation of CSI Attribute Change Callback : immcfg -a saAmfCSIAttriValue+=CCCC safCsiAttr=AmfDemo1,safCsi=AmfDemo,safSi=AmfDemo,safApp=AmfDemo1 +Steps to run amfscstatusdemo: +1)Run amfscstatusdemo from a terminal on a payload node. +2)Bring down controllers. +3)amfscstatusdemo will exit with message: + "Received SC Status Change Callback: SC status Absent" +4)When SCs are down bring one controler up, amfscstatusdemo will + exit with message + "Received SC Status Change Callback: SC status Present" diff --git a/samples/amf/sa_aware/amf_sc_status_app.c b/samples/amf/sa_aware/amf_sc_status_app.c new file mode 100644 index 0000000..b2585b8 --- /dev/null +++ b/samples/amf/sa_aware/amf_sc_status_app.c @@ -0,0 +1,115 @@ +/* -*- OpenSAF -*- + * + * Copyright (C) 2017, Oracle and/or its affiliates. All rights reserved. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed + * under the GNU Lesser General Public License Version 2.1, February 1999. + * The complete license can be accessed from the following location: + * http://opensource.org/licenses/lgpl-license.php + * See the Copying file included with the OpenSAF distribution for full + * licensing terms. + * + */ + +#include <stdio.h> +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <poll.h> +#include <libgen.h> +#include <signal.h> +#include <string.h> +#include <sys/inotify.h> + +#include <saAmf.h> +#include <saAis.h> + +char path[256]; +FILE *fp; + +/* + * @brief AMF will invoke this callback whenever SCs goes down and + * joins back. + */ +static void my_sc_status_cbk(OsafAmfSCStatusT state) { + fp = fopen(path, "w"); + if (fp == NULL) { + exit(EXIT_FAILURE); + } + if (state == OSAF_AMF_SC_PRESENT) { + fprintf(stdout, "\nReceived SC Status Change Callback: SC status Present\n\n"); + fprintf(fp, "\nReceived SC Status Change Callback: SC status Present\n\n"); + } else if(state == OSAF_AMF_SC_ABSENT) { + fprintf(stdout, "\nReceived SC Status Change Callback: SC status Absent\n\n"); + fprintf(fp, "\nReceived SC Status Change Callback: SC status Absent\n\n"); + } + fclose(fp); +} + +int main(int argc, char **argv) +{ + SaAisErrorT rc; + struct pollfd fds[1]; + int inotify_fd, inotify_fd2; + SaAmfCallbacksT_4 amf_cbk = {0}; + SaVersionT ver = {'B', 0x04, 0x01}; + SaAmfHandleT amf_hdl; + + //Open log file. Log pid, a message and close it. + snprintf(path, sizeof(path), "%s/amfscstatusdemo.log", "/tmp"); + fp = fopen(path, "w"); + if (fp == NULL) { + fprintf(stderr, " log file open FAILED:%u", rc); + goto done; + } + fprintf(fp, "%d\n", getpid()); + fclose(fp); + + //Initialize with AMF. + rc = saAmfInitialize_4(&amf_hdl, &amf_cbk, &ver); + if (rc != SA_AIS_OK) { + fprintf(stderr, " saAmfInitialize FAILED %u", rc); + goto done; + } + + //Register SC Status Change Callback with AMF. + osafAmfInstallSCStatusChangeCallback(my_sc_status_cbk); + + if ((inotify_fd = inotify_init ()) < 0) { + fprintf (stderr, "inotify_init() failed with: '%s'\n", strerror (errno)); + goto done; + } + + if ((inotify_fd2 = inotify_add_watch (inotify_fd, path, IN_MODIFY)) < 0) { + fprintf (stderr, "inotify_add_watch failed with: '%s'\n", strerror (errno)); + goto done; + } + + fds[0].fd= inotify_fd; + fds[0].events = POLLIN; + + while (1) { + int res = poll(fds, 1, -1); + if (res == -1) { + if (errno == EINTR) { + continue; + } else { + fprintf(stderr, "poll FAILED - %s", strerror(errno)); + goto done; + } + } + if (fds[0].revents & POLLIN) { + rc = saAmfFinalize(amf_hdl); + if (rc != SA_AIS_OK) { + fprintf(stderr, " saAmfFinalize FAILED %u", rc); + exit(EXIT_FAILURE); + } + inotify_rm_watch(inotify_fd, inotify_fd2); + exit(EXIT_SUCCESS); + } + } +done: + return EXIT_FAILURE; +} -- 1.9.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel