Date   

[PATCH 05/30] Moved platform.c to linux/platform.c

Michael Schonberg <mschonberg@...>
 

The funcitons for accessing shared libraries in platform.c are os
dependent. This is in prepration for windows support.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/linux/platform.c | 85 +++++++++++++++++++++++++++++++++++
common/c_cpp/src/c/platform.c | 85 -----------------------------------
3 files changed, 86 insertions(+), 85 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/platform.c
delete mode 100644 common/c_cpp/src/c/platform.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index 31e78fc..dfd450b 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -48,6 +48,7 @@ AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
src/c/machine_port.c:src/c/linux/machine.c
+ src/c/platform.c:src/c/linux/platform.c
src/c/environment.c:src/c/linux/environment.c]) ;;
esac

diff --git a/common/c_cpp/src/c/linux/platform.c b/common/c_cpp/src/c/linux/platform.c
new file mode 100644
index 0000000..8bf7f4e
--- /dev/null
+++ b/common/c_cpp/src/c/linux/platform.c
@@ -0,0 +1,85 @@
+/* $Id: platform.c,v 1.8.16.2 2011/08/10 14:53:24 nicholasmarriott Exp $
+ *
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "port.h"
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stddef.h>
+
+#include "platform.h"
+#include "wombat/wincompat.h"
+
+/**
+ * Functions relating to DLLs/shared objects
+ */
+char errorBuf[25];
+LIB_HANDLE openSharedLib (const char* libName, const char* path)
+{
+ size_t nameLength;
+ char* fileName;
+ LIB_HANDLE handle;
+
+ if (path)
+ {
+ nameLength = strlen(path) + strlen(libName) + strlen(LIB_EXTENSION) +
+ strlen(PATHSEP) + strlen("lib") + 1;
+ }
+ else
+ {
+ nameLength = strlen(libName) + strlen(LIB_EXTENSION) + strlen("lib") + 1;
+ }
+ fileName = (char*) calloc (nameLength, sizeof (char));
+ if(fileName == NULL)
+ {
+ return 0;
+ }
+
+ if (path)
+ {
+ snprintf (fileName, nameLength, "%s%slib%s%s", path, PATHSEP, libName, LIB_EXTENSION);
+ }
+ else
+ {
+ snprintf (fileName, nameLength, "lib%s%s", libName, LIB_EXTENSION);
+ }
+
+ handle = dlopen (fileName, RTLD_NOW | RTLD_GLOBAL);
+
+ free(fileName);
+ return handle;
+}
+
+
+int closeSharedLib (LIB_HANDLE handle)
+{
+ return dlclose (handle);
+}
+
+void* loadLibFunc (LIB_HANDLE handle, const char* funcName)
+{
+ return dlsym (handle, funcName);
+}
+
+char* getLibError (void)
+{
+ return dlerror();
+}
diff --git a/common/c_cpp/src/c/platform.c b/common/c_cpp/src/c/platform.c
deleted file mode 100644
index 8bf7f4e..0000000
--- a/common/c_cpp/src/c/platform.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/* $Id: platform.c,v 1.8.16.2 2011/08/10 14:53:24 nicholasmarriott Exp $
- *
- * OpenMAMA: The open middleware agnostic messaging API
- * Copyright (C) 2011 NYSE Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-#include "port.h"
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stddef.h>
-
-#include "platform.h"
-#include "wombat/wincompat.h"
-
-/**
- * Functions relating to DLLs/shared objects
- */
-char errorBuf[25];
-LIB_HANDLE openSharedLib (const char* libName, const char* path)
-{
- size_t nameLength;
- char* fileName;
- LIB_HANDLE handle;
-
- if (path)
- {
- nameLength = strlen(path) + strlen(libName) + strlen(LIB_EXTENSION) +
- strlen(PATHSEP) + strlen("lib") + 1;
- }
- else
- {
- nameLength = strlen(libName) + strlen(LIB_EXTENSION) + strlen("lib") + 1;
- }
- fileName = (char*) calloc (nameLength, sizeof (char));
- if(fileName == NULL)
- {
- return 0;
- }
-
- if (path)
- {
- snprintf (fileName, nameLength, "%s%slib%s%s", path, PATHSEP, libName, LIB_EXTENSION);
- }
- else
- {
- snprintf (fileName, nameLength, "lib%s%s", libName, LIB_EXTENSION);
- }
-
- handle = dlopen (fileName, RTLD_NOW | RTLD_GLOBAL);
-
- free(fileName);
- return handle;
-}
-
-
-int closeSharedLib (LIB_HANDLE handle)
-{
- return dlclose (handle);
-}
-
-void* loadLibFunc (LIB_HANDLE handle, const char* funcName)
-{
- return dlsym (handle, funcName);
-}
-
-char* getLibError (void)
-{
- return dlerror();
-}
--
1.7.7.6


[PATCH 04/30] Moved linux code from machine.c to linux/machine.c

Michael Schonberg <mschonberg@...>
 

In preparation for windows support, machine.c contains generic code while
Linux specific code is now in linux/machine.c

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 1 +
common/c_cpp/src/c/Makefile.am | 1 +
common/c_cpp/src/c/linux/machine.c | 599 ++++++++++++++++++++++++++++++++++++
common/c_cpp/src/c/machine.c | 566 +---------------------------------
4 files changed, 603 insertions(+), 564 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/machine.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index b6f537a..31e78fc 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -47,6 +47,7 @@ AC_CANONICAL_BUILD()
AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
+ src/c/machine_port.c:src/c/linux/machine.c
src/c/environment.c:src/c/linux/environment.c]) ;;
esac

