improved structure and thread safety

This commit is contained in:
Jeff Hill
2003-02-12 19:06:15 +00:00
parent 234c515b05
commit 644e6eb273
78 changed files with 2692 additions and 4957 deletions

View File

@@ -8,12 +8,12 @@
* in file LICENSE that is included with this distribution.
\*************************************************************************/
//
// Example EPICS CA directory server
// Example EPICS CA directory server
//
//
// caServer
// |
// directoryServer
// caServer
// |
// directoryServer
//
//
@@ -27,6 +27,7 @@
//
// EPICS
//
#define epicsAssertAuthor "Jeff Hill johill@lanl.gov"
#define caNetAddrSock
#include "casdef.h"
#include "epicsAssert.h"
@@ -34,7 +35,7 @@
#ifndef NELEMENTS
# define NELEMENTS(A) (sizeof(A)/sizeof(A[0]))
# define NELEMENTS(A) (sizeof(A)/sizeof(A[0]))
#endif
class directoryServer;
@@ -44,24 +45,24 @@ class directoryServer;
//
class pvInfo {
public:
pvInfo (const char *pNameIn, sockaddr_in addrIn) :
addr(addrIn), pNext(pvInfo::pFirst)
{
pvInfo::pFirst = this;
this->pName = new char [strlen(pNameIn)+1u];
assert(this->pName);
strcpy(this->pName, pNameIn);
}
const struct sockaddr_in getAddr() const { return this->addr; }
const char *getName () const { return this->pName; }
const pvInfo *getNext () const { return this->pNext; }
static const pvInfo *getFirst () { return pvInfo::pFirst; }
pvInfo (const char *pNameIn, sockaddr_in addrIn) :
addr(addrIn), pNext(pvInfo::pFirst)
{
pvInfo::pFirst = this;
this->pName = new char [strlen(pNameIn)+1u];
assert(this->pName);
strcpy(this->pName, pNameIn);
}
const struct sockaddr_in getAddr() const { return this->addr; }
const char *getName () const { return this->pName; }
const pvInfo *getNext () const { return this->pNext; }
static const pvInfo *getFirst () { return pvInfo::pFirst; }
private:
struct sockaddr_in addr;
char *pName;
const pvInfo *pNext;
static const pvInfo *pFirst;
struct sockaddr_in addr;
char * pName;
const pvInfo * pNext;
static const pvInfo * pFirst;
};
//
@@ -77,41 +78,39 @@ private:
class pvEntry // X aCC 655
: public stringId, public tsSLNode<pvEntry> {
public:
pvEntry (const pvInfo &infoIn, directoryServer &casIn,
const char *pAliasName) :
stringId(pAliasName), info(infoIn), cas(casIn)
{
assert(this->stringId::resourceName()!=NULL);
}
pvEntry (const pvInfo &infoIn, directoryServer &casIn,
const char *pAliasName) :
stringId(pAliasName), info(infoIn), cas(casIn)
{
assert(this->stringId::resourceName()!=NULL);
}
inline ~pvEntry();
inline ~pvEntry();
const pvInfo &getInfo() const { return this->info; }
inline void destroy ();
const pvInfo &getInfo() const { return this->info; }
inline void destroy ();
private:
const pvInfo &info;
directoryServer &cas;
const pvInfo &info;
directoryServer &cas;
};
//
// directoryServer
//
class directoryServer : public caServer {
public:
directoryServer (const char * const pvPrefix, unsigned aliasCount);
~directoryServer();
void show (unsigned level) const;
pvExistReturn pvExistTest (const casCtx&, const char *pPVName);
directoryServer ( const char * const pvPrefix, unsigned aliasCount );
~directoryServer();
void show ( unsigned level ) const;
pvExistReturn pvExistTest ( const casCtx&, const char *pPVName );
void installAliasName (const pvInfo &info, const char *pAliasName);
inline void removeAliasName(pvEntry &entry);
void installAliasName ( const pvInfo &info, const char *pAliasName );
inline void removeAliasName ( pvEntry &entry );
private:
resTable<pvEntry,stringId> stringResTbl;
resTable < pvEntry, stringId > stringResTbl;
};
@@ -120,9 +119,9 @@ private:
//
inline void directoryServer::removeAliasName(pvEntry &entry)
{
pvEntry *pE;
pE = this->stringResTbl.remove(entry);
assert(pE = &entry);
pvEntry *pE;
pE = this->stringResTbl.remove(entry);
assert(pE = &entry);
}
//
@@ -130,7 +129,7 @@ inline void directoryServer::removeAliasName(pvEntry &entry)
//
inline pvEntry::~pvEntry()
{
this->cas.removeAliasName(*this);
this->cas.removeAliasName(*this);
}
//
@@ -138,9 +137,9 @@ inline pvEntry::~pvEntry()
//
inline void pvEntry::destroy ()
{
//
// always created with new
//
delete this;
//
// always created with new
//
delete this;
}

View File

@@ -13,10 +13,8 @@
#include "directoryServer.h"
#include "fdManager.h"
#define LOCAL static
LOCAL int parseDirectoryFile (const char *pFileName);
LOCAL int parseDirectoryFP (FILE *pf, const char *pFileName);
static int parseDirectoryFile (const char *pFileName);
static int parseDirectoryFP (FILE *pf, const char *pFileName);
#ifndef INADDR_NONE
#define INADDR_NONE (~0ul)
@@ -109,7 +107,7 @@ extern int main (int argc, const char **argv)
// <PV name> <host name or dotted ip address> [<optional IP port number>]
//
//
LOCAL int parseDirectoryFile (const char *pFileName)
static int parseDirectoryFile (const char *pFileName)
{
FILE *pf;
@@ -139,7 +137,7 @@ LOCAL int parseDirectoryFile (const char *pFileName)
// <PV name> <host name or dotted ip address> [<optional IP port number>]
//
//
LOCAL int parseDirectoryFP (FILE *pf, const char *pFileName)
static int parseDirectoryFP (FILE *pf, const char *pFileName)
{
pvInfo *pPVI;
char pvNameStr[128];
@@ -193,8 +191,8 @@ LOCAL int parseDirectoryFP (FILE *pf, const char *pFileName)
ipa.sin_port = 0u; // use the default CA server port
}
pPVI = new pvInfo (pvNameStr, ipa);
if (!pPVI) {
pPVI = new pvInfo ( pvNameStr, ipa );
if ( ! pPVI ) {
fprintf (stderr, "Unable to allocate space for a new PV in \"%s\" with PV=\"%s\" host=\"%s\"\n",
pFileName, pvNameStr, hostNameStr);
return -1;