Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/ServiceDiscovery/SlowControlCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ bool SlowControlCollection::Update(SlowControlCollection* SCC, std::string key,

(*SCC)[key]->SetValue(value);
//(*SCC)[key]->Print();
/*
SCFunction tmp_func= (*SCC)[key]->GetChangeFunction();
if (tmp_func!=nullptr){
try{
Expand All @@ -703,11 +704,13 @@ bool SlowControlCollection::Update(SlowControlCollection* SCC, std::string key,
catch(...){
reply= "change function failed";
}
}
}
*/
}
else reply = key + " locked";
}
else{
/*
SCFunction tmp_func= (*SCC)[key]->GetReadFunction();
if (tmp_func!=nullptr){
try{
Expand All @@ -718,8 +721,8 @@ bool SlowControlCollection::Update(SlowControlCollection* SCC, std::string key,
}
}
else (*SCC)[key]->GetValue(reply);


*/
(*SCC)[key]->GetValue(reply);
}
}
return true;
Expand Down
31 changes: 28 additions & 3 deletions src/ServiceDiscovery/SlowControlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ std::string SlowControlElement::Print(){
else if (m_type==SlowControlElementType(OPTIONS)) out+="OPTIONS\"";
else if (m_type==SlowControlElementType(COMMAND)) out+="COMMAND\"";
else if (m_type==SlowControlElementType(INFO)) out+="INFO\"";

mtx.lock();

mtx.lock();

if(m_read_function!=0){
try{
options.Set("value",m_read_function(""));
}
catch(...){
std::cerr<<"failed to call read fucntion"<<std::endl;
}
}

for(std::map<std::string,std::string>::iterator it=options.begin(); it!=options.end(); it++){

out+=",\""+it->first+"\":"+it->second;
}
out+="}";
Expand Down Expand Up @@ -210,6 +217,16 @@ bool SlowControlElement::SetValue(const char value[]){

bool SlowControlElement::SetValue(std::string value){
mtx.lock();

if(m_change_function!=0){
try{
m_change_function(value.c_str());
}
catch(...){
std::cerr<<"failed to call change fucntion"<<std::endl;
}
}

if(m_type == SlowControlElementType(VARIABLE)){
std::stringstream tmp(value);
double val=0;
Expand All @@ -233,6 +250,14 @@ bool SlowControlElement::SetValue(std::string value){

bool SlowControlElement::GetValue(std::string &value){
mtx.lock();
if(m_read_function!=0){
try{
options.Set("value",m_read_function(""));
}
catch(...){
std::cerr<<"failed to call read fucntion"<<std::endl;
}
}
if(!options.Has("value")){
mtx.unlock();
return false;
Expand Down
28 changes: 27 additions & 1 deletion src/ServiceDiscovery/SlowControlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ namespace ToolFramework{
if(value>max) value=max;
}
}
if(m_change_function!=0){
std::stringstream tmp;
tmp<<value;
try{
m_change_function(tmp.str().c_str());
}
catch(...){
std::cerr<<"failed to call change fucntion"<<std::endl;
}
}
options.Set("value", value);
mtx.unlock();
return true;
Expand All @@ -110,14 +120,30 @@ namespace ToolFramework{
template<typename T> T GetValue(){
T tmp;
mtx.lock();
if(m_read_function!=0){
try{
options.Set("value",m_read_function(""));
}
catch(...){
std::cerr<<"failed to call read fucntion"<<std::endl;
}
}
options.Get("value", tmp);
mtx.unlock();
return tmp;

}

template<typename T> bool GetValue(T &value){
mtx.lock();
mtx.lock();
if(m_read_function!=0){
try{
options.Set("value",m_read_function(""));
}
catch(...){
std::cerr<<"failed to call read fucntion"<<std::endl;
}
}
bool ret=options.Get("value", value);
mtx.unlock();
return ret;
Expand Down
Loading