diff --git a/common/c_cpp/src/c/Makefile.am b/common/c_cpp/src/c/Makefile.am
index facce7c..362d457 100644
--- a/common/c_cpp/src/c/Makefile.am
+++ b/common/c_cpp/src/c/Makefile.am
@@ -66,6 +66,7 @@ libwombatcommon_la_SOURCES = \
list.c \
lookup2.c \
machine.c \
+ machine_port.c \
platform.c \
properties.l \
property.c \
diff --git a/common/c_cpp/src/c/linux/machine.c b/common/c_cpp/src/c/linux/machine.c
new file mode 100644
index 0000000..375734c
--- /dev/null
+++ b/common/c_cpp/src/c/linux/machine.c
@@ -0,0 +1,599 @@
+/* $Id: machine.c,v 1.50.16.9 2011/08/10 14:53:24 nicholasmarriott Exp $
+ *
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#include "port.h"
+#include <sys/stat.h>
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "wombat/machine.h"
+#include "wombat/wtable.h"
+
+/* Macros for extract VSIZE and RSS from /proc/pid/stats files */
+#define bytetok(x) (((x) + 512) >> 10)
+
+#define MAXPROCSARRAY 1000 /* need to keep track of processes */
+
+extern int useLWP;
+static int numProc = 0;
+static pid_t procTable[MAXPROCSARRAY];
+static int flagTable[MAXPROCSARRAY];
+
+static char* skip_ws (char* p);
+static char* skip_token (char* p);
+static int uniqueSet (int lhs, int rhs);
+static int isInSet (int lhs, int rhs, int pid);
+void searchDirs (int procChildren[],
+ int dirNames[],
+ int count,
+ cpuVals* cpv,
+ int tempPid);
+pid_t getParentPid (pid_t pid,
+ int childFlag);
+
+time_t getTimeSinceEpoch(void)
+{
+ struct timeval tv;
+ gettimeofday(&tv,NULL);
+ return tv.tv_sec;
+}
+
+static char* skip_ws(char* p)
+{
+ while (isspace(*p))
+ p++;
+ return p;
+}
+
+static char* skip_token(char* p)
+{
+ while (isspace(*p))
+ p++;
+ while (*p && !isspace(*p))
+ p++;
+ return p;
+}
+
+void getProcAndChildCpu(int pid, cpuVals* cpv)
+{
+ int i=0;
+ struct cpuVals tempCpu;
+ tempCpu.userTime=0;
+ tempCpu.sysTime=0;
+ cpv->userTime=0;
+ cpv->sysTime=0;
+ for(i = 0; i < numProc; i++)
+ {
+ getProcessInfo(procTable[i],NULL,&tempCpu,flagTable[i]);
+ cpv->userTime += tempCpu.userTime;
+ cpv->sysTime += tempCpu.sysTime;
+ }
+}
+
+int getNumCpu(void)
+{
+ return sysconf (_SC_NPROCESSORS_ONLN);
+}
+
+void initProcTable(int pid, int debuginfo)
+{
+ DIR *dir = NULL;
+ char buffer[4096] = "";
+ struct dirent *ent = NULL;
+ pid_t allPpidTable[MAXPROCSARRAY];
+ pid_t allProcTable[MAXPROCSARRAY];
+ int allFlagTable[MAXPROCSARRAY];
+ pid_t tempPid = 0;
+ int numAllProc = 0;
+ int childFlag = 0;
+ int i = 0;
+ int currentIndex = 0;
+ int childrenIndex = 0;
+ pid_t pgrp = 0;
+ char *dirNamePtr = NULL;
+
+ /* Trying to find all child process by using ppid and pid relationship.*/
+ dir = opendir("/proc/");
+ while ((ent = readdir(dir)) != NULL)
+ {
+ dirNamePtr = ent->d_name;
+ if (ent->d_name[0] == '.')
+ {
+ dirNamePtr += 1;
+ childFlag = 1;
+ }
+ if (isdigit(dirNamePtr[0]))
+ {
+ tempPid=(pid_t)strtol(dirNamePtr,NULL,10);
+
+ if(tempPid!=pid)
+ {
+ allPpidTable[numAllProc] = getParentPid(tempPid,childFlag);
+ if (allPpidTable[numAllProc] == 0)
+ {
+ /* process must have exited, do not store information reg
+ this pid */
+ continue;
+ }
+ allProcTable[numAllProc] = tempPid;
+ allFlagTable[numAllProc] = childFlag;
+ numAllProc++;
+
+ }
+ }
+ childFlag = 0;
+ }
+ closedir(dir);
+
+ procTable[0]=pid;
+ flagTable[0]=0;
+ numProc=1;
+ while(1)
+ {
+ for(i=0;i<numAllProc;i++)
+ {
+ if(allPpidTable[i]==procTable[currentIndex])
+ {
+ childrenIndex++;
+ procTable[childrenIndex]=allProcTable[i];
+ flagTable[childrenIndex]=allFlagTable[i];
+ numProc++;
+ }
+ }
+ if(currentIndex==childrenIndex)
+ {
+ break;
+ }
+ currentIndex++;
+ }
+
+
+ /* Trying to find all child processes by using group pid. */
+ dir = opendir("/proc/");
+ while ((ent = readdir(dir)) != NULL)
+ {
+ /* get pgrp related processes*/
+ dirNamePtr = ent->d_name;
+ childFlag = 0;
+ if (ent->d_name[0] == '.')
+ {
+ dirNamePtr += 1;
+ childFlag = 1;
+ }
+ if (isdigit(dirNamePtr[0]))
+ {
+ tempPid=(int) strtol(dirNamePtr,NULL,10);
+ if (tempPid==pid)
+ continue;
+ pgrp = getpgid (tempPid);
+ if (pgrp == pid)
+ {
+ procTable[numProc]=tempPid;
+ flagTable[numProc]=childFlag;
+ numProc++;
+ }
+ }
+ }
+ closedir(dir);
+
+ /* Trying to find all child processes via LWP on 64 bit */
+ if (useLWP)
+ {
+ sprintf(buffer, "/proc/%d/task", pid);
+ dir = opendir(buffer);
+ if (dir != NULL)
+ {
+ while ((ent = readdir(dir)) != NULL)
+ {
+ dirNamePtr = ent->d_name;
+ childFlag = 0;
+ if (isdigit(dirNamePtr[0]))
+ {
+ tempPid=(int) strtol(dirNamePtr,NULL,10);
+ if (tempPid==pid)
+ continue;
+ procTable[numProc]=tempPid;
+ flagTable[numProc]=childFlag;
+ numProc++;
+ }
+ }
+ closedir(dir);
+ }
+ }
+
+ /* On some linux kernels only one of above methods works. On other kernel
+ * versons both work. So we need to remove duplicated entries
+ */
+
+ numProc = uniqueSet (0, numProc);
+
+ if(debuginfo)
+ {
+ printf("Debug Info for Stats - Processes Table\n");
+ for(i=0;i<numProc;i++)
+ {
+ printf("%d-%d\n",procTable[i],flagTable[i]);
+ }
+ }
+}
+
+/* Take out duplicated entries. So the result is a unique set of pids.*/
+static int uniqueSet (int lhs, int rhs)
+{
+ int curProc = procTable[lhs];
+ int dup = 0;
+
+ if (lhs == rhs - 1)
+ {
+ if (procTable [lhs] == procTable [rhs])
+ return lhs;
+ else
+ return rhs;
+ }
+ rhs = uniqueSet (lhs + 1, rhs);
+ dup = isInSet (lhs + 1, rhs, curProc);
+ if (dup != -1)
+ {
+ procTable[dup] = procTable[rhs];
+ flagTable[dup] = flagTable[rhs];
+ rhs --;
+ }
+ return rhs;
+}
+
+static int isInSet (int lhs, int rhs, int pid)
+{
+ int i = 0;
+ for (i = lhs; i <= rhs; i++)
+ {
+ if (pid == procTable[i])
+ return i;
+ }
+ return -1;
+}
+
+pid_t getParentPid(pid_t pid, int childFlag)
+{
+ char buffer[4096], *p, *q;
+ int state =0;
+ pid_t ppid=0;
+ char name[64];
+ int len = 0;
+ /* grab the proc stat info in one go */
+ {
+ int fd, len;
+ if(childFlag==1)
+ sprintf(buffer, "/proc/.%d/stat", pid);
+ else
+ sprintf(buffer, "/proc/%d/stat", pid);
+
+ fd = open(buffer, 0);
+
+ if (fd==-1)
+ {
+ return 0;
+ }
+
+ len = read(fd, buffer, sizeof(buffer)-1);
+ close(fd);
+ if (len==-1)
+ {
+ return 0;
+ }
+ buffer[len] = '\0';
+ }
+ /* parse out the status */
+ p = buffer;
+ p = strchr(p, '('); /* skip pid */
+ if (p==NULL)
+ {
+ /* Process has exited since the pid was initially obtained */
+ return 0;
+ }
+ {
+ ++p; /* increment past the '(' char */
+ q = strrchr(p, ')'); /*process name*/
+ len = q-p;
+ if (len >= sizeof(name))
+ len = sizeof(name)-1;
+ memcpy(name, p, len);
+ name[len] = 0;
+ p = q+1;
+ }
+ p = skip_ws(p);
+ switch (*p++)
+ {
+ case 'R': state = 1; break;
+ case 'S': state = 2; break;
+ case 'D': state = 3; break;
+ case 'Z': state = 4; break;
+ case 'T': state = 5; break;
+ case 'W': state = 6; break;
+ }
+ ppid = (pid_t)strtol(p,&p,10); /* skip ppid */
+ return ppid;
+}
+
+void searchDirs(int procChildren[], int dirNames[],
+ int count,cpuVals *cpv,int tempPid)
+{
+ int x=0,ppid=0;
+ struct cpuVals tempCpu;
+ for(x = 0; x < count; x++)
+ {
+ ppid = getProcessInfo(dirNames[x],NULL,&tempCpu,procChildren[x]);
+ if(ppid==tempPid)
+ {
+ cpv->userTime += tempCpu.userTime;
+ cpv->sysTime += tempCpu.sysTime;
+ searchDirs(procChildren,dirNames,count,cpv,dirNames[x]);
+ }
+ else
+ {
+ tempCpu.userTime=0;
+ tempCpu.sysTime=0;
+ }
+ }
+}
+
+static long pagetok(long x)
+{
+ /*
+ * This replaces:
+ *
+ * #include <asm/page.h>
+ *
+ * #define pagetok(x) ((x) << (PAGE_SHIFT - 10))
+ *
+ * which is deprecated according to RedHat
+ */
+ static int initDone = 0;
+ static int pageShift = 0;
+
+ if (!initDone) {
+ int pgSize = sysconf(_SC_PAGESIZE);
+
+ /* We have to calc the power-of-2 that the page size represents */
+ for (pageShift = 0; !(pgSize & 0x01); pageShift++, pgSize >>= 1)
+ ;
+
+ /* Convert to 1K units */
+ pageShift -= 10;
+ initDone = 1;
+ }
+ return (x << pageShift);
+}
+
+int getProcessInfo(int pid ,memVals *memV,cpuVals *cpuV,int childFlag)
+{
+ char buffer[4096], *p;
+ int state =0;
+ int ppid=0;
+ long totalMem = getTotalSystemMem();
+ double cpuClockTicksPerSecond = (double)sysconf(_SC_CLK_TCK);
+ /* grab the proc stat info in one go */
+ {
+ int fd, len;
+ if(childFlag==1)
+ sprintf(buffer, "/proc/.%d/stat", pid);
+ else
+ sprintf(buffer, "/proc/%d/stat", pid);
+
+ fd = open(buffer, 0);
+ if (fd == -1)
+ {
+ if (cpuV)
+ {
+ cpuV->userTime = 0;
+ cpuV->sysTime = 0;
+ }
+ if(memV)
+ {
+ memV->vsize = 0;
+ memV->rss = 0;
+ memV->memPercent = 0;
+ }
+ return 0;
+ }
+ len = read(fd, buffer, sizeof(buffer)-1);
+ close(fd);
+ buffer[len] = '\0';
+ }
+ /* parse out the status */
+ p = buffer;
+ p = strchr(p, '(')+1; /* skip pid */
+ {
+ char name[64];
+ char *q = strrchr(p, ')'); /*process name*/
+ int len = q-p;
+ if (len >= sizeof(name))
+ len = sizeof(name)-1;
+ memcpy(name, p, len);
+ name[len] = 0;
+ p = q+1;
+ }
+ p = skip_ws(p);
+ switch (*p++)
+ {
+ case 'R': state = 1; break;
+ case 'S': state = 2; break;
+ case 'D': state = 3; break;
+ case 'Z': state = 4; break;
+ case 'T': state = 5; break;
+ case 'W': state = 6; break;
+ }
+
+ ppid = (int)strtol(p,&p,10); /* skip ppid */
+ p = skip_token(p); /* skip pgrp */
+ p = skip_token(p); /* skip session */
+ p = skip_token(p); /* skip tty */
+ p = skip_token(p); /* skip tty pgrp */
+ p = skip_token(p); /* skip flags */
+ p = skip_token(p); /* skip min flt */
+ p = skip_token(p); /* skip cmin flt */
+ p = skip_token(p); /* skip maj flt */
+ p = skip_token(p); /* skip cmaj flt */
+ if(cpuV)
+ {
+ cpuV->userTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* utime */
+ cpuV->sysTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* stime */
+ }
+ else
+ {
+ p = skip_token(p); /* skip utime */
+ p = skip_token(p); /* skip stime */
+ }
+ p = skip_token(p); /* skip cutime */
+ p = skip_token(p); /* skip cstime */
+
+ p = skip_token(p); /* skip priority */
+ p = skip_token(p); /* skip nice */
+
+ p = skip_token(p); /* skip timeout */
+ p = skip_token(p); /* skip it_real_val */
+ p = skip_token(p); /* skip start_time */
+
+ if(memV)
+ {
+ memV->vsize = bytetok(strtoul(p, &p, 10)); /* vsize */
+ memV->rss = pagetok(strtoul(p, &p, 10)); /* rss */
+ memV->memPercent =(double)(memV->rss*100.0)/(double)totalMem;
+ }
+
+ return ppid;
+}
+
+int getSystemMemory (systemMemVals* mem)
+{
+ FILE* fp;
+ char buffer[4096];
+ size_t bytes_read;
+ char* match;
+ long totalMem=-1,freeMem=-1,totalSwap=-1,freeSwap=-1;
+
+ fp = fopen ("/proc/meminfo","r");
+ if (fp==NULL)
+ return -1;
+ bytes_read = fread(buffer, 1, sizeof (buffer), fp);
+ fclose(fp);
+
+ if (bytes_read==0 || bytes_read == sizeof (buffer))
+ return -1;
+ buffer[bytes_read] = '\0';
+
+ match = strstr (buffer, "MemTotal:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "MemTotal:%ld", &totalMem);
+ match = strstr (buffer, "MemFree:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "MemFree:%ld", &freeMem);
+ match = strstr (buffer, "SwapTotal:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "SwapTotal:%ld", &totalSwap);
+ match = strstr (buffer, "SwapFree:");
+ if (match == NULL)
+ return -1;
+ sscanf (match, "SwapFree:%ld", &freeSwap);
+
+ mem->totalMem=totalMem;
+ mem->freeMem=freeMem;
+ mem->totalSwap=totalSwap;
+ mem->freeSwap=freeSwap;
+ return 0;
+}
+
+long getTotalSystemMem(void)
+{
+ /* get system wide memory usage */
+ FILE* fp;
+ char buffer[4096];
+ size_t bytes_read;
+ char* match;
+ long totalMem=-1;
+
+ fp = fopen ("/proc/meminfo","r");
+ if (fp==NULL)
+ return totalMem;
+ bytes_read = fread(buffer, 1, sizeof (buffer), fp);
+ fclose(fp);
+
+ if (bytes_read==0 || bytes_read == sizeof (buffer))
+ return totalMem;
+ buffer[bytes_read] = '\0';
+
+ match = strstr (buffer, "MemTotal:");
+ if (match == NULL)
+ return totalMem;
+
+ sscanf (match, "MemTotal:%ld", &totalMem);
+ return totalMem;
+}
+
+void getSystemTime(double* upTime,double* idleTime)
+{
+ FILE* fp;
+ *upTime = 0;
+ *idleTime = 0;
+ fp = fopen("/proc/uptime", "r");
+ if (fp==NULL)
+ return;
+ fscanf (fp, "%lf %lf\n", upTime, idleTime);
+ fclose (fp);
+}
+
+void getProcessorTime(long* usageTime,long* idleTime,int processor)
+{
+ FILE* fp;
+ char buffer[4096];
+ char cpu[10];
+ size_t bytes_read;
+ char* match;
+ long user_read, system_read, nice_read, idle_read;
+ *usageTime = 0;
+ *idleTime = 0;
+
+ fp = fopen ("/proc/stat","r");
+ if (fp==NULL)
+ return;
+ bytes_read = fread(buffer, 1, sizeof (buffer), fp);
+ fclose(fp);
+ if (bytes_read==0 || bytes_read == sizeof (buffer))
+ return;
+ buffer[bytes_read] = '\0';
+ sprintf(cpu,"cpu%d ",processor);
+ match = strstr (buffer, cpu);
+ if (match == NULL)
+ return;
+ sscanf(match, "%*s %ld %ld %ld %ld", &user_read,&system_read,&nice_read,&idle_read);
+ *usageTime = user_read + system_read + nice_read;
+ *idleTime = idle_read;
+}
diff --git a/common/c_cpp/src/c/machine.c b/common/c_cpp/src/c/machine.c
index 512e1ab..fc43143 100644
--- a/common/c_cpp/src/c/machine.c
+++ b/common/c_cpp/src/c/machine.c
@@ -1,5 +1,4 @@
-/* $Id: machine.c,v 1.50.16.9 2011/08/10 14:53:24 nicholasmarriott Exp $
- *
+/*
* OpenMAMA: The open middleware agnostic messaging API
* Copyright (C) 2011 NYSE Inc.
*
@@ -35,28 +34,7 @@
#include "wombat/machine.h"
#include "wombat/wtable.h"

-static int useLWP = 1;
-
-/* Macros for extract VSIZE and RSS from /proc/pid/stats files */
-#define bytetok(x) (((x) + 512) >> 10)
-
-#define MAXPROCSARRAY 1000 /* need to keep track of processes */
-
-static int numProc = 0;
-static pid_t procTable[MAXPROCSARRAY];
-static int flagTable[MAXPROCSARRAY];
-
-static char* skip_ws (char* p);
-static char* skip_token (char* p);
-static int uniqueSet (int lhs, int rhs);
-static int isInSet (int lhs, int rhs, int pid);
-void searchDirs (int procChildren[],
- int dirNames[],
- int count,
- cpuVals* cpv,
- int tempPid);
-pid_t getParentPid (pid_t pid,
- int childFlag);
+int useLWP = 1;

void enableLWP(void)
{
@@ -76,543 +54,3 @@ void getMemVals(int pid, memVals *memV)
getProcessInfo(pid,memV,NULL,0);
}

-time_t getTimeSinceEpoch(void)
-{
- struct timeval tv;
- gettimeofday(&tv,NULL);
- return tv.tv_sec;
-}
-
-static char* skip_ws(char* p)
-{
- while (isspace(*p))
- p++;
- return p;
-}
-
-static char* skip_token(char* p)
-{
- while (isspace(*p))
- p++;
- while (*p && !isspace(*p))
- p++;
- return p;
-}
-
-void getProcAndChildCpu(int pid, cpuVals* cpv)
-{
- int i=0;
- struct cpuVals tempCpu;
- tempCpu.userTime=0;
- tempCpu.sysTime=0;
- cpv->userTime=0;
- cpv->sysTime=0;
- for(i = 0; i < numProc; i++)
- {
- getProcessInfo(procTable[i],NULL,&tempCpu,flagTable[i]);
- cpv->userTime += tempCpu.userTime;
- cpv->sysTime += tempCpu.sysTime;
- }
-}
-
-int getNumCpu(void)
-{
- return sysconf (_SC_NPROCESSORS_ONLN);
-}
-
-void initProcTable(int pid, int debuginfo)
-{
- DIR *dir = NULL;
- char buffer[4096] = "";
- struct dirent *ent = NULL;
- pid_t allPpidTable[MAXPROCSARRAY];
- pid_t allProcTable[MAXPROCSARRAY];
- int allFlagTable[MAXPROCSARRAY];
- pid_t tempPid = 0;
- int numAllProc = 0;
- int childFlag = 0;
- int i = 0;
- int currentIndex = 0;
- int childrenIndex = 0;
- pid_t pgrp = 0;
- char *dirNamePtr = NULL;
-
- /* Trying to find all child process by using ppid and pid relationship.*/
- dir = opendir("/proc/");
- while ((ent = readdir(dir)) != NULL)
- {
- dirNamePtr = ent->d_name;
- if (ent->d_name[0] == '.')
- {
- dirNamePtr += 1;
- childFlag = 1;
- }
- if (isdigit(dirNamePtr[0]))
- {
- tempPid=(pid_t)strtol(dirNamePtr,NULL,10);
-
- if(tempPid!=pid)
- {
- allPpidTable[numAllProc] = getParentPid(tempPid,childFlag);
- if (allPpidTable[numAllProc] == 0)
- {
- /* process must have exited, do not store information reg
- this pid */
- continue;
- }
- allProcTable[numAllProc] = tempPid;
- allFlagTable[numAllProc] = childFlag;
- numAllProc++;
-
- }
- }
- childFlag = 0;
- }
- closedir(dir);
-
- procTable[0]=pid;
- flagTable[0]=0;
- numProc=1;
- while(1)
- {
- for(i=0;i<numAllProc;i++)
- {
- if(allPpidTable[i]==procTable[currentIndex])
- {
- childrenIndex++;
- procTable[childrenIndex]=allProcTable[i];
- flagTable[childrenIndex]=allFlagTable[i];
- numProc++;
- }
- }
- if(currentIndex==childrenIndex)
- {
- break;
- }
- currentIndex++;
- }
-
-
- /* Trying to find all child processes by using group pid. */
- dir = opendir("/proc/");
- while ((ent = readdir(dir)) != NULL)
- {
- /* get pgrp related processes*/
- dirNamePtr = ent->d_name;
- childFlag = 0;
- if (ent->d_name[0] == '.')
- {
- dirNamePtr += 1;
- childFlag = 1;
- }
- if (isdigit(dirNamePtr[0]))
- {
- tempPid=(int) strtol(dirNamePtr,NULL,10);
- if (tempPid==pid)
- continue;
- pgrp = getpgid (tempPid);
- if (pgrp == pid)
- {
- procTable[numProc]=tempPid;
- flagTable[numProc]=childFlag;
- numProc++;
- }
- }
- }
- closedir(dir);
-
- /* Trying to find all child processes via LWP on 64 bit */
- if (useLWP)
- {
- sprintf(buffer, "/proc/%d/task", pid);
- dir = opendir(buffer);
- if (dir != NULL)
- {
- while ((ent = readdir(dir)) != NULL)
- {
- dirNamePtr = ent->d_name;
- childFlag = 0;
- if (isdigit(dirNamePtr[0]))
- {
- tempPid=(int) strtol(dirNamePtr,NULL,10);
- if (tempPid==pid)
- continue;
- procTable[numProc]=tempPid;
- flagTable[numProc]=childFlag;
- numProc++;
- }
- }
- closedir(dir);
- }
- }
-
- /* On some linux kernels only one of above methods works. On other kernel
- * versons both work. So we need to remove duplicated entries
- */
-
- numProc = uniqueSet (0, numProc);
-
- if(debuginfo)
- {
- printf("Debug Info for Stats - Processes Table\n");
- for(i=0;i<numProc;i++)
- {
- printf("%d-%d\n",procTable[i],flagTable[i]);
- }
- }
-}
-
-/* Take out duplicated entries. So the result is a unique set of pids.*/
-static int uniqueSet (int lhs, int rhs)
-{
- int curProc = procTable[lhs];
- int dup = 0;
-
- if (lhs == rhs - 1)
- {
- if (procTable [lhs] == procTable [rhs])
- return lhs;
- else
- return rhs;
- }
- rhs = uniqueSet (lhs + 1, rhs);
- dup = isInSet (lhs + 1, rhs, curProc);
- if (dup != -1)
- {
- procTable[dup] = procTable[rhs];
- flagTable[dup] = flagTable[rhs];
- rhs --;
- }
- return rhs;
-}
-
-static int isInSet (int lhs, int rhs, int pid)
-{
- int i = 0;
- for (i = lhs; i <= rhs; i++)
- {
- if (pid == procTable[i])
- return i;
- }
- return -1;
-}
-
-pid_t getParentPid(pid_t pid, int childFlag)
-{
- char buffer[4096], *p, *q;
- int state =0;
- pid_t ppid=0;
- char name[64];
- int len = 0;
- /* grab the proc stat info in one go */
- {
- int fd, len;
- if(childFlag==1)
- sprintf(buffer, "/proc/.%d/stat", pid);
- else
- sprintf(buffer, "/proc/%d/stat", pid);
-
- fd = open(buffer, 0);
-
- if (fd==-1)
- {
- return 0;
- }
-
- len = read(fd, buffer, sizeof(buffer)-1);
- close(fd);
- if (len==-1)
- {
- return 0;
- }
- buffer[len] = '\0';
- }
- /* parse out the status */
- p = buffer;
- p = strchr(p, '('); /* skip pid */
- if (p==NULL)
- {
- /* Process has exited since the pid was initially obtained */
- return 0;
- }
- {
- ++p; /* increment past the '(' char */
- q = strrchr(p, ')'); /*process name*/
- len = q-p;
- if (len >= sizeof(name))
- len = sizeof(name)-1;
- memcpy(name, p, len);
- name[len] = 0;
- p = q+1;
- }
- p = skip_ws(p);
- switch (*p++)
- {
- case 'R': state = 1; break;
- case 'S': state = 2; break;
- case 'D': state = 3; break;
- case 'Z': state = 4; break;
- case 'T': state = 5; break;
- case 'W': state = 6; break;
- }
- ppid = (pid_t)strtol(p,&p,10); /* skip ppid */
- return ppid;
-}
-
-void searchDirs(int procChildren[], int dirNames[],
- int count,cpuVals *cpv,int tempPid)
-{
- int x=0,ppid=0;
- struct cpuVals tempCpu;
- for(x = 0; x < count; x++)
- {
- ppid = getProcessInfo(dirNames[x],NULL,&tempCpu,procChildren[x]);
- if(ppid==tempPid)
- {
- cpv->userTime += tempCpu.userTime;
- cpv->sysTime += tempCpu.sysTime;
- searchDirs(procChildren,dirNames,count,cpv,dirNames[x]);
- }
- else
- {
- tempCpu.userTime=0;
- tempCpu.sysTime=0;
- }
- }
-}
-
-static long pagetok(long x)
-{
- /*
- * This replaces:
- *
- * #include <asm/page.h>
- *
- * #define pagetok(x) ((x) << (PAGE_SHIFT - 10))
- *
- * which is deprecated according to RedHat
- */
- static int initDone = 0;
- static int pageShift = 0;
-
- if (!initDone) {
- int pgSize = sysconf(_SC_PAGESIZE);
-
- /* We have to calc the power-of-2 that the page size represents */
- for (pageShift = 0; !(pgSize & 0x01); pageShift++, pgSize >>= 1)
- ;
-
- /* Convert to 1K units */
- pageShift -= 10;
- initDone = 1;
- }
- return (x << pageShift);
-}
-
-int getProcessInfo(int pid ,memVals *memV,cpuVals *cpuV,int childFlag)
-{
- char buffer[4096], *p;
- int state =0;
- int ppid=0;
- long totalMem = getTotalSystemMem();
- double cpuClockTicksPerSecond = (double)sysconf(_SC_CLK_TCK);
- /* grab the proc stat info in one go */
- {
- int fd, len;
- if(childFlag==1)
- sprintf(buffer, "/proc/.%d/stat", pid);
- else
- sprintf(buffer, "/proc/%d/stat", pid);
-
- fd = open(buffer, 0);
- if (fd == -1)
- {
- if (cpuV)
- {
- cpuV->userTime = 0;
- cpuV->sysTime = 0;
- }
- if(memV)
- {
- memV->vsize = 0;
- memV->rss = 0;
- memV->memPercent = 0;
- }
- return 0;
- }
- len = read(fd, buffer, sizeof(buffer)-1);
- close(fd);
- buffer[len] = '\0';
- }
- /* parse out the status */
- p = buffer;
- p = strchr(p, '(')+1; /* skip pid */
- {
- char name[64];
- char *q = strrchr(p, ')'); /*process name*/
- int len = q-p;
- if (len >= sizeof(name))
- len = sizeof(name)-1;
- memcpy(name, p, len);
- name[len] = 0;
- p = q+1;
- }
- p = skip_ws(p);
- switch (*p++)
- {
- case 'R': state = 1; break;
- case 'S': state = 2; break;
- case 'D': state = 3; break;
- case 'Z': state = 4; break;
- case 'T': state = 5; break;
- case 'W': state = 6; break;
- }
-
- ppid = (int)strtol(p,&p,10); /* skip ppid */
- p = skip_token(p); /* skip pgrp */
- p = skip_token(p); /* skip session */
- p = skip_token(p); /* skip tty */
- p = skip_token(p); /* skip tty pgrp */
- p = skip_token(p); /* skip flags */
- p = skip_token(p); /* skip min flt */
- p = skip_token(p); /* skip cmin flt */
- p = skip_token(p); /* skip maj flt */
- p = skip_token(p); /* skip cmaj flt */
- if(cpuV)
- {
- cpuV->userTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* utime */
- cpuV->sysTime = ((double)strtoul(p, &p, 10))/cpuClockTicksPerSecond; /* stime */
- }
- else
- {
- p = skip_token(p); /* skip utime */
- p = skip_token(p); /* skip stime */
- }
- p = skip_token(p); /* skip cutime */
- p = skip_token(p); /* skip cstime */
-
- p = skip_token(p); /* skip priority */
- p = skip_token(p); /* skip nice */
-
- p = skip_token(p); /* skip timeout */
- p = skip_token(p); /* skip it_real_val */
- p = skip_token(p); /* skip start_time */
-
- if(memV)
- {
- memV->vsize = bytetok(strtoul(p, &p, 10)); /* vsize */
- memV->rss = pagetok(strtoul(p, &p, 10)); /* rss */
- memV->memPercent =(double)(memV->rss*100.0)/(double)totalMem;
- }
-
- return ppid;
-}
-
-int getSystemMemory (systemMemVals* mem)
-{
- FILE* fp;
- char buffer[4096];
- size_t bytes_read;
- char* match;
- long totalMem=-1,freeMem=-1,totalSwap=-1,freeSwap=-1;
-
- fp = fopen ("/proc/meminfo","r");
- if (fp==NULL)
- return -1;
- bytes_read = fread(buffer, 1, sizeof (buffer), fp);
- fclose(fp);
-
- if (bytes_read==0 || bytes_read == sizeof (buffer))
- return -1;
- buffer[bytes_read] = '\0';
-
- match = strstr (buffer, "MemTotal:");
- if (match == NULL)
- return -1;
- sscanf (match, "MemTotal:%ld", &totalMem);
- match = strstr (buffer, "MemFree:");
- if (match == NULL)
- return -1;
- sscanf (match, "MemFree:%ld", &freeMem);
- match = strstr (buffer, "SwapTotal:");
- if (match == NULL)
- return -1;
- sscanf (match, "SwapTotal:%ld", &totalSwap);
- match = strstr (buffer, "SwapFree:");
- if (match == NULL)
- return -1;
- sscanf (match, "SwapFree:%ld", &freeSwap);
-
- mem->totalMem=totalMem;
- mem->freeMem=freeMem;
- mem->totalSwap=totalSwap;
- mem->freeSwap=freeSwap;
- return 0;
-}
-
-long getTotalSystemMem(void)
-{
- /* get system wide memory usage */
- FILE* fp;
- char buffer[4096];
- size_t bytes_read;
- char* match;
- long totalMem=-1;
-
- fp = fopen ("/proc/meminfo","r");
- if (fp==NULL)
- return totalMem;
- bytes_read = fread(buffer, 1, sizeof (buffer), fp);
- fclose(fp);
-
- if (bytes_read==0 || bytes_read == sizeof (buffer))
- return totalMem;
- buffer[bytes_read] = '\0';
-
- match = strstr (buffer, "MemTotal:");
- if (match == NULL)
- return totalMem;
-
- sscanf (match, "MemTotal:%ld", &totalMem);
- return totalMem;
-}
-
-void getSystemTime(double* upTime,double* idleTime)
-{
- FILE* fp;
- *upTime = 0;
- *idleTime = 0;
- fp = fopen("/proc/uptime", "r");
- if (fp==NULL)
- return;
- fscanf (fp, "%lf %lf\n", upTime, idleTime);
- fclose (fp);
-}
-
-void getProcessorTime(long* usageTime,long* idleTime,int processor)
-{
- FILE* fp;
- char buffer[4096];
- char cpu[10];
- size_t bytes_read;
- char* match;
- long user_read, system_read, nice_read, idle_read;
- *usageTime = 0;
- *idleTime = 0;
-
- fp = fopen ("/proc/stat","r");
- if (fp==NULL)
- return;
- bytes_read = fread(buffer, 1, sizeof (buffer), fp);
- fclose(fp);
- if (bytes_read==0 || bytes_read == sizeof (buffer))
- return;
- buffer[bytes_read] = '\0';
- sprintf(cpu,"cpu%d ",processor);
- match = strstr (buffer, cpu);
- if (match == NULL)
- return;
- sscanf(match, "%*s %ld %ld %ld %ld", &user_read,&system_read,&nice_read,&idle_read);
- *usageTime = user_read + system_read + nice_read;
- *idleTime = idle_read;
-}
--
1.7.7.6


[PATCH 03/30] Moved environment.c to linux/environment.c

Michael Schonberg <mschonberg@...>
 

The funcitons for manipulating environement variables are os-specific. We
may want to add a generic directory for a default implemenation.

This is in preparation for the windows port.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 3 +-
common/c_cpp/src/c/environment.c | 59 --------------------------------
common/c_cpp/src/c/linux/environment.c | 59 ++++++++++++++++++++++++++++++++
3 files changed, 61 insertions(+), 60 deletions(-)
delete mode 100644 common/c_cpp/src/c/environment.c
create mode 100644 common/c_cpp/src/c/linux/environment.c

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index 9b08055..b6f537a 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -46,7 +46,8 @@ AC_CANONICAL_BUILD()
# Set up symbolic links for os-specific files
AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
case $build_os in
- linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h]) ;;
+ linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h
+ src/c/environment.c:src/c/linux/environment.c]) ;;
esac

