Skip to content

Commit

Permalink
More on Feature Request #3031797
Browse files Browse the repository at this point in the history
  • Loading branch information
avpak committed Dec 24, 2010
1 parent f3dff0d commit f95b365
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 35 deletions.
6 changes: 5 additions & 1 deletion Makefile.mingw32
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ openhpi_libs := utils \
marshal \
baselib \
clients
# openhpid
# openhpid \
# plugins/slave

.PHONY: all clean $(openhpi_libs)

Expand All @@ -25,6 +26,7 @@ clean:
out: all
rm -rf ${out}
mkdir -p ${out}
# mkdir -p ${out}/plugins
cp README.windows ${out}
cat include/SaHpi.h | sed -e 's/ __attribute__.*/;/' -e 's/#define SAHPI_API/#define SAHPI_API __declspec(dllimport)/' > ${out}/SaHpi.h
cp include/oHpi.h ${out}
Expand All @@ -37,4 +39,6 @@ out: all
cp baselib/libopenhpi-${VERSION}.a ${out}/
cp baselib/libopenhpi-${VERSION}.def ${out}/
cp clients/*.exe ${out}/
# cp openhpid/openhpid.exe ${out}/
# cp plugins/slave/libslave.dll ${out}/plugins

5 changes: 1 addition & 4 deletions Makefile.mingw32.def
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ GTHREAD_LIBS := -L ${GLIB_DIR}/lib -lgthread-2.0
GMODULE_LIBS := -L ${GLIB_DIR}/lib -lgmodule-2.0
############################################################################

INCLUDES := -I ../include -I ../mingw32

CFLAGS := -DVERSION=\"${VERSION}\" -D_WIN32_WINNT=0x0501 ${INCLUDES}
CXXFLAGS := -DVERSION=\"${VERSION}\" -D_WIN32_WINNT=0x0501 ${INCLUDES}
CPPFLAGS := -DVERSION=\"${VERSION}\" -D_WIN32_WINNT=0x0501 -DOH_DBG_MSGS
LDFLAGS := -no-undefined --enable-runtime-pseudo-reloc

10 changes: 7 additions & 3 deletions baselib/Makefile.mingw32
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@ SRC := conf.c \

OBJ := $(patsubst %.c, %.o, $(patsubst %.cpp, %.o, ${SRC}))

INCLUDES := ${GLIB_INCLUDES} -I ../utils -I ../transport -I ../marshal
DEFS := -DG_LOG_DOMAIN=\"baselib\"
DEFS += -DSAHPI_API="__declspec(dllexport)"

INCLUDES := ${GLIB_INCLUDES}
INCLUDES += -I ../mingw32 -I ../include -I ../utils -I ../transport -I ../marshal

LIBS := ${GLIB_LIBS} ${GTHREAD_LIBS}
LIBS += -L ../utils -lopenhpiutils-${VERSION}
LIBS += -L ../transport -lopenhpitransport-${VERSION}
LIBS += -L ../marshal -lopenhpimarshal-${VERSION}

CXXFLAGS += ${INCLUDES} -DSAHPI_API="__declspec(dllexport)"
CFLAGS += ${INCLUDES} -DSAHPI_API="__declspec(dllexport)"
CPPFLAGS += ${DEFS} ${INCLUDES}

.PHONY: all clean

Expand Down
17 changes: 10 additions & 7 deletions clients/Makefile.mingw32
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,23 @@ TARGETS := hpialarms.exe \

OBJS := $(patsubst %.exe, %.o, ${TARGETS}) clients.o

INCLUDES := ${GLIB_INCLUDES} -I ../utils -I ../include
LIB_DIRS := ${GLIB_LIBS} -L ../baselib -L ../utils
LIB_DIRS += -L ../baselib -lopenhpi-${VERSION}
LIB_DIRS += -L ../utils -lopenhpiutils-${VERSION}
DEFS := -DG_LOG_DOMAIN=\"client\"
DEFS += -DSAHPI_API="__declspec(dllimport)"

CXXFLAGS += ${INCLUDES} -DSAHPI_API="__declspec(dllimport)"
CFLAGS += ${INCLUDES} -DSAHPI_API="__declspec(dllimport)"
INCLUDES := ${GLIB_INCLUDES} -I ../mingw32 -I ../include -I ../utils

LIBS := ${GLIB_LIBS}
LIBS += -L ../baselib -lopenhpi-${VERSION}
LIBS += -L ../utils -lopenhpiutils-${VERSION}

CPPFLAGS += ${DEFS} ${INCLUDES}

.PHONY: all clean

all : ${TARGETS}

%.exe : %.o clients.o
${CXX} -o $@ $^ ${LIB_DIRS}
${CXX} -o $@ $^ ${LIBS}

clean:
rm -f ${OBJS} ${TARGETS}
Expand Down
10 changes: 8 additions & 2 deletions marshal/Makefile.mingw32
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ SRC := marshal.c \

OBJ := $(patsubst %.c, %.o, ${SRC})

CFLAGS += ${GLIB_INCLUDES} -I ../utils
DEFS := -DG_LOG_DOMAIN=\"marshal\"

INCLUDES := ${GLIB_INCLUDES} -I ../mingw32 -I ../include -I ../utils

LIBS := ${GLIB_LIBS}

CPPFLAGS += ${DEFS} ${INCLUDES}

.PHONY: all clean

all : ${TARGET}

${TARGET} : ${OBJ}
${CC} -shared -o $@ $^ ${GLIB_LIBS}
${CC} -shared -o $@ $^ ${LIBS}

clean:
rm -f ${OBJ} ${TARGET}
Expand Down
20 changes: 11 additions & 9 deletions openhpid/Makefile.mingw32
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,24 @@ SRC := alarm.c \

OBJ := $(patsubst %.c, %.o,$(patsubst %.cpp, %.o, ${SRC} ) )

INCLUDES := ${GLIB_INCLUDES} -I ../utils -I ../transport -I ../marshal
LIB_DIRS := ${GLIB_LIBS} -L ../utils -L ../transport -L ../marshal
DEFS := -DG_LOG_DOMAIN=\"openhpid\"

CXXFLAGS += ${INCLUDES}
CFLAGS += ${INCLUDES}
INCLUDES := ${GLIB_INCLUDES}
INCLUDES += -I ../mingw32 -I ../include -I ../utils -I ../transport -I ../marshal

LIBS := ${GLIB_LIBS} ${GTHREAD_LIBS} ${GMODULE_LIBS}
LIBS += -L ../utils -lopenhpiutils-${VERSION}
LIBS += -L ../transport -lopenhpitransport-${VERSION}
LIBS += -L ../marshal -lopenhpimarshal-${VERSION}

CPPFLAGS += ${DEFS} ${INCLUDES}

.PHONY: all clean

all : ${TARGET}

${TARGET} : ${OBJ}
${CXX} -o $@ $^ ${LIB_DIRS} \
-lglib-2.0 -lgthread-2.0 -lgmodule-2.0 \
-lopenhpiutils-${VERSION} \
-lopenhpitransport-${VERSION} \
-lopenhpimarshal-${VERSION}
${CXX} -o $@ $^ ${LIBS}

clean:
rm -f ${OBJ} ${TARGET}
Expand Down
2 changes: 1 addition & 1 deletion openhpid/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ int oh_load_config (char *filename, struct oh_parsed_config *config)

g_scanner_destroy(oh_scanner);

DBG("Done processing conf file.\nNumber of parse errors:%d", done);
DBG("Done processing conf file. Parse errors: %d", done);

config->handler_configs = handler_configs;

Expand Down
182 changes: 180 additions & 2 deletions openhpid/openhpid-win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,202 @@
*
*/

