summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/plcd/src/plcd.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/plcd/src/plcd.c')
-rw-r--r--cleopatre/devkit/plcd/src/plcd.c189
1 files changed, 0 insertions, 189 deletions
diff --git a/cleopatre/devkit/plcd/src/plcd.c b/cleopatre/devkit/plcd/src/plcd.c
deleted file mode 100644
index cac97ac516..0000000000
--- a/cleopatre/devkit/plcd/src/plcd.c
+++ /dev/null
@@ -1,189 +0,0 @@
-/* SPC300 bundle {{{
- *
- * Copyright (C) 2009 Spidcom
- *
- * <<<Licence>>>
- *
- * }}} */
-/**
- * \file devkit/plcd/src/plcd.c
- * \brief PLC daemon for AV stack management
- * \ingroup plcd
- *
- * This PLC daemon is responsible for the initialization of
- * the AV stack : start, parameter sending, status watching.
- * It is also responsible for any configuration change from
- * the ethernet / plc side through MME messages.
- *
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <getopt.h>
-#include <syslog.h>
-#include <assert.h>
-#include <sys/types.h>
-#include <unistd.h> /* for getpid() */
-#include "libmme.h"
-#include "libspid.h"
-#include "plcd.h"
-
-#ifdef __UTESTS__
- #include "plcd_utests.h"
-#endif
-
-static spc300_nvram_t g_nvram;
-
-static void print_usage (const char *cmd)
-{
- fprintf (stderr, "Usage : %s " \
- "[ -h --hw_file hardware_info_file ]" \
- "[ -c --conf_file hpav_conf_file ]" \
- "[ -i --info_file hpav_info_file ]" \
- "[ -v --version show version number ]\n",
- cmd);
-}
-
-static void init_info_file (plcd_ctx_t *ctx)
-{
- FILE *fp;
-
- assert (ctx != NULL);
-
- if((fp = fopen (ctx->hpav_info_path, "w")) != NULL)
- {
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_STATUS, LIBSPID_HPAV_INFO_VALUE_STATUS_UNASSOCIATED);
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_CCO, LIBSPID_HPAV_INFO_VALUE_CCO_STATION);
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, "no");
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_SC, "no");
- fprintf (fp, "%s = %s\n", LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, "no");
- fclose (fp);
- }
-}
-
-int plcd_init (plcd_ctx_t *ctx)
-{
- assert(ctx != NULL);
- memset (ctx, '\0', sizeof(plcd_ctx_t));
- ctx->hardware_info_path = LIBSPID_HARDWARE_INFO_PATH;
- ctx->hpav_info_path = LIBSPID_HPAV_INFO_PATH;
- ctx->hpav_conf_path = LIBSPID_HPAV_CONF_PATH;
- ctx->internal_conf_path = LIBSPID_INTERNAL_CONF_PATH;
-
- init_info_file (ctx);
-
- /* open netlink socket */
- if(0 > (ctx->plc_sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_PLC_DRV)))
- {
- perror ("netlink socket open");
- return -1;
- }
- memset(&ctx->plcd_addr, 0, sizeof(ctx->plcd_addr));
- ctx->plcd_addr.nl_family = AF_NETLINK;
- ctx->plcd_addr.nl_pid = getpid(); /* self pid */
- ctx->plcd_addr.nl_groups = 0; /* not in mcast group */
- if (0 > bind(ctx->plc_sock, (struct sockaddr *)&ctx->plcd_addr, sizeof(ctx->plcd_addr)))
- {
- perror("netlink socket bind");
- return -1;
- }
-
- /* get NVRAM data */
- ctx->nvram = &g_nvram;
-#ifdef __UTESTS__
- if(LIBSPID_SUCCESS != utests_libspid_system_get_nvram (ctx->nvram))
-#else
- if(LIBSPID_SUCCESS != libspid_system_get_nvram (ctx->nvram))
-#endif
- {
- perror ("NVRAM content read");
- return -1;
- }
-
- return 0;
-}
-
-void plcd_uninit(plcd_ctx_t *ctx)
-{
- close(ctx->plc_sock);
-}
-
-#ifdef __UTESTS__
- int utests_main (int argc, char **argv)
-#else
- int main (int argc, char **argv)
-#endif
-{
- plcd_ctx_t ctx; /* main context */
- char buffer[1024];
- int c, opt_index = 0;
-
- struct option long_opts[] =
- { { "hw_file", required_argument, NULL, 'h' },
- { "conf_file", required_argument, NULL, 'c' },
- { "info_file", required_argument, NULL, 'i' },
- { "version", no_argument, NULL, 'v' }
- };
-
- /* show PLCD version */
- syslog (LOG_NOTICE, "PLC Daemon (%s) Running\n", VERSION);
-
- /* init context */
- if ( 0 != plcd_init (&ctx) )
- {
- exit(1);
- }
-
- /* open log process */
- openlog (argv[0], 0, LOG_DAEMON);
-
- /*process options */
- while((c = getopt_long_only (argc, argv,
- "h:c:i:v:",
- long_opts, &opt_index)) != -1)
- {
- switch(c)
- {
- case 'h': /* hardware info file */
- ctx.hardware_info_path = optarg;
- break;
- case 'c': /* HP AV config file */
- ctx.hpav_conf_path = optarg;
- break;
- case 'i': /* HP AV info file */
- ctx.hpav_info_path = optarg;
- break;
- case 'v': /* version number */
- fprintf (stdout, "%s\n", VERSION);
- return 0;
- default:
- print_usage (argv[0]);
- return 1;
- }
- }
-
- /* set the current PID to info file */
- sprintf (buffer, "%d", getpid ());
- if(LIBSPID_SUCCESS != libspid_config_write_item (ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_PLCD_PID, buffer))
- {
- syslog (LOG_WARNING, "write pid to %s failed", ctx.hpav_info_path);
- }
-
- /* initialize the AV stack and loopback until successful init */
- //while(0 > hpav_init (&ctx));
- if(hpav_init (&ctx) < 0)
- {
- syslog (LOG_WARNING, "plc init failed\n");
- return 1;
- }
-
- /* now get all events : DRV MMEs from plcdrv or config file
- changes (from managerd) */
- while (1)
- {
- event_process (&ctx);
- }
- //plcd_uninit(&ctx);
-
- return 0;
-}