# Checks for programs.
diff --git a/common/c_cpp/src/c/environment.c b/common/c_cpp/src/c/environment.c
deleted file mode 100644
index 34affc0..0000000
--- a/common/c_cpp/src/c/environment.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* $Id: environment.c,v 1.2.2.3.12.2 2011/08/10 14:53:23 nicholasmarriott Exp $
- *
- * OpenMAMA: The open middleware agnostic messaging API
- * Copyright (C) 2011 NYSE Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library 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. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA
- */
-
-/* ********************************************************** */
-/* Includes. */
-/* ********************************************************** */
-#include "stdlib.h"
-#include "wombat/environment.h"
-
-int environment_deleteVariable(const char *name)
-{
- return unsetenv(name);
-}
-
-const char *environment_getVariable(const char *name)
-{
- /* Returns. */
- const char *ret = NULL;
-
- /* Check the argument. */
- if(name != NULL)
- {
- ret = getenv(name);
- }
-
- return ret;
-}
-
-int environment_setVariable(const char *name, const char *value)
-{
- /* Returns. */
- int ret = -1;
-
- /* Check the arguments. */
- if((name != NULL) && (value != NULL))
- {
- ret = setenv(name, value, 1);
- }
-
- return ret;
-}
diff --git a/common/c_cpp/src/c/linux/environment.c b/common/c_cpp/src/c/linux/environment.c
new file mode 100644
index 0000000..34affc0
--- /dev/null
+++ b/common/c_cpp/src/c/linux/environment.c
@@ -0,0 +1,59 @@
+/* $Id: environment.c,v 1.2.2.3.12.2 2011/08/10 14:53:23 nicholasmarriott Exp $
+ *
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+/* ********************************************************** */
+/* Includes. */
+/* ********************************************************** */
+#include "stdlib.h"
+#include "wombat/environment.h"
+
+int environment_deleteVariable(const char *name)
+{
+ return unsetenv(name);
+}
+
+const char *environment_getVariable(const char *name)
+{
+ /* Returns. */
+ const char *ret = NULL;
+
+ /* Check the argument. */
+ if(name != NULL)
+ {
+ ret = getenv(name);
+ }
+
+ return ret;
+}
+
+int environment_setVariable(const char *name, const char *value)
+{
+ /* Returns. */
+ int ret = -1;
+
+ /* Check the arguments. */
+ if((name != NULL) && (value != NULL))
+ {
+ ret = setenv(name, value, 1);
+ }
+
+ return ret;
+}
--
1.7.7.6


[PATCH 02/30] Moved Calling Convention from wConfig.h to linux/port.h

Michael Schonberg <mschonberg@...>
 

These are OS specific. wConfig remains for backwards compatibilit; however, it
may be removed in the future. They all default to a no-op for Linux, but are
required for different Windows builds (dynamic, static, debug, etc).

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/src/c/wombat/wConfig.h | 72 +----------------------------------
1 files changed, 2 insertions(+), 70 deletions(-)

diff --git a/common/c_cpp/src/c/wombat/wConfig.h b/common/c_cpp/src/c/wombat/wConfig.h
index c2137df..c7cf7af 100644
--- a/common/c_cpp/src/c/wombat/wConfig.h
+++ b/common/c_cpp/src/c/wombat/wConfig.h
@@ -22,76 +22,8 @@
#ifndef _WOMBAT_WCONFIG_H
#define _WOMBAT_WCONFIG_H

-/* This section defines export semantics for functions exported or
- * imported from Windows libraries. All exported functions must
- * be decorated with the appropriate modifier.
- */
-
-#if defined( WIN32 ) && defined( COMMON_DLL )
- /* We are building common dll */
-# define COMMONExpDLL __declspec( dllexport )
-#elif defined( WIN32 ) && defined( MAMA_DLL ) && defined( MAMA )
- /* We are building mama as a dll */
-# define COMMONExpDLL __declspec( dllimport )
-# define MAMAExpDLL __declspec( dllexport )
-# define MAMAExpBridgeDLL __declspec( dllexport )
-#elif defined( WIN32 ) && defined( MAMA_DLL ) && defined( BRIDGE )
- /* We are building mama bridge as a dll */
-# define MAMAExpDLL __declspec( dllimport )
-# define MAMAExpBridgeDLL __declspec( dllimport )
-# define COMMONExpDLL __declspec( dllimport )
-# define MAMACPPExpDLL
-# define MAMDAExpDLL
-# define MAMDAOPTExpDLL
-#elif defined( WIN32 ) && defined( MAMA_DLL ) && defined( MAMACPP )
- /* We are building mamacpp as a dll */
-# define COMMONExpDLL __declspec( dllimport )
-# define MAMAExpDLL __declspec( dllimport )
-# define MAMACPPExpDLL __declspec( dllexport )
-# define MAMAExpBridgeDLL
-#elif defined( WIN32 ) && defined( MAMDA_DLL ) && defined( MAMDA )
- /* We are building mamda as a dll */
-# define COMMONExpDLL __declspec( dllimport )
-# define MAMAExpDLL __declspec( dllimport )
-# define MAMACPPExpDLL __declspec( dllimport )
-# define MAMDAExpDLL __declspec( dllexport )
-# define MAMAExpBridgeDLL
-#elif defined( WIN32 ) && defined( MAMDA_DLL ) && defined( MAMDAOPT )
- /* We are building extra mamda as a dll */
-# define COMMONExpDLL __declspec( dllimport )
-# define MAMAExpDLL __declspec( dllimport )
-# define MAMACPPExpDLL __declspec( dllimport )
-# define MAMDAExpDLL __declspec( dllimport )
-# define MAMDAOPTExpDLL __declspec( dllexport )
-# define MAMAExpBridgeDLL
-#elif defined( WIN32 ) && !defined ( MAMA_STATIC ) && !defined ( WMW_STATIC ) && !defined (WIRECACHE_STATIC)
- /* We are building mama apps (non static) */
-# define COMMONExpDLL __declspec( dllimport )
-# define WMWExpDLL __declspec( dllexport )
-# define MAMAExpDLL __declspec( dllimport )
-# define MAMACPPExpDLL __declspec( dllimport )
-# define MAMDAExpDLL __declspec( dllimport )
-# define MAMDAOPTExpDLL __declspec( dllimport )
-# define MAMAExpBridgeDLL
-#else
- /* We are building on linux or statically */
-# define COMMONExpDLL
-# define WMWExpDLL
-# define MAMAExpDLL
-# define MAMACPPExpDLL
-# define MAMDAExpDLL
-# define MAMDAOPTExpDLL
-# define MAMAExpBridgeDLL
-#endif /* WIN32 */
-
-/*
- * Windows callback functions require the standard call type.
- */
-#ifdef WIN32
-#define MAMACALLTYPE __stdcall
-#else
-#define MAMACALLTYPE
-#endif
+/* Moved to _os_/port/h */
+#include "port.h"

#endif /* _WOMBAT_WCONFIG_H */

--
1.7.7.6


[PATCH 01/30] Move Linux Specific #includes and Macros #includes

Michael Schonberg <mschonberg@...>
 

This is the first in a series of patches to add Windows suport. Rather
than peppering the source with #ifdef osXXX blocks, os specific headers
and source files go into directory with the same name as the OS. Ideally,
there will be one linux directory in common, one windows, etc.; however,
the same approach should be used in other modules that require os specific
implementations. "#ifdef OS" should be avoided whenever possible.

Each OS directory must at least contain a file "port.h". This file
contains os-specific includes and macros. At some point, it might make
sense to subdivide port.h into several headers (one for networking,
threads, etc.). For the moement we will stick with one until the process
is complete.

We may also want to move some of the linux/ that is common to other os's
like Solaris and BSD to a /unix directory when we start adding support for
other unix-like platforms.

This change creates common/c_cpp/src/c/linux/port.h. All of the #includes
that are not found by the windows compiler are in port.h as well as some
of the obvious linux specific macros.

Signed-off-by: Mike Schonberg <mschonberg@nyx.com>
---
common/c_cpp/configure.ac | 6 ++
common/c_cpp/src/c/MRSWLock.c | 2 +-
common/c_cpp/src/c/Makefile.am | 1 +
common/c_cpp/src/c/destroyHandle.c | 1 +
common/c_cpp/src/c/linux/port.h | 136 ++++++++++++++++++++++++++++++++
common/c_cpp/src/c/list.c | 6 +-
common/c_cpp/src/c/machine.c | 9 +--
common/c_cpp/src/c/platform.c | 5 +-
common/c_cpp/src/c/platform.h | 21 -----
common/c_cpp/src/c/property.c | 4 +-
common/c_cpp/src/c/queue.c | 22 +-----
common/c_cpp/src/c/strutils.c | 7 +-
common/c_cpp/src/c/systree.h | 4 -
common/c_cpp/src/c/timers.h | 3 +-
common/c_cpp/src/c/wSemaphore.c | 8 +--
common/c_cpp/src/c/wlock.c | 3 +-
common/c_cpp/src/c/wlock.h | 5 -
common/c_cpp/src/c/wombat/queue.h | 15 +---
common/c_cpp/src/c/wombat/strutils.h | 7 --
common/c_cpp/src/c/wombat/wSemaphore.h | 51 +------------
common/c_cpp/src/c/wombat/wincompat.h | 1 +
21 files changed, 163 insertions(+), 154 deletions(-)
create mode 100644 common/c_cpp/src/c/linux/port.h

