merge
This commit is contained in:
@@ -33,38 +33,24 @@ Properties::~Properties()
|
||||
delete _infile;
|
||||
delete _outfile;
|
||||
//clear map
|
||||
for(_propertiesIterator = _properties.begin() ;
|
||||
_propertiesIterator != _properties.end();
|
||||
_propertiesIterator++ )
|
||||
{
|
||||
delete [] _propertiesIterator->first;
|
||||
delete [] _propertiesIterator->second;
|
||||
}
|
||||
_properties.clear();
|
||||
}
|
||||
|
||||
void Properties::setProperty(const string key,const string value)
|
||||
{
|
||||
string oldValue;
|
||||
_propertiesIterator = _properties.find(key.c_str());
|
||||
_propertiesIterator = _properties.find(key);
|
||||
|
||||
if(_propertiesIterator != _properties.end()) //found in map
|
||||
{
|
||||
delete[] _propertiesIterator->first;
|
||||
delete[] _propertiesIterator->second;
|
||||
_properties.erase(_propertiesIterator);
|
||||
}
|
||||
|
||||
char* chKey = new char[key.length() + 1];
|
||||
strncpy(chKey,key.c_str(),key.length()+ 1);
|
||||
char* chValue = new char[value.length() + 1];
|
||||
strncpy(chValue,value.c_str(),value.length() + 1);
|
||||
_properties[chKey] = chValue;
|
||||
_properties[key] = value;
|
||||
}
|
||||
|
||||
string Properties::getProperty(const string key)
|
||||
{
|
||||
_propertiesIterator = _properties.find(key.c_str());
|
||||
_propertiesIterator = _properties.find(key);
|
||||
if(_propertiesIterator != _properties.end()) //found in map
|
||||
{
|
||||
return string(_propertiesIterator->second);
|
||||
@@ -78,29 +64,18 @@ string Properties::getProperty(const string key)
|
||||
|
||||
string Properties::getProperty(const string key, const string defaultValue)
|
||||
{
|
||||
_propertiesIterator = _properties.find(key.c_str());
|
||||
_propertiesIterator = _properties.find(key);
|
||||
if(_propertiesIterator != _properties.end()) //found in map
|
||||
{
|
||||
return string(_propertiesIterator->second);
|
||||
}
|
||||
|
||||
char* chKey = new char[key.length() + 1];
|
||||
strncpy(chKey,key.c_str(),key.length()+ 1);
|
||||
char* chValue = new char[defaultValue.length() + 1];
|
||||
strncpy(chValue,defaultValue.c_str(),defaultValue.length() + 1);
|
||||
_properties[chKey] = chValue;
|
||||
_properties[key] = defaultValue;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
void Properties::load()
|
||||
{
|
||||
for (_propertiesIterator = _properties.begin() ;
|
||||
_propertiesIterator != _properties.end();
|
||||
_propertiesIterator++ )
|
||||
{
|
||||
delete [] _propertiesIterator->first;
|
||||
delete [] _propertiesIterator->second;
|
||||
}
|
||||
_properties.clear();
|
||||
|
||||
try
|
||||
@@ -148,12 +123,7 @@ void Properties::load()
|
||||
truncate(key);
|
||||
property = line.substr(pos + 1,line.length());
|
||||
truncate(property);
|
||||
|
||||
char* chKey = new char[key.length() + 1];
|
||||
strncpy(chKey,key.c_str(),key.length()+ 1);
|
||||
char* chProperty = new char[property.length() +1];
|
||||
strncpy(chProperty,property.c_str(),property.length() + 1);
|
||||
_properties[chKey] = chProperty;
|
||||
_properties[key] = property;
|
||||
}
|
||||
}
|
||||
catch (ifstream::failure& e)
|
||||
@@ -302,32 +272,24 @@ ConfigurationProviderImpl::ConfigurationProviderImpl()
|
||||
|
||||
ConfigurationProviderImpl::~ConfigurationProviderImpl()
|
||||
{
|
||||
for(_configsIter = _configs.begin() ;
|
||||
_configsIter != _configs.end();
|
||||
_configsIter++ )
|
||||
{
|
||||
delete [] _configsIter->first;
|
||||
}
|
||||
_configs.clear();
|
||||
}
|
||||
|
||||
void ConfigurationProviderImpl::registerConfiguration(const string name, const Configuration* configuration)
|
||||
{
|
||||
Lock guard(&_mutex);
|
||||
_configsIter = _configs.find(name.c_str());
|
||||
_configsIter = _configs.find(name);
|
||||
if(_configsIter != _configs.end())
|
||||
{
|
||||
string msg = "configuration with name " + name + " already registered";
|
||||
throw BaseException(msg.c_str(), __FILE__, __LINE__);
|
||||
}
|
||||
char* chKey = new char[name.length() + 1];
|
||||
strncpy(chKey,name.c_str(),name.length()+ 1);
|
||||
_configs[chKey] = configuration;
|
||||
_configs[name] = configuration;
|
||||
}
|
||||
|
||||
Configuration* ConfigurationProviderImpl::getConfiguration(const string name)
|
||||
{
|
||||
_configsIter = _configs.find(name.c_str());
|
||||
_configsIter = _configs.find(name);
|
||||
if(_configsIter != _configs.end())
|
||||
{
|
||||
return const_cast<Configuration*>(_configsIter->second);
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
#include <envDefs.h>
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <string.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
@@ -23,13 +23,6 @@ namespace epics { namespace pvAccess {
|
||||
|
||||
#define MAX_NAME_LENGHT 300
|
||||
|
||||
struct conf_cmp_str
|
||||
{
|
||||
bool operator()(char const *a, char const *b)
|
||||
{
|
||||
return strcmp(a, b) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Properties
|
||||
@@ -52,8 +45,8 @@ public:
|
||||
void list();
|
||||
|
||||
private:
|
||||
std::map<const char*,const char* , conf_cmp_str> _properties;
|
||||
std::map<const char*,const char* , conf_cmp_str>::iterator _propertiesIterator;
|
||||
std::map<std::string,std::string> _properties;
|
||||
std::map<std::string,std::string>::iterator _propertiesIterator;
|
||||
std::ifstream* _infile;
|
||||
std::ofstream* _outfile;
|
||||
std::string _fileName;
|
||||
@@ -181,8 +174,8 @@ public:
|
||||
void registerConfiguration(const std::string name, const Configuration* configuration);
|
||||
private:
|
||||
epics::pvData::Mutex _mutex;
|
||||
std::map<const char*,const Configuration*, conf_cmp_str> _configs;
|
||||
std::map<const char*,const Configuration*, conf_cmp_str>::iterator _configsIter;
|
||||
std::map<std::string,const Configuration*> _configs;
|
||||
std::map<std::string,const Configuration*>::iterator _configsIter;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -46,7 +46,9 @@ FieldConstPtr IntrospectionRegistry::getIntrospectionInterface(const short id)
|
||||
Lock guard(&_mutex);
|
||||
_registryIter = _registry.find(id);
|
||||
if(_registryIter == _registry.end())
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
return _registryIter->second;
|
||||
}
|
||||
|
||||
@@ -104,6 +106,9 @@ void IntrospectionRegistry::printKeysAndValues(string name)
|
||||
buffer.clear();
|
||||
cout << "\t" << "Key: "<< _registryIter->first << endl;
|
||||
cout << "\t" << "Value: " << _registryIter->second << endl;
|
||||
_registryIter->second->dumpReferenceCount(&buffer,0);
|
||||
cout << "\t" << "References: " << buffer.c_str() << endl;
|
||||
buffer.clear();
|
||||
_registryIter->second->toString(&buffer);
|
||||
cout << "\t" << "Value toString: " << buffer.c_str() << endl;
|
||||
}
|
||||
@@ -158,11 +163,6 @@ void IntrospectionRegistry::serialize(FieldConstPtr field, StructureConstPtr par
|
||||
{
|
||||
bool existing;
|
||||
const short key = registry->registerIntrospectionInterface(field, existing);
|
||||
/*cout << "@@@@@@@@@" << endl;
|
||||
cout << field->getFieldName() << endl;
|
||||
cout << "address: " << field << endl;
|
||||
cout << "existing: " << existing << endl;
|
||||
cout << "key: " << key << endl;*/
|
||||
if(existing)
|
||||
{
|
||||
control->ensureBuffer(1+sizeof(int16)/sizeof(int8));
|
||||
@@ -244,8 +244,8 @@ FieldConstPtr IntrospectionRegistry::deserialize(ByteBuffer* buffer, Deserializa
|
||||
{
|
||||
control->ensureData(sizeof(int16)/sizeof(int8));
|
||||
FieldConstPtr field = registry->getIntrospectionInterface(buffer->getShort());
|
||||
field->incReferenceCount(); // we inc, so that deserialize always returns a field with +1 ref. count (as when created)
|
||||
return field;
|
||||
field->incReferenceCount(); // we inc, so that deserialize always returns a field with +1 ref. count (as when created)
|
||||
return field;
|
||||
}
|
||||
|
||||
// could also be a mask
|
||||
|
||||
@@ -68,6 +68,7 @@ int main(int argc, char *argv[])
|
||||
assert(doubleProperty == 42);
|
||||
|
||||
if(configuration) delete configuration;
|
||||
if(configProvider) delete configProvider;
|
||||
getShowConstructDestruct()->constuctDestructTotals(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ ScalarArrayConstPtr getScalarArray(string name)
|
||||
StructureConstPtr getStructure(string name)
|
||||
{
|
||||
String properties("alarm");
|
||||
FieldConstPtr powerSupply[3];
|
||||
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
|
||||
powerSupply[0] = standardField->scalar(
|
||||
String("voltage"),pvDouble,properties);
|
||||
powerSupply[1] = standardField->scalar(
|
||||
@@ -97,7 +97,7 @@ StructureConstPtr getStructure(string name)
|
||||
powerSupply[2] = standardField->scalar(
|
||||
String("current"),pvDouble,properties);
|
||||
StructureConstPtr structure = standardField->structure(name,3,powerSupply);
|
||||
PVField * pvField = pvDataCreate->createPVField(0,structure);
|
||||
PVField *pvField = pvDataCreate->createPVField(0,structure);
|
||||
pvFieldArray.push_back(pvField);
|
||||
return structure;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ StructureConstPtr getStructure(string name)
|
||||
StructureArrayConstPtr getStructureArray(string name1, string name2)
|
||||
{
|
||||
String properties("alarm");
|
||||
FieldConstPtr powerSupply[3];
|
||||
FieldConstPtrArray powerSupply = new FieldConstPtr[3];
|
||||
powerSupply[0] = standardField->scalar(
|
||||
String("voltage"),pvDouble,properties);
|
||||
powerSupply[1] = standardField->scalar(
|
||||
@@ -411,7 +411,7 @@ int main(int argc, char *argv[])
|
||||
statusCreate = getStatusCreate();
|
||||
fieldCreate = getFieldCreate();
|
||||
standardField = getStandardField();
|
||||
cout << "DONE1" << endl;
|
||||
|
||||
|
||||
flusher = new SerializableControlImpl();
|
||||
control = new DeserializableControlImpl();
|
||||
@@ -420,7 +420,6 @@ int main(int argc, char *argv[])
|
||||
clientRegistry = new IntrospectionRegistry(false);
|
||||
serverRegistry = new IntrospectionRegistry(true);
|
||||
|
||||
|
||||
testRegistryPutGet();
|
||||
testRegistryReset();
|
||||
testSerialize();
|
||||
@@ -444,7 +443,7 @@ int main(int argc, char *argv[])
|
||||
if(clientRegistry) delete clientRegistry;
|
||||
if(serverRegistry) delete serverRegistry;
|
||||
|
||||
getShowConstructDestruct()->showDeleteStaticExit(stdout);
|
||||
getShowConstructDestruct()->showDeleteStaticExit(stdout);
|
||||
cout << "DONE" << endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user