#include <getopt.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>

#include <glib.h>

#include <oHpi.h>

#include <oh_error.h>

#include "init.h"
#include "server.h"


static bool daemonized = false;
static bool verbose_flag = false;


/*--------------------------------------------------------------------*/
/* Function: display_help */
/*--------------------------------------------------------------------*/

void display_help(void)
{
printf("Help for openhpid:\n\n");
printf(" openhpid -c conf_file [-v] [-p port]\n\n");
printf(" -c conf_file Sets path/name of the configuration file.\n");
printf(" This option is required unless the environment\n");
printf(" variable OPENHPI_CONF has been set to a valid\n");
printf(" configuration file.\n");
printf(" -v This option causes the daemon to display verbose\n");
printf(" messages. This option is optional.\n");
printf(" -p port Overrides the default listening port (%d) of\n",
OPENHPI_DEFAULT_DAEMON_PORT);
printf(" the daemon. The option is optional.\n");
printf(" -s seconds Overrides the default socket read timeout of 30\n");
printf(" minutes. The option is optional.\n");
printf(" -t threads Sets the maximum number of connection threads.\n");
printf(" The default is umlimited. The option is optional.\n");
printf(" -n Forces the code to run as a foreground process\n");
printf(" and NOT as a daemon. The default is to run as\n");
printf(" a daemon. The option is optional.\n\n");
printf("A typical invocation might be\n\n");
printf(" openhpid.exe -c C:\\openhpi.conf\n\n");
}


/*--------------------------------------------------------------------*/
/* Function: setenv */
/*--------------------------------------------------------------------*/