diff --git a/common/c_cpp/configure.ac b/common/c_cpp/configure.ac
index a95eb91..9b08055 100755
--- a/common/c_cpp/configure.ac
+++ b/common/c_cpp/configure.ac
@@ -43,6 +43,12 @@ AM_INIT_AUTOMAKE([foreign])
AM_CONFIG_HEADER([config.h])
AC_CANONICAL_BUILD()

+# Set up symbolic links for os-specific files
+AC_MSG_NOTICE([Configuring symbolic links for $build_os in $srcdir])
+case $build_os in
+ linux*-*) AC_CONFIG_LINKS([src/c/port.h:src/c/linux/port.h]) ;;
+esac
+
# Checks for programs.
AC_PROG_CXX

diff --git a/common/c_cpp/src/c/MRSWLock.c b/common/c_cpp/src/c/MRSWLock.c
index b7d84c3..8cccb7c 100644
--- a/common/c_cpp/src/c/MRSWLock.c
+++ b/common/c_cpp/src/c/MRSWLock.c
@@ -22,8 +22,8 @@
/* ********************************************************** */
/* Includes. */
/* ********************************************************** */
+#include "port.h"
#include "wombat/MRSWLock.h"
-#include "wombat/wincompat.h"
#include <stdlib.h>

/* ********************************************************** */
diff --git a/common/c_cpp/src/c/Makefile.am b/common/c_cpp/src/c/Makefile.am
index bab6069..facce7c 100644
--- a/common/c_cpp/src/c/Makefile.am
+++ b/common/c_cpp/src/c/Makefile.am
@@ -38,6 +38,7 @@ nobase_include_HEADERS = \
property.h \
wlock.h \
timers.h \
+ port.h \
wombat/MRSWLock.h \
wombat/environment.h \
wombat/machine.h \
diff --git a/common/c_cpp/src/c/destroyHandle.c b/common/c_cpp/src/c/destroyHandle.c
index 37a2ae3..cf63ea8 100644
--- a/common/c_cpp/src/c/destroyHandle.c
+++ b/common/c_cpp/src/c/destroyHandle.c
@@ -22,6 +22,7 @@
/* ************************************************************** */
/* Includes. */
/* ************************************************************** */
+#include "port.h"
#include "destroyHandle.h"
#include <stdio.h>

diff --git a/common/c_cpp/src/c/linux/port.h b/common/c_cpp/src/c/linux/port.h
new file mode 100644
index 0000000..a1de75d
--- /dev/null
+++ b/common/c_cpp/src/c/linux/port.h
@@ -0,0 +1,136 @@
+/*
+ * OpenMAMA: The open middleware agnostic messaging API
+ * Copyright (C) 2011 NYSE Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+/* Linux Specific macros, #includes, and prototypes.
+ *
+ * For Linux, most should be macros. Some of the contents of this file may be
+ * moved to a common "unix.h' file when we port to Solaris and other unix
+ * variants.
+ */
+
+#ifndef PORT_LINUX_H__
+#define PORT_LINUX_H__
+
+#if defined (__cplusplus)
+extern "C"
+{
+#endif
+
+#include <pthread.h>
+#include <sys/types.h>
+#include <sys/vfs.h>
+#include <sys/param.h>
+#include <sys/resource.h>
+#include <sys/time.h>
+#include <sys/times.h>
+#include <netinet/in.h>
+#include <semaphore.h>
+#include <dirent.h>
+#include <dlfcn.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+/* Call Types */
+#define COMMONExpDLL
+#define WMWExpDLL
+#define MAMAExpDLL
+#define MAMACPPExpDLL
+#define MAMDAExpDLL
+#define MAMDAOPTExpDLL
+#define MAMAExpBridgeDLL
+#define MAMACALLTYPE
+
+/* Type for handle to dynamically loaded library */
+typedef void* LIB_HANDLE;
+
+/* suffix for shared libraries */
+#define LIB_EXTENSION ".so"
+
+/* 8 byte int typedefs */
+typedef unsigned long long int w_u64_t;
+typedef long long int w_i64_t;
+
+/* Network conversion function */
+#if __BYTE_ORDER == __LITTLE_ENDIAN
+#define htonll(x) \
+ ((uint64_t)htonl((uint32_t)((x)>>32)) | (uint64_t)htonl((uint32_t)(x))<<32)
+#define ntohll(x) \
+ ((uint64_t)ntohl((uint32_t)((x)>>32)) | (uint64_t)ntohl((uint32_t)(x))<<32)
+#else
+#define htonll(x) ((uint64_t)(x))
+#define ntohll(x) ((uint64_t)(x))
+#endif
+
+/* For delimiting multiple paths in env variables properties */
+#define PATH_DELIM ':'
+
+/* Use Posix semaphores for Linux */
+#define wsem_t sem_t
+#define wsem_init sem_init
+#define wsem_post sem_post
+#define wsem_wait sem_wait
+#define wsem_trywait sem_trywait
+#define wsem_destroy sem_destroy
+#define wsem_getvalue sem_getvalue
+
+int wsem_timedwait (wsem_t* sem, unsigned int ts);
+
+/* User pthreads for linux */
+#define wthread_mutex_t pthread_mutex_t
+#define wthread_mutex_init pthread_mutex_init
+#define wthread_mutex_unlock pthread_mutex_unlock
+#define wthread_mutex_lock pthread_mutex_lock
+#define wthread_mutex_destroy pthread_mutex_destroy
+#define wthread_t pthread_t
+#define wthread_detach pthread_detach
+#define wthread_self pthread_self
+#define wthread_equal pthread_equal
+#define wthread_cleanup_push pthread_cleanup_push
+#define wthread_cleanup_pop pthread_cleanup_pop
+#define wthread_join pthread_join
+#define wthread_create pthread_create
+#define wthread_exit pthread_exit
+
+#define wthread_cond_t pthread_cond_t
+#define wthread_cond_init pthread_cond_init
+#define wthread_cond_signal pthread_cond_signal
+#define wthread_cond_destroy pthread_cond_destroy
+#define wthread_cond_wait pthread_cond_wait
+
+#define wthread_spinlock_t pthread_spinlock_t
+#define wthread_spin_init pthread_spin_init
+#define wthread_spin_unlock pthread_spin_unlock
+#define wthread_spin_lock pthread_spin_lock
+#define wthread_spin_destroy pthread_spin_destroy
+#define wthread_attr_t pthread_attr_t
+#define wthread_attr_init pthread_attr_init
+#define wthread_attr_setdetachstate pthread_attr_setdetachstate
+
+#define wthread_mutexattr_t pthread_mutexattr_t
+#define wthread_mutexattr_init pthread_mutexattr_init
+#define wthread_mutexattr_settype pthread_mutexattr_settype
+
+#define wGetCurrentThreadId pthread_self
+
+#if defined (__cplusplus)
+} /* extern "c" */
+#endif
+
+#endif /* LINUX_H__ */
diff --git a/common/c_cpp/src/c/list.c b/common/c_cpp/src/c/list.c
index e37b4b0..ef3a00d 100644
--- a/common/c_cpp/src/c/list.c
+++ b/common/c_cpp/src/c/list.c
@@ -19,11 +19,7 @@
* 02110-1301 USA
*/

-#ifndef WIN32
-#include <pthread.h>
-#else
-#include "wombat/wincompat.h"
-#endif
+#include "port.h"

#include <stdlib.h>
#include <stdio.h>
diff --git a/common/c_cpp/src/c/machine.c b/common/c_cpp/src/c/machine.c
index 42bd9de..512e1ab 100644
--- a/common/c_cpp/src/c/machine.c
+++ b/common/c_cpp/src/c/machine.c
@@ -19,14 +19,10 @@
* 02110-1301 USA
*/

-#include <sys/param.h>
-#include <sys/resource.h>
+#include "port.h"
#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/times.h>

#include <ctype.h>
-#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
@@ -34,10 +30,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/vfs.h>
#include <time.h>
-#include <unistd.h>
-#include <unistd.h>

#include "wombat/machine.h"
#include "wombat/wtable.h"
diff --git a/common/c_cpp/src/c/platform.c b/common/c_cpp/src/c/platform.c
index 0ed6d18..8bf7f4e 100644
--- a/common/c_cpp/src/c/platform.c
+++ b/common/c_cpp/src/c/platform.c
@@ -19,6 +19,7 @@
* 02110-1301 USA
*/

+#include "port.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -27,10 +28,6 @@
#include "platform.h"
#include "wombat/wincompat.h"

-
-#define LIB_EXTENSION ".so"
-
-
/**
* Functions relating to DLLs/shared objects
*/
diff --git a/common/c_cpp/src/c/platform.h b/common/c_cpp/src/c/platform.h
index c3b17d6..440f962 100644
--- a/common/c_cpp/src/c/platform.h
+++ b/common/c_cpp/src/c/platform.h
@@ -25,16 +25,6 @@
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
-#include "wombat/wincompat.h"
-#include <dlfcn.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-
-#ifdef WIN32
-typedef HINSTANCE LIB_HANDLE;
-#else
-typedef void* LIB_HANDLE;
-#endif

/* The platform specific prefix and postfix will automatically be added to the libname
e.g on Linux "mamaImpl" will load "libmamaimpl.so" */
@@ -50,17 +40,6 @@ void* loadLibFunc (LIB_HANDLE handle, const char* funcName);
COMMONExpDLL
char* getLibError (void);

-/* Network conversion function */
-#if defined(WIN32) || __BYTE_ORDER == __LITTLE_ENDIAN
-#define htonll(x) \
- ((uint64_t)htonl((uint32_t)((x)>>32)) | (uint64_t)htonl((uint32_t)(x))<<32)
-#define ntohll(x) \
- ((uint64_t)ntohl((uint32_t)((x)>>32)) | (uint64_t)ntohl((uint32_t)(x))<<32)
-#else
-#define htonll(x) ((uint64_t)(x))
-#define ntohll(x) ((uint64_t)(x))
-#endif
-
#if defined(__cplusplus)
}
#endif /* __cplusplus */
diff --git a/common/c_cpp/src/c/property.c b/common/c_cpp/src/c/property.c
index 456c08f..a5271ec 100644
--- a/common/c_cpp/src/c/property.c
+++ b/common/c_cpp/src/c/property.c
@@ -19,6 +19,8 @@
* 02110-1301 USA
*/

+#include "port.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -32,8 +34,6 @@

#define KEY_BLOCK_SIZE 64

-#define PATH_DELIM ':'
-
int gPropertyDebug = 0;

typedef struct
diff --git a/common/c_cpp/src/c/queue.c b/common/c_cpp/src/c/queue.c
index ce960d1..03cf678 100644
--- a/common/c_cpp/src/c/queue.c
+++ b/common/c_cpp/src/c/queue.c
@@ -19,16 +19,9 @@
* 02110-1301 USA
*/

-#ifndef WIN32
-#include <pthread.h>
-#else
-#include "wombat/wincompat.h"
-#define pthread_mutex_t wthread_mutex_t
-#define pthread_mutex_init wthread_mutex_init
-#define pthread_mutex_destroy wthread_mutex_destroy
-#define pthread_mutex_lock wthread_mutex_lock
-#define pthread_mutex_unlock wthread_mutex_unlock
-#endif
+
+#include "port.h"
+
#include "wombat/wSemaphore.h"

#include <errno.h>
@@ -120,14 +113,10 @@ wombatQueue_create (wombatQueue queue, uint32_t maxSize, uint32_t initialSize,
return WOMBAT_QUEUE_SEM_ERR;
}

-#ifndef WIN32
if (pthread_mutex_init( &impl->mLock, NULL) != 0)
{
return WOMBAT_QUEUE_MTX_ERR;
}
-#else
- wthread_mutex_init( &impl->mLock, NULL);
-#endif

initialSize = initialSize == 0 ? WOMBAT_QUEUE_CHUNK_SIZE : initialSize;
wombatQueueImpl_allocChunk (impl, initialSize);
@@ -173,15 +162,10 @@ wombatQueue_destroy (wombatQueue queue)
result = WOMBAT_QUEUE_SEM_ERR;
}

-#ifndef WIN32
if (pthread_mutex_destroy( &impl->mLock) != 0)
{
result = WOMBAT_QUEUE_MTX_ERR;
}
-#else
- wthread_mutex_destroy( &impl->mLock);
-#endif
-

free (impl);
return WOMBAT_QUEUE_OK;
diff --git a/common/c_cpp/src/c/strutils.c b/common/c_cpp/src/c/strutils.c
index 1fae9b7..4874fe6 100644
--- a/common/c_cpp/src/c/strutils.c
+++ b/common/c_cpp/src/c/strutils.c
@@ -23,17 +23,14 @@
#define __STDC_FORMAT_MACROS
#endif

+#include "port.h"
+
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
-#ifndef WIN32
-#include <inttypes.h>
-#else
-#include <wombat/wincompat.h>
-#endif
#include <wombat/strutils.h>

