cdev-1.7.2n
This commit is contained in:
15
extensions/cdevGenericServer/cdevTagMap/Makefile
Executable file
15
extensions/cdevGenericServer/cdevTagMap/Makefile
Executable file
@@ -0,0 +1,15 @@
|
||||
ARCH = OS
|
||||
SHOBJ = NO
|
||||
|
||||
include ../include/makeinclude/Makefile.$(ARCH)
|
||||
|
||||
APPNAME = "Tag Map Source"
|
||||
CXXINCLUDES = -I./
|
||||
LIBS = $(CDEVLIBS) $(OSLIBS)
|
||||
TARGETS = $(BASEBIN)/cdevTagMapTest
|
||||
|
||||
targets: $(TARGETS)
|
||||
|
||||
$(BASEBIN)/cdevTagMapTest: $(OBJDIR)/cdevTagMap.o $(OBJDIR)/cdevTagMapTest.o
|
||||
$(LINK.cc) $^ -o $@ $(LIBS)
|
||||
|
||||
21
extensions/cdevGenericServer/cdevTagMap/NMakefile.mak
Normal file
21
extensions/cdevGenericServer/cdevTagMap/NMakefile.mak
Normal file
@@ -0,0 +1,21 @@
|
||||
.SUFFIXES: .cc .obj
|
||||
|
||||
APPNAME = Tag Map Source
|
||||
ARCH = WINNT-4.0
|
||||
BINARIES = $(BASEBIN)\cdevTagMapTest.exe
|
||||
|
||||
include ..\include\makeinclude\Makefile.WINNT-4.0
|
||||
|
||||
CXXEXTRA = /D "GENERIC_SERVER_API= "
|
||||
CXXINCLUDES = /I .\\
|
||||
TARGETS = $(BASEBIN)\cdevTagMapTest.exe
|
||||
|
||||
targets : $(TARGETS)
|
||||
|
||||
$(BASEBIN)\cdevTagMapTest.exe : .exec\$(TARGETDIR)\cdevTagMap.obj .exec\$(TARGETDIR)\cdevTagMapTest.obj
|
||||
-@if exist $@ erase $@
|
||||
@echo ^ ^ ^ ^ ^ ^ =^> Linking $(@F)
|
||||
$(LINK) $(CDEVLIB)\cdev.lib\
|
||||
$(LINK_EXE_FLAGS) /out:$@ $?
|
||||
@echo ^ ^ ^ ^ ^ ^ ^ ^ ^ Done...
|
||||
|
||||
221
extensions/cdevGenericServer/cdevTagMap/cdevTagMap.cc
Executable file
221
extensions/cdevGenericServer/cdevTagMap/cdevTagMap.cc
Executable file
@@ -0,0 +1,221 @@
|
||||
#include <cdevTagMap.h>
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevTagMap::cdevTagMap :
|
||||
// * This is the constructor for the cdevTagMap class.
|
||||
// *****************************************************************************
|
||||
cdevTagMap::cdevTagMap ( void )
|
||||
: cnt(0),
|
||||
maximum(0),
|
||||
local(NULL),
|
||||
remote(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevTagMap::cdevTagMap :
|
||||
// * This is the destructor for the cdevTagMap class.
|
||||
// *****************************************************************************
|
||||
cdevTagMap::~cdevTagMap ( void )
|
||||
{
|
||||
if(local !=NULL) free(local);
|
||||
if(remote!=NULL) free(remote);
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevTagMap::updateTagMap :
|
||||
// * This method will read the names and integers from a cdevData object and
|
||||
// * will then pass these values to the updateTagMap method for processing.
|
||||
// *
|
||||
// * For standardization the tag integers are placed in tag 1, and the
|
||||
// * tag strings are placed in tag 2...
|
||||
// *****************************************************************************
|
||||
void cdevTagMap::updateTagMap ( cdevData & data )
|
||||
{
|
||||
char ** names;
|
||||
int * tags;
|
||||
size_t nameCnt=0, tagCnt=0;
|
||||
|
||||
if(data.getElems(1, &tagCnt)==CDEV_SUCCESS &&
|
||||
data.getElems(2, &nameCnt)==CDEV_SUCCESS &&
|
||||
tagCnt>0 && tagCnt==nameCnt)
|
||||
{
|
||||
names = new char *[nameCnt];
|
||||
tags = new int [tagCnt];
|
||||
memset(names, 0, sizeof(char *)*nameCnt);
|
||||
data.get(1, tags);
|
||||
data.get(2, names);
|
||||
updateTagMap(names, tags, nameCnt);
|
||||
while(nameCnt>0)
|
||||
{
|
||||
--nameCnt;
|
||||
delete names[nameCnt];
|
||||
}
|
||||
delete names;
|
||||
delete tags;
|
||||
}
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevTagMap::updateTagMap :
|
||||
// * This method will create a mapping of the differences between the tags
|
||||
// * specified in the user provided array and the tags that are stored
|
||||
// * within cdevData.
|
||||
// *****************************************************************************
|
||||
void cdevTagMap::updateTagMap ( char ** names, int * tags, int count )
|
||||
{
|
||||
// *********************************************************************
|
||||
// * Process each item in the names array from last to first.
|
||||
// *********************************************************************
|
||||
while((--count)>=0)
|
||||
{
|
||||
int localTag = -1;
|
||||
|
||||
// *************************************************************
|
||||
// * Determine if a tag that is identified by the names[count]
|
||||
// * string exists in the cdevData Global Tag Table. If it
|
||||
// * does, copy its integer representation into the localTag
|
||||
// * variable.
|
||||
// *************************************************************
|
||||
if(cdevData::tagC2I(names[count], &localTag)!=CDEV_SUCCESS)
|
||||
{
|
||||
// *****************************************************
|
||||
// * If the string does not already exist in the
|
||||
// * cdevData Global Tag Table, then attempt to add it.
|
||||
// *
|
||||
// * If the specified integer is in use locally by
|
||||
// * another cdevData tag - then the value will be
|
||||
// * incremented until an open slot is found.
|
||||
// *****************************************************
|
||||
char * s;
|
||||
localTag = tags[count];
|
||||
while(cdevData::tagI2C(localTag, s)==CDEV_SUCCESS)
|
||||
{
|
||||
localTag++;
|
||||
}
|
||||
cdevData::insertTag(localTag, names[count]);
|
||||
}
|
||||
|
||||
// *************************************************************
|
||||
// * If the local integer tag value differs from the remote
|
||||
// * integer tag value, then this tag must be added to the
|
||||
// * list.
|
||||
// *************************************************************
|
||||
if(localTag != tags[count])
|
||||
{
|
||||
int idx;
|
||||
|
||||
// *****************************************************
|
||||
// * Walk through the list and determine if the tag
|
||||
// * has already been added to the list...
|
||||
// *****************************************************
|
||||
for(idx=0; idx<cnt && remote[idx]!=tags[count]; idx++);
|
||||
|
||||
// *****************************************************
|
||||
// * If the tag does not already exist in the list,
|
||||
// * then do the following.
|
||||
// *****************************************************
|
||||
if(idx>=cnt)
|
||||
{
|
||||
// *********************************************
|
||||
// * If the internal arrays have not yet been
|
||||
// * allocated, then allocate a default number
|
||||
// * of entries (64).
|
||||
// *********************************************
|
||||
if(maximum==0)
|
||||
{
|
||||
maximum=64;
|
||||
local = (int *)malloc(maximum*sizeof(int));
|
||||
remote = (int *)malloc(maximum*sizeof(int));
|
||||
}
|
||||
// *********************************************
|
||||
// * If the internal arrays are already filled
|
||||
// * by the existing entries, then double the
|
||||
// * size of the arrays.
|
||||
// *********************************************
|
||||
else if(idx>=maximum)
|
||||
{
|
||||
maximum*=2;
|
||||
local = (int *)realloc(local, maximum*sizeof(int));
|
||||
remote = (int *)realloc(remote, maximum*sizeof(int));
|
||||
}
|
||||
|
||||
// *********************************************
|
||||
// * Populate the new entry with the mismatch
|
||||
// * data and increment the total number of
|
||||
// * mismatches.
|
||||
// *********************************************
|
||||
local [idx] = localTag;
|
||||
remote[idx] = tags[count];
|
||||
cnt = idx+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevTagMap::swapTags :
|
||||
// * This method is used to swap between two sets of tags... If a tag
|
||||
// * listed in the outTags array is used in the cdevData item, its tag will
|
||||
// * be converted to the corresponding value in the inTags array.
|
||||
// *****************************************************************************
|
||||
void cdevTagMap::swapTags ( cdevData & data, int *inTags, int *outTags, int count)
|
||||
{
|
||||
int tag;
|
||||
int changeCount = 0;
|
||||
cdevDataIterator iter(&data);
|
||||
|
||||
iter.init();
|
||||
do {
|
||||
int idx;
|
||||
for(idx=0, tag=iter.tag(); idx<count && tag!=outTags[idx]; idx++);
|
||||
if(idx<count)
|
||||
{
|
||||
data.changeTag(tag, -1*inTags[idx]);
|
||||
changeCount++;
|
||||
}
|
||||
} while(++iter != 0);
|
||||
|
||||
if(changeCount)
|
||||
{
|
||||
iter.init();
|
||||
do
|
||||
{
|
||||
if((tag=iter.tag())<0) data.changeTag(tag, -1*tag);
|
||||
} while(++iter!=0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * cdevTagMap::asciiDump :
|
||||
// * This mechanism is used to perform an ascii dump of the contents of a
|
||||
// * cdevtagMap structure.
|
||||
// *****************************************************************************
|
||||
void cdevTagMap::asciiDump (FILE * fp )
|
||||
{
|
||||
fprintf(fp, "----------------------------------------------------------\n");
|
||||
fprintf(fp, " Diagnostic Dump of CDEV Tag Map\n");
|
||||
fprintf(fp, "----------------------------------------------------------\n\n");
|
||||
fprintf(fp, "Number of Mismatches : %i\n", cnt);
|
||||
fprintf(fp, "Allocated Maximum Mismatches : %i\n", maximum);
|
||||
if(cnt) {
|
||||
fprintf(fp, "\nMismatch Table:\n\n");
|
||||
fprintf(fp, "\tTag Name Local ID Remote ID\n");
|
||||
fprintf(fp, "\t--------------------------------------------------\n");
|
||||
for(int i=0; i<cnt; i++)
|
||||
{
|
||||
char * s;
|
||||
cdevData::tagI2C(local[i], s);
|
||||
fprintf(fp, "\t%-26.26s%-13i%i\n", s, local[i], remote[i]);
|
||||
}
|
||||
fprintf(fp, "\t--------------------------------------------------\n\n");
|
||||
}
|
||||
fprintf(fp, "----------------------------------------------------------\n");
|
||||
fprintf(fp, " End of Diagnostic Dump of CDEV Tag Map\n");
|
||||
fprintf(fp, "----------------------------------------------------------\n\n");
|
||||
fflush(fp);
|
||||
}
|
||||
|
||||
31
extensions/cdevGenericServer/cdevTagMap/cdevTagMap.h
Executable file
31
extensions/cdevGenericServer/cdevTagMap/cdevTagMap.h
Executable file
@@ -0,0 +1,31 @@
|
||||
#include <cdevPlatforms.h>
|
||||
#include <cdevData.h>
|
||||
|
||||
|
||||
// *****************************************************************************
|
||||
// * class cdevTagMap:
|
||||
// * The purpose of the cdevTagMap is to allow rapid translation between
|
||||
// * the cdev tag tables that within different processes.
|
||||
// *
|
||||
// * This class provides the capability to switch back and forth from the
|
||||
// * local tag values to the remote tag values.
|
||||
// *****************************************************************************
|
||||
class GENERIC_SERVER_API cdevTagMap
|
||||
{
|
||||
private:
|
||||
int cnt;
|
||||
int maximum;
|
||||
int * local;
|
||||
int * remote;
|
||||
|
||||
public:
|
||||
cdevTagMap ( void );
|
||||
~cdevTagMap ( void );
|
||||
void updateTagMap ( cdevData & data );
|
||||
void updateTagMap ( char ** names, int * tags, int count );
|
||||
void swapTags ( cdevData & data, int *inTags, int *outTags, int count);
|
||||
void localToRemote ( cdevData & data ) { if(cnt) swapTags(data, remote, local, cnt); }
|
||||
void remoteToLocal ( cdevData & data ) { if(cnt) swapTags(data, local, remote, cnt); }
|
||||
void asciiDump ( FILE * fp = stdout );
|
||||
};
|
||||
|
||||
58
extensions/cdevGenericServer/cdevTagMap/cdevTagMapTest.cc
Executable file
58
extensions/cdevGenericServer/cdevTagMap/cdevTagMapTest.cc
Executable file
@@ -0,0 +1,58 @@
|
||||
#include <cdevTagMap.h>
|
||||
|
||||
char * version1Names[] =
|
||||
{
|
||||
"Version 1 Tag 100",
|
||||
"Version 1 Tag 101",
|
||||
"Version 1 Tag 102",
|
||||
"Version 1 Tag 103"
|
||||
};
|
||||
|
||||
int version1Tags[] =
|
||||
{
|
||||
100, 101, 102, 103
|
||||
};
|
||||
|
||||
char * version2Names[] =
|
||||
{
|
||||
"Version 2 Tag 100",
|
||||
"Version 2 Tag 101",
|
||||
"Version 2 Tag 102",
|
||||
"Version 2 Tag 103"
|
||||
};
|
||||
|
||||
int version2Tags[] =
|
||||
{
|
||||
103, 102, 101, 100
|
||||
};
|
||||
|
||||
int main()
|
||||
{
|
||||
cdevTagMap map;
|
||||
cdevData version1Data;
|
||||
cdevData version2Data;
|
||||
version1Data.insert(1, version1Tags, 4);
|
||||
version1Data.insert(2, version1Names, 4);
|
||||
version2Data.insert(1, version2Tags, 4);
|
||||
version2Data.insert(2, version2Names, 4);
|
||||
|
||||
// map.updateTagMap (version1Names, version1Tags, 4);
|
||||
// map.updateTagMap (version2Names, version2Tags, 4);
|
||||
map.updateTagMap(version1Data);
|
||||
map.updateTagMap(version2Data);
|
||||
|
||||
map.asciiDump(stdout);
|
||||
|
||||
cdevData data;
|
||||
|
||||
data.insert(103, "Version 2 Tag 100");
|
||||
data.insert(102, "Version 2 Tag 101");
|
||||
data.insert(101, "Version 2 Tag 102");
|
||||
data.insert(100, "Version 2 Tag 103");
|
||||
map.remoteToLocal(data);
|
||||
data.asciiDump();
|
||||
map.localToRemote(data);
|
||||
data.asciiDump();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user