static int setenv(const char * var, const char * val)
{
static const size_t BUFSIZE = 1024;
char buf[BUFSIZE];
snprintf(buf, BUFSIZE, "%s=%s", var, val);
return _putenv(buf);
}


/*--------------------------------------------------------------------*/
/* Logging Utility Functions */
/*--------------------------------------------------------------------*/

static const char * get_log_level_name(GLogLevelFlags log_level)
{
if (log_level & G_LOG_LEVEL_ERROR) {
return "ERR";
} else if (log_level & G_LOG_LEVEL_CRITICAL) {
return "CRIT";
} else if (log_level & G_LOG_LEVEL_WARNING) {
return "WARN";
} else if (log_level & G_LOG_LEVEL_MESSAGE) {
return "MSG";
} else if (log_level & G_LOG_LEVEL_INFO) {
return "INFO";
} else if (log_level & G_LOG_LEVEL_DEBUG) {
return "DBG";
}
return "???";
}

void log_handler(const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer /*user_data */)
{
if ((!verbose_flag) && ((log_level & G_LOG_LEVEL_CRITICAL) == 0) ) {
return;
}
if (!daemonized) {
printf("%s: %s: %s\n",
log_domain,
get_log_level_name(log_level),
message);
} else {
// TODO implement
}
}


/*--------------------------------------------------------------------*/
/* Function: main */
/*--------------------------------------------------------------------*/

int main(int argc, char *argv[])
{
// TODO implement
printf( "Hello World\n" );
// TODO deamonization
g_log_set_default_handler(log_handler, 0);

struct option options[] = {
{"verbose", no_argument, 0, 'v'},
{"nondaemon", no_argument, 0, 'n'},
{"cfg", required_argument, 0, 'c'},
{"port", required_argument, 0, 'p'},
{"timeout", required_argument, 0, 's'},
{"threads", required_argument, 0, 't'},
{0, 0, 0, 0}
};

char *cfgfile = 0;
int port = OPENHPI_DEFAULT_DAEMON_PORT;
unsigned int sock_timeout = 0; // unlimited
int max_threads = -1; // unlimited
bool runasdaemon = true;

/* get the command line options */
int c;
while (1) {
c = getopt_long(argc, argv, "nvc:p:f:s:t:", options, 0);
/* detect when done scanning options */
if (c == -1) {
break;
}
switch (c) {
case 0:
/* no need to do anything here */
break;
case 'c':
setenv("OPENHPI_CONF", optarg);
cfgfile = g_strdup(optarg);
break;
case 'p':
setenv("OPENHPI_DAEMON_PORT", optarg);
port = atoi(optarg);
break;
case 'v':
verbose_flag = true;
break;
case 's':
sock_timeout = atoi(optarg);
break;
case 't':
max_threads = atoi(optarg);
if (max_threads <= 0) {
max_threads = -1;
}
break;
case 'n':
runasdaemon = false;
break;
case '?':
default:
/* they obviously need it */
display_help();
exit(-1);
}
}
if (optind < argc) {
CRIT("Unknown command line option specified. Exiting.");
display_help();
exit(-1);
}

// see if we have a valid configuration file
if ((!cfgfile) || (!g_file_test(cfgfile, G_FILE_TEST_EXISTS))) {
CRIT("Cannot find configuration file. Exiting.");
display_help();
exit(-1);
}

if (oh_init()) { // Initialize OpenHPI
CRIT("There was an error initializing OpenHPI. Exiting.");
return 8;
}

// announce ourselves
INFO("%s version %s started.", argv[0], VERSION);
INFO("OPENHPI_CONF = %s.", cfgfile);
INFO("OPENHPI_DAEMON_PORT = %u.", port);

bool rc = oh_server_run(port, sock_timeout, max_threads);
if (!rc) {
return 9;
}

return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/slave/handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ bool cHandler::Init()
bool cHandler::WaitForDiscovery()
{
while ( m_startup_discovery_status == StartupDiscoveryUncompleted ) {
usleep( (useconds_t)( DiscoveryStatusCheckInterval / 1000ULL ) );
g_usleep( (gulong)( DiscoveryStatusCheckInterval / 1000ULL ) );
}

return ( m_startup_discovery_status == StartupDiscoveryDone );
Expand Down Expand Up @@ -188,7 +188,7 @@ void cHandler::ThreadProc()
}
}
if ( !m_stop ) {
usleep( (useconds_t)( OpenSessionRetryInterval / 1000ULL ) );
g_usleep( (gulong)( OpenSessionRetryInterval / 1000ULL ) );
}
}
}
Expand Down
Loading

0 comments on commit f95b365

Please sign in to comment.