static const char* gIntegerStrings[] = {
diff --git a/common/c_cpp/src/c/systree.h b/common/c_cpp/src/c/systree.h
index f5a15cc..818be5a 100644
--- a/common/c_cpp/src/c/systree.h
+++ b/common/c_cpp/src/c/systree.h
@@ -24,10 +24,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

-#ifdef WIN32
-#define __attribute__(a)
-#endif
-
#ifndef _SYS_TREE_H_
#define _SYS_TREE_H_

diff --git a/common/c_cpp/src/c/timers.h b/common/c_cpp/src/c/timers.h
index a653dc4..38a3732 100644
--- a/common/c_cpp/src/c/timers.h
+++ b/common/c_cpp/src/c/timers.h
@@ -22,8 +22,7 @@
#ifndef TIMERS_INTERNAL_
#define TIMERS_INTERNAL_

-#include <sys/time.h>
-#include <pthread.h>
+#include "port.h"

typedef void* timerElement;
typedef void* timerHeap;
diff --git a/common/c_cpp/src/c/wSemaphore.c b/common/c_cpp/src/c/wSemaphore.c
index 04b526f..df2bae1 100644
--- a/common/c_cpp/src/c/wSemaphore.c
+++ b/common/c_cpp/src/c/wSemaphore.c
@@ -19,15 +19,11 @@
* 02110-1301 USA
*/

-#include "wombat/wincompat.h"
+#include "port.h"
+
#include "wombat/wSemaphore.h"

#ifndef WIN32
-#include <pthread.h>
-#include <semaphore.h>
-#include <time.h>
-#include <sys/time.h>
-

int wsem_timedwait (wsem_t* sem, unsigned int timeoutval)
{
diff --git a/common/c_cpp/src/c/wlock.c b/common/c_cpp/src/c/wlock.c
index 309b89d..9cd7d21 100644
--- a/common/c_cpp/src/c/wlock.c
+++ b/common/c_cpp/src/c/wlock.c
@@ -19,7 +19,8 @@
* 02110-1301 USA
*/

-#include <pthread.h>
+#include "port.h"
+
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
diff --git a/common/c_cpp/src/c/wlock.h b/common/c_cpp/src/c/wlock.h
index 4c5a82c..199dad8 100644
--- a/common/c_cpp/src/c/wlock.h
+++ b/common/c_cpp/src/c/wlock.h
@@ -22,11 +22,6 @@
#ifndef _WOMBAT_WLOCK_H
#define _WOMBAT_WLOCK_H

-
-#include "wombat/wincompat.h"
-
-
-
typedef void * wLock;

COMMONExpDLL wLock wlock_create( void );
diff --git a/common/c_cpp/src/c/wombat/queue.h b/common/c_cpp/src/c/wombat/queue.h
index 36590d0..e9e2093 100644
--- a/common/c_cpp/src/c/wombat/queue.h
+++ b/common/c_cpp/src/c/wombat/queue.h
@@ -25,20 +25,7 @@
/*
* Fully thread safe queue implementation.
*/
-
-#ifndef WIN32
-#include <semaphore.h>
-#include <inttypes.h>
-#else
-#include "wombat/wincompat.h"
-#endif
-
-#ifndef WIN32
-/* For Forte */
-#ifndef SEM_VALUE_MAX
-#define SEM_VALUE_MAX 2147483647 /* from headers */
-#endif
-
+#ifdef SEM_VALUE_MAX
#define WOMBAT_QUEUE_MAX_SIZE SEM_VALUE_MAX /* 2_147_483_647 on Linux */
#else
#define WOMBAT_QUEUE_MAX_SIZE 2147483647 /* max possible size */
diff --git a/common/c_cpp/src/c/wombat/strutils.h b/common/c_cpp/src/c/wombat/strutils.h
index b20e712..d5d1fb8 100644
--- a/common/c_cpp/src/c/wombat/strutils.h
+++ b/common/c_cpp/src/c/wombat/strutils.h
@@ -30,13 +30,6 @@ extern "C" {


typedef unsigned long int w_u32_t;
-#ifndef WIN32
-typedef unsigned long long int w_u64_t;
-typedef long long int w_i64_t;
-#else
-typedef unsigned __int64 w_u64_t;
-typedef __int64 w_i64_t;
-#endif
typedef long int w_i32_t;
typedef float w_f32_t;
typedef double w_f64_t;
diff --git a/common/c_cpp/src/c/wombat/wSemaphore.h b/common/c_cpp/src/c/wombat/wSemaphore.h
index 89949a6..9adb8d2 100644
--- a/common/c_cpp/src/c/wombat/wSemaphore.h
+++ b/common/c_cpp/src/c/wombat/wSemaphore.h
@@ -22,55 +22,6 @@
#ifndef WSEMAPHORE_H__
#define WSEMAPHORE_H__

-#ifndef WIN32
-
-#include <pthread.h>
-#include <semaphore.h>
-#include <time.h>
-
-#define wsem_t sem_t
-#define wsem_init sem_init
-#define wsem_post sem_post
-#define wsem_wait sem_wait
-#define wsem_trywait sem_trywait
-#define wsem_destroy sem_destroy
-#define wsem_getvalue sem_getvalue
-
-int wsem_timedwait (wsem_t* sem, unsigned int ts);
-
-#else
-#include "wombat/wincompat.h"
-
-/**
- * Waiting on Win32 semaphore involves a system call and is very inefficient.
- * When we test to determine if the queue is empty with a Win32 semaphore
- * WaitForSingleObject consumes all the CPU. We can be much more efficient
- * using a critical section and not call WaitForSingleObject when there is
- * nothing on the Queue.
- */
-typedef void* wsem_t;
-
-COMMONExpDLL
-int wsem_init (wsem_t* sem, int dummy, int count);
-
-COMMONExpDLL
-int wsem_destroy (wsem_t* sem);
-
-COMMONExpDLL
-int wsem_post (wsem_t* sem);
-
-COMMONExpDLL
-int wsem_wait (wsem_t* sem);
-
-COMMONExpDLL
-int wsem_timedwait (wsem_t* sem, unsigned int ts);
-
-COMMONExpDLL
-int wsem_trywait (wsem_t* sem);
-
-COMMONExpDLL
-int wsem_getvalue (wsem_t*, int* items);
-
-#endif
+#include "port.h"

#endif /* WSEMAPHORE_H__ */
diff --git a/common/c_cpp/src/c/wombat/wincompat.h b/common/c_cpp/src/c/wombat/wincompat.h
index 5c78acb..756ecea 100644
--- a/common/c_cpp/src/c/wombat/wincompat.h
+++ b/common/c_cpp/src/c/wombat/wincompat.h
@@ -22,6 +22,7 @@
#ifndef _WOMBAT_WINCOMPAT_H
#define _WOMBAT_WINCOMPAT_H

+#include "port.h"
#include "wConfig.h"

#define PATHSEP "/"
--
1.7.7.6


[PATCH 00/30] Preparing for Windows Support

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

This rather large patch set introduces the changes required for Windows support.
Prior to OpenMAMA, MAMA supported other operating systems (Windows and Solaris)
through conditional compilation with ifdef's. This approach proved messy and
difficult to maintain.

For OpenMAMA, we removed most of the "#ifdef WIN32" blocks with the intention of
reintroducing Windows support in a better way. The following patches move all of
the Windows specific code to the windows subdirectory in common and puts the
Linux equivalents in a linux subdirectory when necessary. Most of the
portability layer consists of macros and small inline functions and is almost
entirely identical to the old #ifdef code; however, rather than scattering it
throughout the code base we have it all in one place.

This should greatly simplify future ports to Solaris and other platform:
implementors only need to reproduce the compatibility layer for the new
platform.

NOTE: The build infrastructure for Windows is not part of this patch set. It
will be checked in with the C++, Java and MAMDA support in the next few weeks.

Michael Schonberg (29):
Move Linux Specific #includes and Macros
Moved Calling Convention from wConfig.h to linux/port.h
Moved environment.c to linux/environment.c
Moved linux code from machine.c to linux/machine.c
Moved platform.c to linux/platform.c
Moved wincompat.h contents to _os_/port.h
Changes for queue.c to build on windows
wlock.c changes for windows support
Preparing timer.c and timer.c for windows support
Move wSemaphore.c to linx/wSemaphroe.c
Moved macros for inline functions to _os_/port.h
Added wthread_global_mutex macros
Header changes for windows support
Prepare ft.c for Windows support
Removed PATHSEP macro
Added Thread Local Storage
Added getHostName and getIpAddress.
mama.c changes for windows support
Add wtimegm macro for poritning timegm
Correct Method Signatures for Linking On Windows
Correct windows calling convention for queue
Conflation manager fixes for windows
Replaced numerous #ifdef WIN32 with port.h
Removed #ifdef WIN32 from playbackFileParser
Adding new common/../windows/* files
Changes for Windows
Added wdlXXX macos to linux/port.h
Moved port.h to wombat sub directory
Renamed resolve_ip to wresolve_ip

Mike Schonberg (1):
Moved wombat/wInterlocked.h to Linux directory

common/c_cpp/configure.ac | 13 +
common/c_cpp/src/c/MRSWLock.c | 2 +-
common/c_cpp/src/c/Makefile.am | 3 +
common/c_cpp/src/c/destroyHandle.c | 1 +
common/c_cpp/src/c/environment.c | 59 --
common/c_cpp/src/c/linux/environment.c | 59 ++
common/c_cpp/src/c/linux/machine.c | 599 ++++++++++++++++++++
common/c_cpp/src/c/linux/network.c | 195 +++++++
common/c_cpp/src/c/linux/platform.c | 84 +++
common/c_cpp/src/c/linux/port.h | 181 ++++++
common/c_cpp/src/c/linux/wConfig.h | 40 ++
common/c_cpp/src/c/linux/wInterlocked.h | 142 +++++
common/c_cpp/src/c/linux/wSemaphore.c | 57 ++
common/c_cpp/src/c/list.c | 6 +-
common/c_cpp/src/c/machine.c | 575 +-------------------
common/c_cpp/src/c/platform.c | 88 ---
common/c_cpp/src/c/platform.h | 21 -
common/c_cpp/src/c/properties.l | 16 +-
common/c_cpp/src/c/property.c | 4 +-
common/c_cpp/src/c/queue.c | 110 ++---
common/c_cpp/src/c/strutils.c | 7 +-
common/c_cpp/src/c/systree.h | 4 -
common/c_cpp/src/c/timers.c | 176 +++---
common/c_cpp/src/c/timers.h | 5 +-
common/c_cpp/src/c/wSemaphore.c | 192 -------
common/c_cpp/src/c/windows/environment.c | 81 +++
common/c_cpp/src/c/windows/lock.h | 82 +++
common/c_cpp/src/c/windows/machine_win.c | 213 +++++++
common/c_cpp/src/c/windows/mmap.h | 28 +
common/c_cpp/src/c/windows/network.c | 87 +++
common/c_cpp/src/c/windows/platform.c | 84 +++
common/c_cpp/src/c/windows/port.c | 276 +++++++++
common/c_cpp/src/c/windows/port.h | 251 ++++++++
common/c_cpp/src/c/windows/wSemaphore.c | 147 +++++
common/c_cpp/src/c/windows/wombat/targetsxs.h | 38 ++
common/c_cpp/src/c/windows/wombat/wConfig.h | 101 ++++
common/c_cpp/src/c/windows/wombat/wInterlocked.h | 97 ++++
common/c_cpp/src/c/wlock.c | 11 +-
common/c_cpp/src/c/wlock.h | 5 -
common/c_cpp/src/c/wombat/queue.h | 67 +--
common/c_cpp/src/c/wombat/strutils.h | 7 -
common/c_cpp/src/c/wombat/wCommon.h | 27 +-
common/c_cpp/src/c/wombat/wConfig.h | 99 +----
common/c_cpp/src/c/wombat/wInterlocked.h | 142 -----
common/c_cpp/src/c/wombat/wSemaphore.h | 51 +--
common/c_cpp/src/c/wombat/wincompat.h | 49 +--
mama/c_cpp/src/c/bridge/avis/bridge.c | 5 +-
mama/c_cpp/src/c/bridge/avis/msg.c | 5 +-
mama/c_cpp/src/c/bridge/avis/transportbridge.c | 5 +-
mama/c_cpp/src/c/conflation/connection.c | 4 +-
mama/c_cpp/src/c/conflation/connection_int.h | 10 +-
mama/c_cpp/src/c/conflation/manager.c | 10 +-
mama/c_cpp/src/c/conflation/manager_int.h | 4 +-
mama/c_cpp/src/c/conflation/serverconnection_int.h | 8 +-
mama/c_cpp/src/c/datetime.c | 5 +-
mama/c_cpp/src/c/fileutils.c | 1 -
mama/c_cpp/src/c/ft.c | 203 ++------
mama/c_cpp/src/c/imagerequest.c | 2 +-
mama/c_cpp/src/c/imagerequest.h | 2 +-
mama/c_cpp/src/c/mama.c | 163 ++----
mama/c_cpp/src/c/mama/conflation/manager.h | 16 +-
mama/c_cpp/src/c/mama/datetime.h | 4 +-
mama/c_cpp/src/c/mama/fielddesc.h | 4 +-
mama/c_cpp/src/c/mama/ft.h | 4 +-
mama/c_cpp/src/c/mama/mama.h | 14 +-
mama/c_cpp/src/c/mama/msg.h | 14 +-
mama/c_cpp/src/c/mama/msgfield.h | 4 +-
mama/c_cpp/src/c/mama/subscriptiontype.h | 3 +-
mama/c_cpp/src/c/mama/timezone.h | 4 +-
mama/c_cpp/src/c/mama/types.h | 2 +-
mama/c_cpp/src/c/msg.c | 2 +-
mama/c_cpp/src/c/payload/avismsg/avismsgimpl.c | 4 +-
mama/c_cpp/src/c/playback/playbackFileParser.c | 31 +-
mama/c_cpp/src/c/playback/playbackFileParser.h | 10 +-
mama/c_cpp/src/c/playback/playbackpublisher.h | 5 +-
mama/c_cpp/src/c/priceimpl.c | 19 +-
mama/c_cpp/src/c/queue.c | 2 +-
mama/c_cpp/src/c/senderId.c | 7 +-
mama/c_cpp/src/c/stat.c | 2 +-
mama/c_cpp/src/c/statsgenerator.c | 2 +-
mama/c_cpp/src/c/statslogger.c | 4 +-
mama/c_cpp/src/c/syncresponder.c | 4 +-
mama/c_cpp/src/c/timezone.c | 36 +-
mama/c_cpp/src/examples/c/mamainboxc.c | 15 +-
mama/c_cpp/src/examples/c/mamaio.c | 9 +-
mama/c_cpp/src/examples/c/mamalistenc.c | 56 +-
mama/c_cpp/src/examples/c/mamaproxyc.c | 46 +-
mama/c_cpp/src/examples/c/mamapublisherc.c | 19 +-
mama/c_cpp/src/examples/c/mamasubscriberc.c | 20 +-
.../src/examples/c/mamasymbollistsubscriberc.c | 44 +-
mama/c_cpp/src/regression/c/tools/basicinbox.c | 31 +-
mama/c_cpp/src/regression/c/tools/basicpub.c | 50 +--
mama/c_cpp/src/regression/c/tools/basicsub.c | 61 +--
93 files changed, 3329 insertions(+), 2228 deletions(-)
delete mode 100644 common/c_cpp/src/c/environment.c
create mode 100644 common/c_cpp/src/c/linux/environment.c
create mode 100644 common/c_cpp/src/c/linux/machine.c
create mode 100644 common/c_cpp/src/c/linux/network.c
create mode 100644 common/c_cpp/src/c/linux/platform.c
create mode 100644 common/c_cpp/src/c/linux/port.h
create mode 100644 common/c_cpp/src/c/linux/wConfig.h
create mode 100644 common/c_cpp/src/c/linux/wInterlocked.h
create mode 100644 common/c_cpp/src/c/linux/wSemaphore.c
delete mode 100644 common/c_cpp/src/c/platform.c
delete mode 100644 common/c_cpp/src/c/wSemaphore.c
create mode 100644 common/c_cpp/src/c/windows/environment.c
create mode 100644 common/c_cpp/src/c/windows/lock.h
create mode 100644 common/c_cpp/src/c/windows/machine_win.c
create mode 100644 common/c_cpp/src/c/windows/mmap.h
create mode 100644 common/c_cpp/src/c/windows/network.c
create mode 100644 common/c_cpp/src/c/windows/platform.c
create mode 100644 common/c_cpp/src/c/windows/port.c
create mode 100644 common/c_cpp/src/c/windows/port.h
create mode 100644 common/c_cpp/src/c/windows/wSemaphore.c
create mode 100644 common/c_cpp/src/c/windows/wombat/targetsxs.h
create mode 100644 common/c_cpp/src/c/windows/wombat/wConfig.h
create mode 100644 common/c_cpp/src/c/windows/wombat/wInterlocked.h
mode change 100644 => 120000 common/c_cpp/src/c/wombat/wConfig.h
delete mode 100644 common/c_cpp/src/c/wombat/wInterlocked.h

--
1.7.7.6


[PATCH] [mama] Use "ft" as default FT transport name

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

When setting up fault tolerance use "ft" as the transport name for reading
properties if the call does not provide a transport.

Signed-off-by: Michael Schonberg <mschonberg@nyx.com>
---
mama/c_cpp/src/c/ft.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/mama/c_cpp/src/c/ft.c b/mama/c_cpp/src/c/ft.c
index efbc16d..0a7931c 100644
--- a/mama/c_cpp/src/c/ft.c
+++ b/mama/c_cpp/src/c/ft.c
@@ -946,18 +946,23 @@ multicastFt_setup (

mamaFtMemberImpl* impl = (mamaFtMemberImpl*) member;

- if (!impl || !groupName || !transport)
+ if (!impl || !groupName)
return MAMA_STATUS_INVALID_ARG;

/* Get the transport name. */
- status = mamaTransport_getName(transport, &transportName);
- if((MAMA_STATUS_OK != status) || (NULL == transportName) || ('\0' ==
- transportName[0]))
+ if(transport)
{
- mama_log (MAMA_LOG_LEVEL_ERROR, "MAMA multicast FT: the transport name "
- "is invalid");
- return MAMA_STATUS_INVALID_ARG;
+ status = mamaTransport_getName(transport, &transportName);
+ if((MAMA_STATUS_OK != status) || (NULL == transportName) || ('\0' ==
+ transportName[0]))
+ {
+ mama_log (MAMA_LOG_LEVEL_ERROR, "MAMA multicast FT: the transport name "
+ "is invalid");
+ return MAMA_STATUS_INVALID_ARG;
+ }
}
+ else
+ transportName = "ft";

ftInterface = multicastFt_getProperty(propertyName,
"mama.multicast.transport.%s.interface", transportName);
--
1.7.7.6


Re: Getting a bridge build version

Mark Spielman
 

Mike,

I believe it makes most sense for me to use the mama/version.h as it seems to be the correct place to get version information. One follow on question. Why even in the tar package I downloaded from OpenMAMA for 1.1 is the following still present in mama/version.h.

#define MAMA_VERSION "openmama DEVRELEASE.."

And this is the value I get when I print the global mama_version. To me this should be set to something like 5.0.3rc11 which would be the concat of:

#define MAMA_VERSION_MAJOR 5
#define MAMA_VERSION_MINOR 0
#define MAMA_VERSION_RELEASE 3rc11

Cheers,
Mark

-----Original Message-----
From: Michael Schonberg [mailto:mikeschonberg@gmail.com] On Behalf Of Michael Schonberg
Sent: Tuesday, March 27, 2012 5:00 PM
To: Mark Spielman
Cc: openmama-dev@lists.openmama.org
Subject: Re: [Openmama-dev] Getting a bridge build version

On 03/27/2012 01:12 PM, Mark Spielman wrote:
I'm interested in any best practices for getting a build version to report as part of the bridgeImpl->bridgeGetVersion() method. I've found what looks to be a reasonable version in the file: mama/c_cpp/config.h. I believe this is what AVIS is using. In OpenMAMA 1.1 it's currently set to:
It is largely up to the bridge implementor; however, it makes sense to identify both the version of the bridge code and the underlying middleware if it is available.

/* Version number of package */
#define VERSION "5.0.3rc11"
Avis does not provide version information through the API so the implementor simply used the MAMA version that was current at the time. Future releases of the Avis bridge will return "not implemented" for this method.

Or it seems I could just reuse the version from mama/c_cpp/c/src/c/mama/version.h as the equivalent of a bridge build version. Any suggestions? I'd like to be able to track a version that identifies a particular build of bridge code to correlate this for bug tracking.

Cheers,
Mark


Mark Spielman
Development Lead, Solace Systems Professional Services
+1-613-271-1010 x1021
mark.spielman@solacesystems.com<mailto:mark.spielman@solacesystems.com
www.solacesystems.com<http://www.solacesystems.com/>




_______________________________________________
Openmama-dev mailing list
Openmama-dev@lists.openmama.org
http://lists.openmama.org/listinfo/openmama-dev
Regards,
-Mike


Re: [Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary

Mark Spielman
 

Hi Mike,

I appreciate the feedback. Below is an updated patch. Let me know if there are any other suggested edits.

Cheers,
Mark

---------

This patch introduces a .gitignore file to force git to skip known build artifacts when displaying status information.

Signed-off-by: Mark Spielman <mark.spielman@solacesystems.com>

---

iff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d018ef3
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,76 @@
+# Compiled source #
+###################
+*.com
+*.class
+*.dll
+*.exe
+*.o
+*.so
+*.lo
+*.la
+
+# Temporary Directories #
+#########################
+.dep*
+.lib*
+
+# GNU Automake #
+################
+Makefile
+Makefile.in
+
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store*
+ehthumbs.db
+Icon?
+Thumbs.db
+*~
+*.swp
+
+# OpenMAMA Specific #
+# ###################
+common/c_cpp/aclocal.m4
+common/c_cpp/autom4te.cache/
+common/c_cpp/config.h
+common/c_cpp/config.h.in
+common/c_cpp/config.status
+common/c_cpp/configure
+common/c_cpp/etc/
+common/c_cpp/libtool
+common/c_cpp/src/c/properties.c
+common/c_cpp/src/c/version.h
+common/c_cpp/stamp-h1
+mama/c_cpp/aclocal.m4
+mama/c_cpp/autom4te.cache/
+mama/c_cpp/config.h
+mama/c_cpp/config.h.in
+mama/c_cpp/config.status
+mama/c_cpp/configure
+mama/c_cpp/doc/c/
+mama/c_cpp/doxyconfig-c
+mama/c_cpp/etc/
+mama/c_cpp/libtool
+mama/c_cpp/src/c/bridge/solace/Makefile.am
+mama/c_cpp/src/c/mama/version.h
+mama/c_cpp/src/c/version.c
+mama/c_cpp/stamp-h1

-----Original Message-----
From: openmama-dev-bounces@lists.openmama.org [mailto:openmama-dev-bounces@lists.openmama.org] On Behalf Of Michael Schonberg
Sent: Tuesday, March 27, 2012 8:03 PM
To: openmama-dev@lists.openmama.org
Subject: Re: [Openmama-dev] [Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary

This is very useful.

I would remove mama/c_cpp/config.h.in~ and add *~ and *.swp for temporary files generated by vi.

-Mike

[snip]

_______________________________________________
Openmama-dev mailing list
Openmama-dev@lists.openmama.org
http://lists.openmama.org/listinfo/openmama-dev


Re: [Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary

Michael Schonberg <mschonberg@...>
 

This is very useful.

I would remove mama/c_cpp/config.h.in~ and add *~ and *.swp for temporary
files generated by vi.

-Mike

On 03/27/2012 01:53 PM, Mark Spielman wrote:
This patch introduces a .gitignore file to force git to skip known build artifacts when displaying status information.

Signed-off-by: Mark Spielman <mark.spielman@solacesystems.com>

---

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..182bfd9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,75 @@
+# Compiled source #
+###################
+*.com
+*.class
+*.dll
+*.exe
+*.o
+*.so
+*.lo
+*.la
+
+# Temporary Directories #
+#########################
+.dep*
+.lib*
+
# Temporary Files
#################
*.swp
*~

+# GNU Automake #
+################
+Makefile
+Makefile.in
+
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store*
+ehthumbs.db
+Icon?
+Thumbs.db
+
+# OpenMAMA Specific #
+# ###################
+common/c_cpp/aclocal.m4
+common/c_cpp/autom4te.cache/
+common/c_cpp/config.h
+common/c_cpp/config.h.in
+common/c_cpp/config.status
+common/c_cpp/configure
+common/c_cpp/etc/
+common/c_cpp/libtool
+common/c_cpp/src/c/properties.c
+common/c_cpp/src/c/version.h
+common/c_cpp/stamp-h1
+mama/c_cpp/aclocal.m4
+mama/c_cpp/autom4te.cache/
+mama/c_cpp/config.h
+mama/c_cpp/config.h.in
+mama/c_cpp/config.status
+mama/c_cpp/configure
+mama/c_cpp/doc/c/
+mama/c_cpp/doxyconfig-c
+mama/c_cpp/etc/
+mama/c_cpp/libtool
+mama/c_cpp/src/c/bridge/solace/Makefile.am
+mama/c_cpp/src/c/mama/version.h
+mama/c_cpp/src/c/version.c
+mama/c_cpp/stamp-h1
_______________________________________________
Openmama-dev mailing list
Openmama-dev@lists.openmama.org
http://lists.openmama.org/listinfo/openmama-dev


Re: Getting a bridge build version

Michael Schonberg <mschonberg@...>
 

On 03/27/2012 01:12 PM, Mark Spielman wrote:
I'm interested in any best practices for getting a build version to report as part of the bridgeImpl->bridgeGetVersion() method. I've found what looks to be a reasonable version in the file: mama/c_cpp/config.h. I believe this is what AVIS is using. In OpenMAMA 1.1 it's currently set to:
It is largely up to the bridge implementor; however, it makes sense to identify both the version of the bridge code and the underlying middleware if it is available.

/* Version number of package */
#define VERSION "5.0.3rc11"
Avis does not provide version information through the API so the implementor simply used the MAMA version that was current at the time. Future releases of the Avis bridge will return "not implemented" for this method.

Or it seems I could just reuse the version from mama/c_cpp/c/src/c/mama/version.h as the equivalent of a bridge build version. Any suggestions? I'd like to be able to track a version that identifies a particular build of bridge code to correlate this for bug tracking.

Cheers,
Mark


Mark Spielman
Development Lead, Solace Systems Professional Services
+1-613-271-1010 x1021
mark.spielman@solacesystems.com<mailto:mark.spielman@solacesystems.com>
www.solacesystems.com<http://www.solacesystems.com/>





_______________________________________________
Openmama-dev mailing list
Openmama-dev@lists.openmama.org
http://lists.openmama.org/listinfo/openmama-dev
Regards,
-Mike


[Patch 1.1 1/1] OpenMAMA (C): Adding .gitignore to force git to skip known build artifacts in status summary

Mark Spielman
 

This patch introduces a .gitignore file to force git to skip known build artifacts when displaying status information.

Signed-off-by: Mark Spielman <mark.spielman@solacesystems.com>

---

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..182bfd9
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,75 @@
+# Compiled source #
+###################
+*.com
+*.class
+*.dll
+*.exe
+*.o
+*.so
+*.lo
+*.la
+
+# Temporary Directories #
+#########################
+.dep*
+.lib*
+
+# GNU Automake #
+################
+Makefile
+Makefile.in
+
+# Packages #
+############
+# it's better to unpack these files and commit the raw source
+# git has its own built in compression methods
+*.7z
+*.dmg
+*.gz
+*.iso
+*.jar
+*.rar
+*.tar
+*.zip
+
+# Logs and databases #
+######################
+*.log
+*.sql
+*.sqlite
+
+# OS generated files #
+######################
+.DS_Store*
+ehthumbs.db
+Icon?
+Thumbs.db
+
+# OpenMAMA Specific #
+# ###################
+common/c_cpp/aclocal.m4
+common/c_cpp/autom4te.cache/
+common/c_cpp/config.h
+common/c_cpp/config.h.in
+common/c_cpp/config.status
+common/c_cpp/configure
+common/c_cpp/etc/
+common/c_cpp/libtool
+common/c_cpp/src/c/properties.c
+common/c_cpp/src/c/version.h
+common/c_cpp/stamp-h1
+mama/c_cpp/aclocal.m4
+mama/c_cpp/autom4te.cache/
+mama/c_cpp/config.h
+mama/c_cpp/config.h.in
+mama/c_cpp/config.h.in~
+mama/c_cpp/config.status
+mama/c_cpp/configure
+mama/c_cpp/doc/c/
+mama/c_cpp/doxyconfig-c
+mama/c_cpp/etc/
+mama/c_cpp/libtool
+mama/c_cpp/src/c/bridge/solace/Makefile.am
+mama/c_cpp/src/c/mama/version.h
+mama/c_cpp/src/c/version.c
+mama/c_cpp/stamp-h1


Getting a bridge build version

Mark Spielman
 

I’m interested in any best practices for getting a build version to report as part of the bridgeImpl->bridgeGetVersion() method.  I’ve found what looks to be a reasonable version in the file: mama/c_cpp/config.h.  I believe this is what AVIS is using.  In OpenMAMA 1.1 it’s currently set to:

 

/* Version number of package */

#define VERSION "5.0.3rc11"

 

Or it seems I could just reuse the version from mama/c_cpp/c/src/c/mama/version.h as the equivalent of a bridge build version.  Any suggestions?  I’d like to be able to track a version that identifies a particular build of bridge code to correlate this for bug tracking.

 

Cheers,

Mark

 

 

Mark Spielman

Development Lead, Solace Systems Professional Services
+1-613-271-1010 x1021

mark.spielman@...

www.solacesystems.com

 

 


Re: Bridge Error Code

Mike Schonberg <mschonberg@...>
 

Mark,

 

MAMA_STATUS_PLATFORM is used for generic bridge errors. It might be useful to add some more specific error codes as well.

 

Regards,

-Mike

 

From: openmama-dev-bounces@... [mailto:openmama-dev-bounces@...] On Behalf Of Mark Spielman
Sent: Tuesday, March 27, 2012 12:08 PM
To: openmama-dev@...
Subject: [Openmama-dev] Bridge Error Code

 

I am in the process of implementing a bridge support for a new middleware component in openMAMA.  During implementation I have a need to return a sensible mama_status code for a generic bridge error.  Something equivalent to handling unexpected internal errors.  I see there’s the following in status.h:

 

/* No bridge */

    MAMA_STATUS_NO_BRIDGE_IMPL              = 26,

 

But I’m looking more for something like: MAMA_STATUS_BRDIGE_INTERNAL_ERROR

 

Can you suggest what the appropriate code is.  In general I will try to match up to existing codes wherever possible.

 

Cheers,

Mark

 

 

 

Mark Spielman

Development Lead, Solace Systems Professional Services
+1-613-271-1010 x1021

mark.spielman@...

www.solacesystems.com

 

 




Please consider the environment before printing this email.

Visit our website at http://www.nyse.com
*****************************************************************************
Note: The information contained in this message and any attachment to it is privileged, confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by replying to the message, and please delete it from your system. Thank you. NYSE Euronext.




Bridge Error Code

Mark Spielman
 

I am in the process of implementing a bridge support for a new middleware component in openMAMA.  During implementation I have a need to return a sensible mama_status code for a generic bridge error.  Something equivalent to handling unexpected internal errors.  I see there’s the following in status.h:

 

/* No bridge */

    MAMA_STATUS_NO_BRIDGE_IMPL              = 26,

 

But I’m looking more for something like: MAMA_STATUS_BRDIGE_INTERNAL_ERROR

 

Can you suggest what the appropriate code is.  In general I will try to match up to existing codes wherever possible.

 

Cheers,

Mark

 

 

 

Mark Spielman

Development Lead, Solace Systems Professional Services
+1-613-271-1010 x1021

mark.spielman@...

www.solacesystems.com

 

 


[PATCH 4/4] Make sure that we load and unload bridges properly

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

These changes ensure that we hold the lock while opening and closing payload and
messaging brdiges. Additionally, we store the shared library handles so we can
close them when cleaning up.

Signed-off-by: John Gray <jgray@nyx.com>
---
mama/c_cpp/src/c/mama.c | 100 ++++++++++++++++++++++++++++++++++++++++------
1 files changed, 87 insertions(+), 13 deletions(-)

diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index 2623f29..0657286 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -187,6 +187,11 @@ static mamaImpl gImpl = {{0}, {0}, {0}, {0}, 0, PTHREAD_MUTEX_INITIALIZER};
/* Private Function Prototypes. */
/* ************************************************************************* */

+static mama_status
+mama_loadBridgeWithPathInternal (mamaBridge* impl,
+ const char* middlewareName,
+ const char* path,
+ uint8_t lock);

/* Description : This function will free any memory associated with a
* mamaApplicationContext object but will not free the
@@ -332,8 +337,12 @@ static mama_status mamaInternal_loadStatsPublisher ()
}

/* Will load the bridge if its not already loaded */
+ /* Lock is alread acquired at this point */
if (MAMA_STATUS_OK !=
- (status = mama_loadBridge (&bridge, statsLogMiddlewareName)))
+ (status = mama_loadBridgeWithPathInternal (&bridge,
+ statsLogMiddlewareName,
+ NULL,
+ 0)))
{
mama_log (MAMA_LOG_LEVEL_ERROR,
"mamaInternal_loadStatsLogger(): ",
@@ -914,12 +923,12 @@ mama_openWithPropertiesCount (const char* path,
mama_log (MAMA_LOG_LEVEL_SEVERE,
"mama_openWithProperties(): "
"Error connecting to Entitlements Server");
+ pthread_mutex_unlock (&gImpl.myLock);
mama_close();

if (count)
*count = gImpl.myRefCount;

- pthread_mutex_unlock (&gImpl.myLock);
return result;
}
#endif /* WITH_ENTITLEMENTS */
@@ -1151,6 +1160,11 @@ mama_closeCount (unsigned int* count)
/* mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*)
* gImpl.myPayloads [(uint8_t)payload];*/
gImpl.myPayloads[(uint8_t)payload] = NULL;
+ if(gImpl.myPayloadLibraries[(uint8_t)payload])
+ {
+ closeSharedLib (gImpl.myPayloadLibraries[(uint8_t)payload]);
+ gImpl.myPayloadLibraries[(uint8_t)payload] = NULL;
+ }
}

gDefaultPayload = NULL;
@@ -1250,8 +1264,10 @@ mama_closeCount (unsigned int* count)
mamaMiddleware_convertToString (middleware));

}
+ gImpl.myBridges[middleware] = NULL;
+ closeSharedLib (gImpl.myBridgeLibraries[middleware]);
+ gImpl.myBridgeLibraries[middleware] = NULL;
}
- gImpl.myBridges[middleware] = NULL;
}

/* The properties must not be closed down until after the bridges have been destroyed. */
@@ -1796,9 +1812,11 @@ mamaInternal_registerBridge (mamaBridge bridge,
middlewareName ? middlewareName : "");
return;
}
-
+
+ pthread_mutex_lock (&gImpl.myLock);
gImpl.myBridges[middleware] = bridge;
((mamaBridgeImpl*)(bridge))->mRefCount = 0;
+ pthread_mutex_unlock (&gImpl.myLock);
}

