summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1999-10-31 21:32:41 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1999-10-31 21:32:41 +0000
commit4319dd05b48bd894f40ace95f06b089419311aba (patch)
tree6e419551c7a35e9e7b06640ab6ec1e8f41ac1346
parent76e3bbf9e5ca21c2468c29367fad10b3910ed0e3 (diff)
downloadATCD-4319dd05b48bd894f40ace95f06b089419311aba.tar.gz
ChangeLogTag:Sun Oct 31 15:29:08 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
-rw-r--r--ChangeLog-99b7
-rw-r--r--ace/Capabilities.cpp358
-rw-r--r--ace/Capabilities.h177
-rw-r--r--ace/Capabilities.i52
-rw-r--r--ace/Makefile1
-rw-r--r--tests/Capabilities_Test.cfg5
-rw-r--r--tests/Capabilities_Test.cpp73
-rw-r--r--tests/Makefile1
-rw-r--r--tests/run_tests.lst1
9 files changed, 675 insertions, 0 deletions
diff --git a/ChangeLog-99b b/ChangeLog-99b
index b2f0de37335..5738408f4e2 100644
--- a/ChangeLog-99b
+++ b/ChangeLog-99b
@@ -1,3 +1,10 @@
+Sun Oct 31 15:29:08 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
+
+ * ace/Makefile,
+ * tests/run_tests.lst,
+ tests/Makefile (BIN): Added an entry for the new ACE_Capabilities
+ classes.
+
Fri Oct 29 21:09:49 1999 Ossama Othman <othman@cs.wustl.edu>
* man/html/Makefile.am:
diff --git a/ace/Capabilities.cpp b/ace/Capabilities.cpp
new file mode 100644
index 00000000000..163add04c32
--- /dev/null
+++ b/ace/Capabilities.cpp
@@ -0,0 +1,358 @@
+// $Id$
+
+#include "ace/Map_Manager.h"
+#include "ace/Capabilities.h"
+
+#define ACE_ESC ((char)0x1b)
+
+ACE_Capabilities::ACE_Capabilities (void)
+{
+}
+
+ACE_Capabilities::~ACE_Capabilities (void)
+{
+ this->resetcaps ();
+}
+
+const char *
+ACE_Capabilities::parse (const char *buf,
+ ACE_CString &cap)
+{
+ while (*buf!='\0' && *buf!=',')
+ {
+ if (*buf == '\\')
+ {
+ buf++;
+ if (*buf == 'E' || *buf == 'e')
+ {
+ cap += ACE_ESC;
+ buf++;
+ continue;
+ }
+ else if (*buf == 'r')
+ {
+ cap += '\r';
+ buf++;
+ continue;
+ }
+ else if (*buf == 'n')
+ {
+ cap += '\n';
+ buf++;
+ continue;
+ }
+ else if (*buf == 't')
+ {
+ cap += '\t';
+ buf++;
+ continue;
+ }
+ else if (*buf == '\\')
+ {
+ cap += *buf++;
+ continue;
+ }
+ if (isdigit(*buf))
+ {
+ int oc = 0;
+ for (int i = 0;
+ i < 3 && *buf && isdigit (*buf);
+ i++)
+ oc = oc * 8 + (*buf++ - '0');
+
+ cap += (char) oc;
+ continue;
+ }
+ }
+ cap += *buf++;
+ }
+ return buf;
+}
+
+const char *
+ACE_Capabilities::parse (const char *buf,
+ int &cap)
+{
+ int n = 0;
+
+ while (*buf && isdigit (*buf))
+ n = n * 10 + (*buf++ - '0');
+
+ cap = n;
+
+ return buf;
+}
+
+void
+ACE_Capabilities::resetcaps (void)
+{
+ for (ACE_Hash_Map_Iterator<ACE_CString, ACE_CapEntry *, ACE_Null_Mutex> iter (caps_);
+ !iter.done ();
+ iter.advance ())
+ {
+ ACE_Hash_Map_Entry<ACE_CString,ACE_CapEntry*> *entry;
+ iter.next (entry);
+ delete entry->int_id_;
+ }
+
+ caps_.close ();
+ caps_.open ();
+}
+
+int
+ACE_Capabilities::fillent (const char *buf)
+{
+ this->resetcaps ();
+ while (*buf)
+ {
+ ACE_CString s;
+ int n;
+ ACE_CString name;
+ ACE_CapEntry *ce;
+
+ // Skip blanks
+ while (*buf && isspace(*buf)) buf++;
+ // If we get end of line return
+
+ if (*buf=='\0')
+ break;
+
+ if (*buf=='#')
+ {
+ while (*buf && *buf!='\n')
+ buf++;
+ if (*buf=='\n')
+ buf++;
+ continue;
+ }
+ while(*buf && *buf != '='
+ && *buf!= '#'
+ && *buf != ',')
+ name += *buf++;
+
+ // If name is null.
+ switch (*buf)
+ {
+ case '=':
+ // String property
+ buf = this->parse (buf + 1, s);
+ ACE_NEW_RETURN (ce,
+ ACE_StringCapEntry (s),
+ -1);
+ if (caps_.bind (name, ce) == -1)
+ {
+ delete ce;
+ return -1;
+ }
+ break;
+ case '#':
+ // Integer property
+ buf = this->parse (buf + 1, n);
+ ACE_NEW_RETURN (ce,
+ ACE_IntCapEntry (n),
+ -1);
+ if (caps_.bind (name, ce) == -1)
+ {
+ delete ce;
+ return -1;
+ }
+ break;
+ case ',':
+ // Boolean
+ ACE_NEW_RETURN (ce,
+ ACE_BoolCapEntry (1),
+ -1);
+ if (caps_.bind (name, ce) == -1)
+ {
+ delete ce;
+ return -1;
+ }
+ break;
+ default:
+ return 0;
+ }
+
+ if (*buf++!=',')
+ return -1;
+ }
+
+ return 0;
+}
+
+int
+ACE_Capabilities::is_entry (const char *name,
+ const char *line)
+{
+ for (;;)
+ {
+ // Skip blanks or irrelevant characters
+ while (*line && isspace(*line))
+ line++;
+
+ // End of line reached
+ if (*line=='\0')
+ break;
+
+ // Build the entry name
+ ACE_CString nextname;
+ while (*line && *line != '|' && *line != ',')
+ nextname += *line++;
+
+ // We have found the required entry?
+ if (ACE_OS::strcmp (nextname.c_str (), name) == 0)
+ return 1;
+
+ // Skip puntuaction char if neccesary.
+ if (*line=='|' || *line==',')
+ line++;
+ else
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "Invalid entry\n"));
+ break;
+ }
+ }
+ return 0;
+}
+
+int
+ACE_Capabilities::getline (FILE *fp,
+ ACE_CString &line)
+
+{
+ int ch;
+
+ line.set (0, 0);
+
+ while ((ch = fgetc (fp)) != EOF && ch != '\n')
+ line += (char) ch;
+
+ if (ch == EOF && line.length () == 0)
+ return -1;
+ else
+ return 0;
+}
+
+int
+ACE_Capabilities::getval (const char *keyname,
+ ACE_CString &val)
+{
+ ACE_CapEntry* cap;
+ if (caps_.find (keyname, cap) == -1)
+ return -1;
+
+ ACE_StringCapEntry *scap =
+ ACE_dynamic_cast (ACE_StringCapEntry *,
+ cap);
+ if (scap == 0)
+ return -1;
+
+ val = scap->getval ();
+ return 0;
+}
+
+int
+ACE_Capabilities::getval (const char *keyname,
+ int &val)
+{
+ ACE_CapEntry *cap;
+ if (caps_.find (keyname, cap) == -1)
+ return -1;
+
+ ACE_IntCapEntry *icap =
+ ACE_dynamic_cast (ACE_IntCapEntry *,
+ cap);
+ if (icap != 0)
+ {
+ val = icap->getval ();
+ return 0;
+ }
+
+ ACE_BoolCapEntry *bcap =
+ ACE_dynamic_cast (ACE_BoolCapEntry *,
+ cap);
+
+ if (bcap == 0)
+ return -1;
+
+ val = bcap->getval ();
+ return 0;
+}
+
+static int
+is_empty (const char *line)
+{
+ while (*line && isspace (*line))
+ line++;
+
+ return *line == '\0' || *line == '#';
+}
+
+static int
+is_line (const char *line)
+{
+ while (*line && isspace (*line))
+ line++;
+
+ return *line != '\0';
+}
+
+int
+ACE_Capabilities::getent (const char *fname,
+ const char *name)
+{
+ FILE *fp = ACE_OS::fopen (fname,
+ "r");
+
+ if (fp == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Can't open %s file\n",
+ fname),
+ -1);
+
+ int done;
+ ACE_CString line;
+
+ while (!(done = (this->getline (fp, line) == -1))
+ && is_empty (line.c_str ()))
+ continue;
+
+ while (!done)
+ {
+ ACE_CString newline;
+ ACE_CString description;
+
+ while (!(done= (this->getline (fp, newline) == -1)))
+ if (is_line (newline.c_str ()))
+ description += newline;
+ else
+ break;
+
+ if (this->is_entry (name, line.c_str()))
+ {
+ ACE_OS::fclose (fp);
+ return this->fillent (description.c_str ());
+ }
+
+ line = newline;
+ while (!done && is_empty (line.c_str ()))
+ done = this->getline (fp, line) == -1;
+ }
+
+ ACE_OS::fclose (fp);
+ return -1;
+}
+
+#if defined(ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Equal_To<ACE_CString>;
+template class ACE_Hash<ACE_CString>;
+template class ACE_Hash_Map_Manager<ACE_CString,ACE_CapEntry*,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Iterator<ACE_CString,ACE_CapEntry*,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Reverse_Iterator<ACE_CString,ACE_CapEntry*,ACE_Null_Mutex>;
+// template class ACE_Hash_Map_Iterator_Base<ACE_CString,ACE_CapEntry*,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Entry<ACE_CString,ACE_CapEntry*>;
+template class ACE_Hash_Map_Manager_Ex<ACE_CString,ACE_CapEntry*,ACE_Hash<ACE_CString>,ACE_Equal_To<ACE_CString>,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Iterator_Base_Ex<ACE_CString,ACE_CapEntry*,ACE_Hash<ACE_CString>,ACE_Equal_To<ACE_CString>,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Iterator_Ex<ACE_CString,ACE_CapEntry*,ACE_Hash<ACE_CString>,ACE_Equal_To<ACE_CString>,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Reverse_Iterator_Ex<ACE_CString,ACE_CapEntry*,ACE_Hash<ACE_CString>,ACE_Equal_To<ACE_CString>,ACE_Null_Mutex>;
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/ace/Capabilities.h b/ace/Capabilities.h
new file mode 100644
index 00000000000..d2c1ec5f2bb
--- /dev/null
+++ b/ace/Capabilities.h
@@ -0,0 +1,177 @@
+/* -*- C++ -*- */
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// ace
+//
+// = FILENAME
+// Capabilities.h
+//
+// = AUTHOR
+// Arturo Montes <mitosys@colomsat.net.co>
+//
+// ============================================================================
+
+#ifndef ACE_CAPABILITIES_H
+#define ACE_CAPABILITIES_H
+
+#include "ace/OS.h"
+#include "ace/Synch.h"
+#include "ace/Hash_Map_Manager.h"
+#include "ace/Containers.h"
+#include "ace/SString.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+# pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+class ACE_Export ACE_CapEntry
+{
+ // = TITLE
+ // This class is the base class for all ACE Capabilities entry
+ // subclasses.
+ //
+ // = DESCRIPTION
+ // This class is not instantiable and does not provide accessors
+ // or methods. If you want to add a new kind of attribute you
+ // subclasses of this class and dynamic cast to proper subclass.
+protected:
+ enum
+ {
+ INTCAP = 0,
+ STRINGCAP = 1,
+ BOOLCAP = 2
+ };
+public:
+ virtual ~ACE_CapEntry (void);
+
+protected:
+ ACE_CapEntry (int captype);
+
+ int captype_;
+};
+
+class ACE_Export ACE_IntCapEntry : public ACE_CapEntry
+{
+ // = TITLE
+ // This class implement the ACE Integer Capability subclass.
+ //
+ // = DESCRIPTION
+ // This is a container class for ACE Capabilities integer container
+ // values.
+public:
+ ACE_IntCapEntry (int val);
+ int getval (void) const;
+
+protected:
+ int val_;
+};
+
+class ACE_Export ACE_StringCapEntry : public ACE_CapEntry
+{
+ // = TITLE
+ // This class implement the ACE String Capability subclass.
+ //
+ // = DESCRIPTION
+ // This is a container class for ACE Capabilities String container
+ // values.
+public:
+ ACE_StringCapEntry (const ACE_CString &val);
+ ACE_CString getval (void) const;
+
+protected:
+ ACE_CString val_;
+};
+
+class ACE_Export ACE_BoolCapEntry : public ACE_CapEntry
+{
+ // = TITLE
+ // This class implement the ACE Bool Capability subclass.
+ //
+ // = DESCRIPTION
+ // This is a container class for ACE Capabilities bool container
+ // values.
+public:
+ ACE_BoolCapEntry (int val);
+ int getval (void) const;
+
+protected:
+ int val_;
+};
+
+class ACE_Export ACE_Capabilities
+{
+ // = TITLE
+ // This class implement the ACE Capabilities.
+ //
+ // = DESCRIPTION
+ // This is a container class for ACE Capabilities
+ // values. Currently exist three different capability values:
+ // <ACE_IntCapEntry> (integer), <ACE_BoolCapEntry> (bool) and
+ // <ACE_StringCapEntry> (String). An <ACE_Capabilities> is a
+ // unordered set of pair = (<String>, <ACE_CapEntry> *). Where
+ // the first component is the name of capability and the second
+ // component is a pointer to the capability value container. A
+ // <FILE> is a container for <ACE_Capabilities>, the
+ // <ACE_Capabilities> has a name in the file, as a termcap file.
+public:
+ ACE_Capabilities (void);
+ // The Constructor
+
+ ~ACE_Capabilities(void);
+ // The Destructor
+
+public:
+ int getval (const char *ent,
+ ACE_CString &val);
+ // Get a string entry.
+
+ int getval (const char *ent,
+ int &val);
+ // Get an integer entry.
+
+ int getent (const char *fname,
+ const char *name);
+ // Get the ACE_Capabilities name from FILE fname and load the
+ // associated capabitily entries in map.
+
+protected:
+ // Parse an integer property
+ const char *parse (const char *buf,
+ int &cap);
+ // Parse a string property
+
+ const char *parse (const char *buf,
+ ACE_CString &cap);
+ // Fill the ACE_Capabilities with description in ent.
+
+ int fillent(const char *ent);
+ // Parse a cap entry
+
+ int parseent (const char *name,
+ char *line);
+ // Get a line from FILE input stream
+
+ int getline (FILE* fp,
+ ACE_CString &line);
+ // Is a valid entry
+
+ int is_entry (const char *name,
+ const char *line);
+ // Reset the set of capabilities
+
+ void resetcaps (void);
+ // Atributes.
+
+private:
+ ACE_Hash_Map_Manager<ACE_CString, ACE_CapEntry *, ACE_Null_Mutex> caps_;
+ // This is the set of ACE_CapEntry.
+};
+
+#if defined (__ACE_INLINE__)
+#include "ace/Capabilities.i"
+#endif /* __ACE_INLINE__ */
+
+#endif /* __ACE_CAPABILITIES_H__ */
diff --git a/ace/Capabilities.i b/ace/Capabilities.i
new file mode 100644
index 00000000000..b9287004892
--- /dev/null
+++ b/ace/Capabilities.i
@@ -0,0 +1,52 @@
+/* -*- C++ -*- */
+// $Id$
+
+ACE_INLINE
+ACE_CapEntry::ACE_CapEntry (int captype)
+ : captype_ (captype)
+{
+}
+
+ACE_INLINE
+ACE_CapEntry::~ACE_CapEntry (void)
+{
+}
+
+ACE_INLINE
+ACE_IntCapEntry::ACE_IntCapEntry (int val)
+ : ACE_CapEntry (INTCAP),
+ val_ (val)
+{
+}
+
+ACE_INLINE int
+ACE_IntCapEntry::getval (void) const
+{
+ return val_;
+}
+
+ACE_INLINE
+ACE_StringCapEntry::ACE_StringCapEntry (const ACE_CString &val)
+ : ACE_CapEntry (STRINGCAP),
+ val_(val)
+{
+}
+
+ACE_INLINE ACE_CString
+ACE_StringCapEntry::getval (void) const
+{
+ return val_;
+}
+
+ACE_INLINE
+ACE_BoolCapEntry::ACE_BoolCapEntry (int val)
+ : ACE_CapEntry (BOOLCAP),
+ val_(val)
+{
+}
+
+ACE_INLINE int
+ACE_BoolCapEntry::getval (void) const
+{
+ return val_;
+}
diff --git a/ace/Makefile b/ace/Makefile
index b245f2d2848..f03d3eba6a9 100644
--- a/ace/Makefile
+++ b/ace/Makefile
@@ -17,6 +17,7 @@ UTILS_FILES = \
Active_Map_Manager \
Arg_Shifter \
ARGV \
+ Capabilities \
Containers \
Dirent \
Dynamic \
diff --git a/tests/Capabilities_Test.cfg b/tests/Capabilities_Test.cfg
new file mode 100644
index 00000000000..6c5d612620e
--- /dev/null
+++ b/tests/Capabilities_Test.cfg
@@ -0,0 +1,5 @@
+Config|Esta entrada reservada para la configuracion,
+ bool,
+ integer#2,
+ string=000030,
+
diff --git a/tests/Capabilities_Test.cpp b/tests/Capabilities_Test.cpp
new file mode 100644
index 00000000000..9b788193c37
--- /dev/null
+++ b/tests/Capabilities_Test.cpp
@@ -0,0 +1,73 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// tests
+//
+// = FILENAME
+// Capabilities_Test.cpp
+//
+// = DESCRIPTION
+// This is a test that makes sure the <ACE_Capabililties> class
+// works correctly.
+//
+// = AUTHOR
+// Arturo Montes <mitosys@colomsat.net.co>
+//
+// ============================================================================
+
+ACE_RCSID(tests, Capabilities_Test, "$Id$")
+
+#if defined(__BORLANDC__) && __BORLANDC__ >= 0x0530
+USELIB("..\ace\aced.lib");
+//---------------------------------------------------------------------------
+#endif /* defined(__BORLANDC__) && __BORLANDC__ >= 0x0530 */
+
+#include "ace/Capabilities.h"
+
+static int
+load_config (void)
+{
+ char *config = "captest.cfg";
+
+ ACE_Capabilities caps;
+ if (caps.getent (config,
+ "Config") == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Can't read %s",
+ config),
+ 1);
+
+ int b = 0;
+ caps.getval ("bool", b);
+ ACE_DEBUG ((LM_DEBUG,
+ "bool = %d\n",
+ b));
+
+ int n = 0;
+ caps.getval ("integer", n);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "integer = %d\n",
+ n));
+
+ ACE_CString s;
+ caps.getval ("string", s);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "string = %s\n",
+ s.c_str ()));
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ ACE_START_TEST (ASYS_TEXT ("Capabilities_Test"));
+
+ int result = load_config ();
+
+ ACE_END_TEST;
+ return result;
+}
diff --git a/tests/Makefile b/tests/Makefile
index 43561d3bab8..2cff7e470eb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -17,6 +17,7 @@ BIN = Aio_Platform_Test \
Cache_Map_Manager_Test \
Cached_Accept_Conn_Test \
Cached_Conn_Test \
+ Capabilities \
CDR_File_Test \
CDR_Test \
Collection_Test \
diff --git a/tests/run_tests.lst b/tests/run_tests.lst
index 12a4e318f95..0e1be1d45a9 100644
--- a/tests/run_tests.lst
+++ b/tests/run_tests.lst
@@ -1,5 +1,6 @@
Basic_Types_Test
chorus/Env_Value_Test
+Capabilities_Test
Atomic_Op_Test
Object_Manager_Test
CDR_File_Test