Skip to content
Open
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
23 changes: 8 additions & 15 deletions src/ServiceDiscovery/SlowControlCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,28 +737,21 @@ bool SlowControlCollection::Update(SlowControlCollection* SCC, std::string key,
//printf("d0 %s = %s : %s\n", reply.c_str(), key.c_str(), value.c_str());
if(value!=""){
if(!testing || (testing && !(*SCC)[key]->Lockable())){

if(!(*SCC)[key]->SetValue(value)){

std::string change_result;
if(!(*SCC)[key]->SetValue(value, change_result)){
reply =" Error setting "+key+" to value: " + value;
return false;
}
else{
reply = value;
// A change function's actual return (e.g. ExportConfig's JSON
// payload) matters for some controls - fall back to echoing
// value for the common case of no change function / nothing
// returned, matching the old behaviour.
reply = change_result.empty() ? value : change_result;
return true;
}
//(*SCC)[key]->Print();
/*
SCFunction tmp_func= (*SCC)[key]->GetChangeFunction();
if (tmp_func!=nullptr){
try{
reply=tmp_func(key.c_str());

}
catch(...){
reply= "change function failed";
}
}
*/
}
else reply = key + " locked";
}
Expand Down
15 changes: 10 additions & 5 deletions src/ServiceDiscovery/SlowControlElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ bool SlowControlElement::SetValue(const char value[]){


bool SlowControlElement::SetValue(std::string value){
std::string result;
return SetValue(value, result);
}

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

if(m_type == SlowControlElementType(VARIABLE)){
Expand All @@ -225,20 +230,20 @@ bool SlowControlElement::SetValue(std::string value){
mtx.unlock();
return SetValue(val);
}

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



if(m_type == SlowControlElementType(INFO)){ //sanitising for web printout
for(unsigned int i=0; i<value.length(); i++){
if(value.at(i)==',') value.at(i)='.';
Expand Down
4 changes: 4 additions & 0 deletions src/ServiceDiscovery/SlowControlElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ namespace ToolFramework{
bool SetValue(const char value[]);
bool SetDefault(std::string value);
bool SetValue(std::string value);
// Same as SetValue(std::string), but also hands back whatever the change
// function actually returned (empty if there's no change function, or it
// returned nothing) - SetValue(std::string) alone discards that.
bool SetValue(std::string value, std::string& result);
bool GetValue(std::string &value);
bool Lockable();
bool Hidden();
Expand Down
Loading