mama_status
@@ -1813,8 +1831,9 @@ mama_setDefaultPayload (char id)
}

mama_status
-mama_loadPayloadBridge (mamaPayloadBridge* impl,
- const char* payloadName)
+mama_loadPayloadBridgeInternal (mamaPayloadBridge* impl,
+ const char* payloadName,
+ uint8_t lock)
{
char bridgeImplName [256];
char initFuncName [256];
@@ -1829,6 +1848,9 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
snprintf (bridgeImplName, 256, "mama%simpl",
payloadName);

+ if (lock)
+ pthread_mutex_lock (&gImpl.myLock);
+
bridgeLib = openSharedLib (bridgeImplName, NULL);

if (!bridgeLib)
@@ -1839,6 +1861,8 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
"Could not open payload bridge library [%s] [%s]",
bridgeImplName ? bridgeImplName : "",
getLibError());
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -1855,11 +1879,18 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
initFuncName ? initFuncName : "",
bridgeImplName ? bridgeImplName : "");
closeSharedLib (bridgeLib);
+
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
+
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

if (MAMA_STATUS_OK != (status = initFunc (impl, &payloadChar)))
{
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
+
return status;
}

@@ -1867,6 +1898,10 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
{
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_loadPayloadBridge(): Error in [%s] ", initFuncName);
+
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
+
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -1876,7 +1911,11 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
"mama_loadPayloadBridge(): "
"Payload bridge %s already loaded",
payloadName);
- return MAMA_STATUS_OK;
+
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
+
+ return MAMA_STATUS_OK;
}

gImpl.myPayloads [(int)payloadChar] = *impl;
@@ -1891,10 +1930,20 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
"mama_loadPayloadBridge(): "
"Sucessfully loaded %s payload bridge from library [%s]",
payloadName, bridgeImplName);
+
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);

return MAMA_STATUS_OK;
}

+mama_status
+mama_loadPayloadBridge (mamaPayloadBridge* impl,
+ const char* payloadName)
+{
+ return mama_loadPayloadBridgeInternal (impl, payloadName, 1);
+}
+
int
mamaInternal_generateLbmStats ()
{
@@ -1910,9 +1959,10 @@ mama_loadBridge (mamaBridge* impl,
}

mama_status
-mama_loadBridgeWithPath (mamaBridge* impl,
- const char* middlewareName,
- const char* path)
+mama_loadBridgeWithPathInternal (mamaBridge* impl,
+ const char* middlewareName,
+ const char* path,
+ uint8_t lock)
{
char bridgeImplName [256];
char initFuncName [256];
@@ -1934,15 +1984,19 @@ mama_loadBridgeWithPath (mamaBridge* impl,
"mama_loadBridge(): Invalid middleware [%s]",
middlewareName);
}
+
+ if (lock)
+ pthread_mutex_lock (&gImpl.myLock);

/* Check if a bridge has already been initialized for the middleware */
if (gImpl.myBridges [middleware])
{
*impl = gImpl.myBridges [middleware];
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_OK;
}

-
snprintf (bridgeImplName, 256, "mama%simpl",
middlewareName);

@@ -1950,7 +2004,6 @@ mama_loadBridgeWithPath (mamaBridge* impl,

if (!bridgeLib)
{
-
if (path)
{
mama_log (MAMA_LOG_LEVEL_ERROR,
@@ -1968,6 +2021,8 @@ mama_loadBridgeWithPath (mamaBridge* impl,
bridgeImplName ? bridgeImplName : "",
getLibError());
}
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -1984,6 +2039,8 @@ mama_loadBridgeWithPath (mamaBridge* impl,
initFuncName ? initFuncName : "",
bridgeImplName ? bridgeImplName : "");
closeSharedLib (bridgeLib);
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -1993,6 +2050,8 @@ mama_loadBridgeWithPath (mamaBridge* impl,
{
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_loadBridge(): Error in [%s] ", initFuncName);
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -2005,22 +2064,37 @@ mama_loadBridgeWithPath (mamaBridge* impl,
result = ((mamaBridgeImpl*)(*impl))->bridgeOpen (*impl);

if (MAMA_STATUS_OK != result)
+ {
+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
+ }

if (((mamaBridgeImpl*)(*impl))->bridgeGetDefaultPayloadId(&payloadName, &payloadId) == MAMA_STATUS_OK)
{
if (!gImpl.myPayloads [(uint8_t)payloadId])
{
mamaPayloadBridge payloadImpl;
- mama_loadPayloadBridge (&payloadImpl,payloadName);
+ mama_loadPayloadBridgeInternal (&payloadImpl,payloadName,0);
}
}

gImpl.myBridges [middleware] = *impl;
+ gImpl.myBridgeLibraries [middleware] = bridgeLib;

+ if (lock)
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_OK;
}

+mama_status
+mama_loadBridgeWithPath (mamaBridge* impl,
+ const char* middlewareName,
+ const char* path)
+{
+ return mama_loadBridgeWithPathInternal(impl, middlewareName, path, 1);
+}
+
/*
* Function pointer type for calling getVersion in the wrapper
*/
--
1.7.5.4


[PATCH 3/4] Added Per-bridge Reference Count

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

Added a reference count to mamaBridgeImpl struct. mama_start() and mama_stop()
increment and decrement this reference count to determine when initialization is
required and when the bridges can be unloaded. The internal registerBridge()
method ensures that it is properly initialized to 0.

Signed-off-by: John Gray <jgray@nyx.com>
---
mama/c_cpp/src/c/bridge.h | 3 +++
mama/c_cpp/src/c/mama.c | 41 +++++++++++++++++++++++++++++++++++++----
2 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/mama/c_cpp/src/c/bridge.h b/mama/c_cpp/src/c/bridge.h
index 5a9588b..5ab7707 100644
--- a/mama/c_cpp/src/c/bridge.h
+++ b/mama/c_cpp/src/c/bridge.h
@@ -681,6 +681,9 @@ typedef mama_status
*/
typedef struct mamaBridgeImpl
{
+ /* Used by mama_start() and mama_stop(). */
+ unsigned int mRefCount;
+
/*The default event queue is now middleware specific. (Originally global)*/
mamaQueue mDefaultEventQueue;

diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index 7b6add9..2623f29 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -1295,6 +1295,8 @@ mama_status
mama_start (mamaBridge bridgeImpl)
{
mamaBridgeImpl* impl = (mamaBridgeImpl*)bridgeImpl;
+ mama_status rval = MAMA_STATUS_OK;
+ unsigned int prevRefCnt = 0;

if (!impl)
{
@@ -1310,8 +1312,25 @@ mama_start (mamaBridge bridgeImpl)
return MAMA_STATUS_INVALID_QUEUE;
}

- /*Delegate to the bridge specific implementation*/
- return impl->bridgeStart (impl->mDefaultEventQueue);
+ pthread_mutex_lock(&gImpl.myLock);
+ prevRefCnt = impl->mRefCount++;
+ pthread_mutex_unlock(&gImpl.myLock);
+
+ if (prevRefCnt > 0)
+ return MAMA_STATUS_OK;
+
+ /* Delegate to the bridge specific implementation */
+ /* Can't hold lock because bridgeStart blocks */
+ rval = impl->bridgeStart (impl->mDefaultEventQueue);
+
+ if (rval != MAMA_STATUS_OK)
+ {
+ pthread_mutex_lock(&gImpl.myLock);
+ impl->mRefCount--;
+ pthread_mutex_unlock(&gImpl.myLock);
+ }
+
+ return rval;
}

struct startBackgroundClosure
@@ -1385,6 +1404,7 @@ mama_status
mama_stop (mamaBridge bridgeImpl)
{
mamaBridgeImpl* impl = (mamaBridgeImpl*)bridgeImpl;
+ mama_status rval = MAMA_STATUS_OK;

if (!impl)
{
@@ -1402,7 +1422,19 @@ mama_stop (mamaBridge bridgeImpl)
}

/*Delegate to the bridge specific implementation*/
- return impl->bridgeStop (impl->mDefaultEventQueue);
+ pthread_mutex_lock(&gImpl.myLock);
+ if (impl->mRefCount > 0)
+ {
+ impl->mRefCount--;
+ if(impl->mRefCount == 0)
+ {
+ rval = impl->bridgeStop (impl->mDefaultEventQueue);
+ if (MAMA_STATUS_OK != rval)
+ impl->mRefCount++;
+ }
+ }
+ pthread_mutex_unlock(&gImpl.myLock);
+ return rval;
}

/**
@@ -1749,7 +1781,6 @@ enableEntitlements (const char **servers)

#endif

-
void
mamaInternal_registerBridge (mamaBridge bridge,
const char* middlewareName)
@@ -1767,6 +1798,7 @@ mamaInternal_registerBridge (mamaBridge bridge,
}

gImpl.myBridges[middleware] = bridge;
+ ((mamaBridgeImpl*)(bridge))->mRefCount = 0;
}

mama_status
@@ -1779,6 +1811,7 @@ mama_setDefaultPayload (char id)

return MAMA_STATUS_OK;
}
+
mama_status
mama_loadPayloadBridge (mamaPayloadBridge* impl,
const char* payloadName)
--
1.7.5.4


[PATCH 2/4] Add mama_openWithPropertiesCount() and mama_closeCount()

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

These methods take an additonal unsigned int* parameter that upon return
contains the the reference count for mama_openXXX() and mama_closeXXX(). This
allows applications to performa one-time global initialization when
the int is 1 and mama_openWithPropertiesCount() returns MAMA_STATUS_OK. Likewise
applications can clean up global data when the count is zero and
mama_closeCount() returns MAMA_STATUS_OK.

Signed-off-by: John Gray <jgray@nyx.com>
---
mama/c_cpp/src/c/mama.c | 58 +++++++++++++++++++++++++++++++++++------
mama/c_cpp/src/c/mama/mama.h | 45 ++++++++++++++++++++++++++++++++
2 files changed, 94 insertions(+), 9 deletions(-)

diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index cecfa4a..7b6add9 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -643,8 +643,9 @@ mamaInternal_getDefaultPayload (void)
}

mama_status
-mama_openWithProperties (const char* path,
- const char* filename)
+mama_openWithPropertiesCount (const char* path,
+ const char* filename,
+ unsigned int* count)
{
mama_status result = MAMA_STATUS_OK;
mama_size_t numBridges = 0;
@@ -695,6 +696,10 @@ mama_openWithProperties (const char* path,
{
if (MAMA_STATUS_OK == result)
gImpl.myRefCount++;
+
+ if (count)
+ *count = gImpl.myRefCount;
+
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
@@ -757,6 +762,9 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_openWithProperties(): "
"Could not create stats generator.");
+ if (count)
+ *count = gImpl.myRefCount;
+
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
@@ -874,6 +882,9 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_SEVERE,
"mama_openWithProperties(): "
"At least one bridge must be specified");
+ if (count)
+ *count = gImpl.myRefCount;
+
pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}
@@ -883,6 +894,9 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_SEVERE,
"mama_openWithProperties(): "
"At least one payload must be specified");
+ if (count)
+ *count = gImpl.myRefCount;
+
pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}
@@ -901,6 +915,10 @@ mama_openWithProperties (const char* path,
"mama_openWithProperties(): "
"Error connecting to Entitlements Server");
mama_close();
+
+ if (count)
+ *count = gImpl.myRefCount;
+
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
@@ -938,6 +956,8 @@ mama_openWithProperties (const char* path,
if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge,
&statsGenQueue)))
{
+ if (count)
+ *count = gImpl.myRefCount;
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
@@ -948,6 +968,8 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_openWithProperties(): "
"Could not set queue for stats generator.");
+ if (count)
+ *count = gImpl.myRefCount;
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
@@ -957,12 +979,16 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_openWithProperties(): "
"Failed to enable stats logging");
+ if (count)
+ *count = gImpl.myRefCount;
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
}

gImpl.myRefCount++;
+ if (count)
+ *count = gImpl.myRefCount;
pthread_mutex_unlock (&gImpl.myLock);
return result;
}
@@ -972,7 +998,14 @@ mama_open ()
{
/*Passing NULL as path and filename will result in the
default behaviour - mama.properties on $WOMBAT_PATH*/
- return mama_openWithProperties (NULL, NULL);
+ return mama_openWithPropertiesCount (NULL, NULL, NULL);
+}
+
+mama_status
+mama_openWithProperties (const char* path,
+ const char* filename)
+{
+ return mama_openWithPropertiesCount (path, filename, NULL);
}

mama_status
@@ -1079,7 +1112,7 @@ mama_getVersion (mamaBridge bridgeImpl)
}

mama_status
-mama_close ()
+mama_closeCount (unsigned int* count)
{
mama_status result = MAMA_STATUS_OK;
mamaMiddleware middleware = 0;
@@ -1088,6 +1121,8 @@ mama_close ()
pthread_mutex_lock (&gImpl.myLock);
if (gImpl.myRefCount == 0)
{
+ if (count)
+ *count = gImpl.myRefCount;
pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_OK;
}
@@ -1113,11 +1148,8 @@ mama_close ()
/* Look for a bridge for each of the payloads and close them */
for (payload = 0; payload != MAMA_PAYLOAD_MAX; ++payload)
{
- mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gImpl.myPayloads [(uint8_t)payload];
- if (impl)
- {
-
- }
+ /* mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*)
+ * gImpl.myPayloads [(uint8_t)payload];*/
gImpl.myPayloads[(uint8_t)payload] = NULL;
}

@@ -1244,10 +1276,18 @@ mama_close ()
mama_freeAppContext(&appContext);

}
+ if (count)
+ *count = gImpl.myRefCount;
pthread_mutex_unlock (&gImpl.myLock);
return result;
}

+mama_status
+mama_close (void)
+{
+ return mama_closeCount (NULL);
+}
+
/**
* Start processing messages.
*/
diff --git a/mama/c_cpp/src/c/mama/mama.h b/mama/c_cpp/src/c/mama/mama.h
index 658bce6..557ac2c 100644
--- a/mama/c_cpp/src/c/mama/mama.h
+++ b/mama/c_cpp/src/c/mama/mama.h
@@ -220,6 +220,40 @@ extern "C"
extern mama_status
mama_openWithProperties (const char* path,
const char* filename);
+ /**
+ * Initialize MAMA.
+ *
+ * Allows users of the API to override the default behavior of mama_open()
+ * where a file mama.properties is required to be located in the directory
+ * specified by \$WOMBAT_PATH.
+ *
+ * The properties file must have the same structure as a standard
+ * mama.properties file.
+ *
+ * If null is passed as the path the API will look for the properties file on
+ * the \$WOMBAT_PATH.
+ *
+ * If null is passed as the filename the API will look for the default
+ * filename of mama.properties.
+ *
+ * The count value on return will be the number of times that mama_openXxx()
+ * has ben invoked successfully. Applicatiins can use this to perform
+ * one-time initialization when the value is 1 and the return is
+ * MAMA_STATUS_OK
+ *
+ * @param path Fully qualified path to the directory containing the properties
+ * file
+ * @param filename The name of the file containing MAMA properties.
+ * @param count The number of times mama_OpenXXX() has been called
+ * successfully.
+ *
+ * @return mama_status Whether the call was successful or not.
+ */
+ MAMAExpDLL
+ extern mama_status
+ mama_openWithPropertiesCount (const char* path,
+ const char* filename,
+ unsigned int* count);

/**
* Set a specific property for the API.
@@ -291,6 +325,17 @@ extern "C"
MAMAExpDLL
extern mama_status
mama_close (void);
+
+ /**
+ * Close MAMA and free all associated resource.
+ *
+ * @param count Filled with the number of times mama has been opened
+ * successfully. Applications can perform global one-time cleanup when this
+ * value is 0 and the return value is MAMA_STATUS_OK.
+ */
+ MAMAExpDLL
+ extern mama_status
+ mama_closeCount (unsigned int* count);

/**
* Return the version information for the library.
--
1.7.5.4


[PATCH 1/4] Added locking around mama_open() and mama_close()

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

Improved the reference counting logic and added locking around mama_open() and
mama_close(). The change ensures that all initialization (one-time) and cleanup
only occurs once. It also ensures that the reference count never goes belowe
zero.

Signed-off-by: John Gray <jgray@nyx.com>
---
mama/c_cpp/src/c/mama.c | 39 ++++++++++++++++++++++++++++-----------
1 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index 4142c16..cecfa4a 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -654,6 +654,8 @@ mama_openWithProperties (const char* path,
const char* statsLogging = "false";
const char* catchCallbackExceptions = NULL;

+ pthread_mutex_lock (&gImpl.myLock);
+
if (pthread_key_create(&last_err_key, NULL) != 0)
{
mama_log (MAMA_LOG_LEVEL_NORMAL, "WARNING!!! - CANNOT ALLOCATE KEY FOR ERRORS");
@@ -689,7 +691,14 @@ mama_openWithProperties (const char* path,
"********************************************************");
#endif

- if (gImpl.myRefCount++) return result;
+ if (0 != gImpl.myRefCount)
+ {
+ if (MAMA_STATUS_OK == result)
+ gImpl.myRefCount++;
+ pthread_mutex_unlock (&gImpl.myLock);
+ return result;
+ }
+ /* Code after this point is one-time initialization */

#ifdef WITH_INACTIVE_CHECK
mama_log (MAMA_LOG_LEVEL_WARN,
@@ -748,10 +757,10 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_openWithProperties(): "
"Could not create stats generator.");
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}

-
globalLogging = properties_Get (gProperties, "mama.statslogging.global.logging");
globalPublishing = properties_Get (gProperties, "mama.statslogging.global.publishing");
transportLogging = properties_Get (gProperties, "mama.statslogging.transport.logging");
@@ -842,7 +851,6 @@ mama_openWithProperties (const char* path,
}
}

-
if (mamaInternal_statsPublishingEnabled())
{
mamaInternal_loadStatsPublisher();
@@ -866,16 +874,16 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_SEVERE,
"mama_openWithProperties(): "
"At least one bridge must be specified");
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

if (!gDefaultPayload)
{
-
-
mama_log (MAMA_LOG_LEVEL_SEVERE,
"mama_openWithProperties(): "
"At least one payload must be specified");
+ pthread_mutex_unlock (&gImpl.myLock);
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

@@ -893,6 +901,7 @@ mama_openWithProperties (const char* path,
"mama_openWithProperties(): "
"Error connecting to Entitlements Server");
mama_close();
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}
#endif /* WITH_ENTITLEMENTS */
@@ -929,6 +938,7 @@ mama_openWithProperties (const char* path,
if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge,
&statsGenQueue)))
{
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}
}
@@ -938,6 +948,7 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_openWithProperties(): "
"Could not set queue for stats generator.");
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -946,10 +957,13 @@ mama_openWithProperties (const char* path,
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_openWithProperties(): "
"Failed to enable stats logging");
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}
}

+ gImpl.myRefCount++;
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}

@@ -1071,7 +1085,14 @@ mama_close ()
mamaMiddleware middleware = 0;
int payload = 0;

- if( !--gImpl.myRefCount )
+ pthread_mutex_lock (&gImpl.myLock);
+ if (gImpl.myRefCount == 0)
+ {
+ pthread_mutex_unlock (&gImpl.myLock);
+ return MAMA_STATUS_OK;
+ }
+
+ if (!--gImpl.myRefCount)
{
#ifdef WITH_ENTITLEMENTS
if( gEntitlementClient != 0 )
@@ -1120,7 +1141,6 @@ mama_close ()
gUnknownMsgStat = NULL;
}

-
if (gMessageStat)
{
mamaStat_destroy (gMessageStat);
@@ -1224,10 +1244,7 @@ mama_close ()
mama_freeAppContext(&appContext);

}
- if (gImpl.myRefCount < 0)
- {
- gImpl.myRefCount = 0;
- }
+ pthread_mutex_unlock (&gImpl.myLock);
return result;
}

--
1.7.5.4


[PATCH] MAMA: Move global bridge data to struct

Michael Schonberg <mschonberg@...>
 

From: Mike Schonberg <mschonberg@nyx.com>

This is in preparation for adding improved reference counting and locking around
mama_open(), and mama_close() to enable them to be called safely from
multi-threaded applications.

A number of compiler warnings are also fixed.

Signed-off-by: John Gray <jgray@nyx.com>
---
mama/c_cpp/src/c/mama.c | 106 +++++++++++++++++++++++++++++------------------
1 files changed, 66 insertions(+), 40 deletions(-)

diff --git a/mama/c_cpp/src/c/mama.c b/mama/c_cpp/src/c/mama.c
index ee0d6a0..4142c16 100644
--- a/mama/c_cpp/src/c/mama.c
+++ b/mama/c_cpp/src/c/mama.c
@@ -128,7 +128,6 @@ static const char* gHostName = NULL;

static void lookupIPAddress (void);

-static int gRefCount = 0;

wproperty_t gProperties = 0;
static mamaStatsLogger gStatsPublisher = NULL;
@@ -148,11 +147,9 @@ mamaStat gRvMsgsStat;

#define MAMA_PAYLOAD_MAX CHAR_MAX

-static mamaBridge gMamaBridges [MAMA_MIDDLEWARE_MAX];
-static mamaPayloadBridge gMamaPayloads [MAMA_PAYLOAD_MAX];
static mamaPayloadBridge gDefaultPayload = NULL;

-pthread_key_t last_err_key;
+static pthread_key_t last_err_key;

/**
* struct mamaApplicationGroup
@@ -164,16 +161,39 @@ typedef struct mamaAppContext_
const char* myApplicationClass;
} mamaApplicationContext;

+/**
+ * This structure contains data needed to control starting and stopping of
+ * mama.
+ *
+ * TODO: Access to this structure will ultimately be protected by a reference
+ * count and a lock.
+ */
+typedef struct mamaImpl_
+{
+ mamaBridge myBridges[MAMA_MIDDLEWARE_MAX];
+ mamaPayloadBridge myPayloads[MAMA_PAYLOAD_MAX];
+ LIB_HANDLE myBridgeLibraries[MAMA_MIDDLEWARE_MAX];
+ LIB_HANDLE myPayloadLibraries[MAMA_PAYLOAD_MAX];
+ unsigned int myRefCount;
+ pthread_mutex_t myLock;
+} mamaImpl;

static mamaApplicationContext appContext;
static char mama_ver_string[256];

+static mamaImpl gImpl = {{0}, {0}, {0}, {0}, 0, PTHREAD_MUTEX_INITIALIZER};
+
+/* ************************************************************************* */
+/* Private Function Prototypes. */
+/* ************************************************************************* */
+
+
/* Description : This function will free any memory associated with a
* mamaApplicationContext object but will not free the
* object itself.
* Arguments : context [I] The context object to free.
*/
-void
+static void
mama_freeAppContext(mamaApplicationContext *context)
{
/* Only continue if the object is valid. */
@@ -348,7 +368,7 @@ mamaInternal_createStatsPublisher ()
statsLogMiddlewareName = "wmw";
}

- bridge = gMamaBridges[mamaMiddleware_convertFromString (statsLogMiddlewareName)];
+ bridge = gImpl.myBridges[mamaMiddleware_convertFromString (statsLogMiddlewareName)];

if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge,
&queue)))
@@ -596,7 +616,7 @@ mamaInternal_findBridge ()

for (middleware = 0; middleware < MAMA_MIDDLEWARE_MAX; middleware++)
{
- bridge = gMamaBridges [middleware];
+ bridge = gImpl.myBridges [middleware];

if (bridge != NULL)
{
@@ -610,9 +630,10 @@ mamaInternal_findBridge ()
mamaPayloadBridge
mamaInternal_findPayload (char id)
{
- if (('\0' == id) || (MAMA_PAYLOAD_MAX < id)) return NULL;
+ if ('\0' == id)
+ return NULL;

- return gMamaPayloads[(uint8_t)id];
+ return gImpl.myPayloads[(uint8_t)id];
}

mamaPayloadBridge
@@ -668,7 +689,7 @@ mama_openWithProperties (const char* path,
"********************************************************");
#endif

- if (gRefCount++) return result;
+ if (gImpl.myRefCount++) return result;

#ifdef WITH_INACTIVE_CHECK
mama_log (MAMA_LOG_LEVEL_WARN,
@@ -831,10 +852,10 @@ mama_openWithProperties (const char* path,
/* Look for a bridge for each of the middlewares and open them */
for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware)
{
- mamaBridgeImpl* impl = (mamaBridgeImpl*) gMamaBridges [middleware];
+ mamaBridgeImpl* impl = (mamaBridgeImpl*) gImpl.myBridges [middleware];
if (impl)
{
- mama_log (MAMA_LOG_LEVEL_FINE, mama_getVersion (gMamaBridges[middleware]));
+ mama_log (MAMA_LOG_LEVEL_FINE, mama_getVersion (gImpl.myBridges[middleware]));
mamaQueue_enableStats(impl->mDefaultEventQueue);
++numBridges;
}
@@ -903,7 +924,7 @@ mama_openWithProperties (const char* path,
statsMiddleware = "wmw";
}

- bridge = gMamaBridges[mamaMiddleware_convertFromString (statsMiddleware)];
+ bridge = gImpl.myBridges[mamaMiddleware_convertFromString (statsMiddleware)];

if (MAMA_STATUS_OK != (result = mamaBridgeImpl_getInternalEventQueue (bridge,
&statsGenQueue)))
@@ -1050,7 +1071,7 @@ mama_close ()
mamaMiddleware middleware = 0;
int payload = 0;

- if( !--gRefCount )
+ if( !--gImpl.myRefCount )
{
#ifdef WITH_ENTITLEMENTS
if( gEntitlementClient != 0 )
@@ -1064,19 +1085,19 @@ mama_close ()

for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware)
{
- mamaBridge bridge = gMamaBridges[middleware];
+ mamaBridge bridge = gImpl.myBridges[middleware];
if (bridge)
mamaBridgeImpl_stopInternalEventQueue (bridge);
}
/* Look for a bridge for each of the payloads and close them */
for (payload = 0; payload != MAMA_PAYLOAD_MAX; ++payload)
{
- mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gMamaPayloads [(uint8_t)payload];
+ mamaPayloadBridgeImpl* impl = (mamaPayloadBridgeImpl*) gImpl.myPayloads [(uint8_t)payload];
if (impl)
{

}
- gMamaPayloads[(uint8_t)payload] = NULL;
+ gImpl.myPayloads[(uint8_t)payload] = NULL;
}

gDefaultPayload = NULL;
@@ -1166,11 +1187,11 @@ mama_close ()
/* Look for a bridge for each of the middlewares and close them */
for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware)
{
- mamaBridgeImpl* impl = (mamaBridgeImpl*) gMamaBridges [middleware];
+ mamaBridgeImpl* impl = (mamaBridgeImpl*) gImpl.myBridges [middleware];
if (impl)
{
if (MAMA_STATUS_OK != (
- (result = impl->bridgeClose (gMamaBridges[middleware]))))
+ (result = impl->bridgeClose (gImpl.myBridges[middleware]))))
{
mama_log (MAMA_LOG_LEVEL_ERROR,
"mama_close(): Error closing %s bridge.",
@@ -1178,7 +1199,7 @@ mama_close ()

}
}
- gMamaBridges[middleware] = NULL;
+ gImpl.myBridges[middleware] = NULL;
}

/* The properties must not be closed down until after the bridges have been destroyed. */
@@ -1203,9 +1224,9 @@ mama_close ()
mama_freeAppContext(&appContext);

}
- if (gRefCount < 0)
+ if (gImpl.myRefCount < 0)
{
- gRefCount = 0;
+ gImpl.myRefCount = 0;
}
return result;
}
@@ -1339,10 +1360,10 @@ mama_stopAll (void)
/* Look for a bridge for each of the middlewares and open them */
for (middleware = 0; middleware != MAMA_MIDDLEWARE_MAX; ++middleware)
{
- mamaBridgeImpl* impl = (mamaBridgeImpl*) gMamaBridges [middleware];
+ mamaBridgeImpl* impl = (mamaBridgeImpl*) gImpl.myBridges [middleware];
if (impl)
{
- status = mama_stop (gMamaBridges[middleware]);
+ status = mama_stop (gImpl.myBridges[middleware]);
if (MAMA_STATUS_OK != status)
{
mama_log (MAMA_LOG_LEVEL_ERROR,
@@ -1676,8 +1697,10 @@ void
mamaInternal_registerBridge (mamaBridge bridge,
const char* middlewareName)
{
- mamaMiddleware middleware =
- mamaMiddleware_convertFromString (middlewareName);
+ mamaMiddleware middleware;
+
+ middleware = mamaMiddleware_convertFromString (middlewareName);
+
if (middleware >= MAMA_MIDDLEWARE_MAX)
{
mama_log (MAMA_LOG_LEVEL_SEVERE,
@@ -1686,15 +1709,16 @@ mamaInternal_registerBridge (mamaBridge bridge,
return;
}

- gMamaBridges [middleware] = bridge;
+ gImpl.myBridges[middleware] = bridge;
}

mama_status
mama_setDefaultPayload (char id)
{
- if (('\0' == id) || (MAMA_PAYLOAD_MAX < id) || gMamaPayloads[(uint8_t)id] == NULL) return MAMA_STATUS_NULL_ARG;
+ if ('\0' == id || gImpl.myPayloads[(uint8_t)id] == NULL)
+ return MAMA_STATUS_NULL_ARG;

- gDefaultPayload = gMamaPayloads[(uint8_t)id];
+ gDefaultPayload = gImpl.myPayloads[(uint8_t)id];

return MAMA_STATUS_OK;
}
@@ -1756,7 +1780,7 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
return MAMA_STATUS_NO_BRIDGE_IMPL;
}

- if (gMamaPayloads [payloadChar])
+ if (gImpl.myPayloads [(int)payloadChar])
{
mama_log (MAMA_LOG_LEVEL_NORMAL,
"mama_loadPayloadBridge(): "
@@ -1765,7 +1789,8 @@ mama_loadPayloadBridge (mamaPayloadBridge* impl,
return MAMA_STATUS_OK;
}

- gMamaPayloads [payloadChar] = *impl;
+ gImpl.myPayloads [(int)payloadChar] = *impl;
+ gImpl.myPayloadLibraries [(int)payloadChar] = bridgeLib;

if (!gDefaultPayload)
{
@@ -1804,14 +1829,15 @@ mama_loadBridgeWithPath (mamaBridge* impl,
LIB_HANDLE bridgeLib = NULL;
bridge_createImpl initFunc = NULL;
char* payloadName = NULL;
- char payloadId = NULL;
+ char payloadId = '\0';
mama_status result = MAMA_STATUS_OK;
- mamaMiddleware middleware =
- mamaMiddleware_convertFromString (middlewareName);
+ mamaMiddleware middleware = 0;

if (!impl)
return MAMA_STATUS_NULL_ARG;

+ middleware = mamaMiddleware_convertFromString (middlewareName);
+
if (middleware >= MAMA_MIDDLEWARE_MAX)
{
mama_log (MAMA_LOG_LEVEL_ERROR,
@@ -1820,9 +1846,9 @@ mama_loadBridgeWithPath (mamaBridge* impl,
}

/* Check if a bridge has already been initialized for the middleware */
- if (gMamaBridges [middleware])
+ if (gImpl.myBridges [middleware])
{
- *impl = gMamaBridges [middleware];
+ *impl = gImpl.myBridges [middleware];
return MAMA_STATUS_OK;
}

@@ -1844,7 +1870,6 @@ mama_loadBridgeWithPath (mamaBridge* impl,
bridgeImplName ? bridgeImplName : "",
getLibError());
}
-
else
{
mama_log (MAMA_LOG_LEVEL_ERROR,
@@ -1889,18 +1914,19 @@ mama_loadBridgeWithPath (mamaBridge* impl,

result = ((mamaBridgeImpl*)(*impl))->bridgeOpen (*impl);

- if (MAMA_STATUS_OK != result) return result;
+ if (MAMA_STATUS_OK != result)
+ return result;

if (((mamaBridgeImpl*)(*impl))->bridgeGetDefaultPayloadId(&payloadName, &payloadId) == MAMA_STATUS_OK)
{
- if (!gMamaPayloads [(uint8_t)payloadId])
+ if (!gImpl.myPayloads [(uint8_t)payloadId])
{
mamaPayloadBridge payloadImpl;
mama_loadPayloadBridge (&payloadImpl,payloadName);
}
}

- gMamaBridges [middleware] = *impl;
+ gImpl.myBridges [middleware] = *impl;

return MAMA_STATUS_OK;
}
--
1.7.5.4

2221 - 2240 of 2305