Repository navigation
updated slow control prototype #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,11 +39,17 @@ std::string SlowControlElement::Print(){ | |
| mtx.lock(); | ||
|
|
||
| if(m_read_function!=0){ | ||
| std::string response=""; | ||
| bool ret = false; | ||
| try{ | ||
| options.Set("value",m_read_function("")); | ||
| ret = m_read_function("", m_name.c_str(), response); | ||
| if(ret) options.Set("value", response); | ||
| } | ||
| catch(...){ | ||
| std::cerr<<"failed to call read fucntion"<<std::endl; | ||
| ret = false; | ||
| } | ||
| if(!ret){ | ||
| std::cerr<<"failed to call read fucntion"<<m_name<<" : "<<response<<std::endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fucntion. :) |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -209,31 +215,49 @@ bool SlowControlElement::SetDefault(std::string value){ | |
| } | ||
|
|
||
|
|
||
|
|
||
| bool SlowControlElement::SetValue(const char value[]){ | ||
| std::string tmp_value=value; | ||
| return SetValue(tmp_value); | ||
| } | ||
|
|
||
|
|
||
| bool SlowControlElement::SetValue(const char value[], std::string& response){ | ||
| std::string tmp_value=value; | ||
| return SetValue(tmp_value, response); | ||
| } | ||
|
|
||
|
|
||
| bool SlowControlElement::SetValue(std::string value){ | ||
| std::string tmp=""; | ||
| return SetValue(value, tmp); | ||
|
|
||
| } | ||
|
|
||
| bool SlowControlElement::SetValue(std::string value, std::string& response){ | ||
|
|
||
| mtx.lock(); | ||
|
|
||
| if(m_type == SlowControlElementType(VARIABLE)){ | ||
| std::stringstream tmp(value); | ||
| double val=0; | ||
| tmp>>val; | ||
| mtx.unlock(); | ||
| return SetValue(val); | ||
| return SetValue(val, response); | ||
| } | ||
|
|
||
| if(m_change_function!=0){ | ||
| bool ret = false; | ||
| try{ | ||
| m_change_function(value.c_str()); | ||
| ret = m_change_function(value.c_str(), m_name.c_str(), response); | ||
| } | ||
| catch(...){ | ||
| std::cerr<<"failed to call change fucntion"<<std::endl; | ||
| mtx.unlock(); | ||
| return false; | ||
| ret = false; | ||
| } | ||
| if(!ret){ | ||
| std::cerr<<"failed to call change fucntion "<<m_name<<" : "<<response<<std::endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fucntion 🙃 |
||
| mtx.unlock(); | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -254,10 +278,18 @@ bool SlowControlElement::SetValue(std::string value){ | |
|
|
||
|
|
||
| bool SlowControlElement::GetValue(std::string &value){ | ||
|
|
||
| std::string tmp=""; | ||
| return GetValue(value, tmp); | ||
| } | ||
|
|
||
| bool SlowControlElement::GetValue(std::string &value, std::string& response){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does GetValue accept a value and a response....? What goes in what? |
||
| mtx.lock(); | ||
| if(m_read_function!=0){ | ||
| bool ret = false; | ||
| try{ | ||
| options.Set("value",m_read_function("")); | ||
| ret = m_read_function("", m_name.c_str(), response); | ||
| if(ret) options.Set("value", response); | ||
| } | ||
| catch(std::exception& e){ | ||
| std::cerr<<"caught "<<e.what()<<" calling read function for SlowControl "<<m_name<<std::endl; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,7 @@ | |
| namespace ToolFramework{ | ||
|
|
||
| // typedef std::string (*SCFunction)(const char*); | ||
| typedef std::function<std::string(const char*)> SCFunction; | ||
| typedef std::function<bool(const char*, const char*, std::string&)> SCFunction; | ||
|
|
||
| enum SlowControlElementType { BUTTON, VARIABLE, OPTIONS, COMMAND, INFO }; | ||
|
|
||
|
|
@@ -31,9 +31,12 @@ namespace ToolFramework{ | |
| SlowControlElementType GetType(); | ||
| bool AddCommand(std::string value); | ||
| bool SetValue(const char value[]); | ||
| bool SetValue(const char value[], std::string& response); | ||
| bool SetDefault(std::string value); | ||
| bool SetValue(std::string value); | ||
| bool SetValue(std::string value, std::string& response); | ||
| bool GetValue(std::string &value); | ||
| bool GetValue(std::string &value, std::string& response); | ||
| bool Lockable(); | ||
| bool Hidden(); | ||
|
|
||
|
|
@@ -90,6 +93,11 @@ namespace ToolFramework{ | |
|
|
||
|
|
||
| template<typename T> bool SetValue(T value){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we maintaining all these SetValue signatures that don't return a response? |
||
| std::string tmp =""; | ||
| return SetValue(value, tmp); | ||
| } | ||
|
|
||
| template<typename T> bool SetValue(T value, std::string& response){ | ||
| mtx.lock(); | ||
| if(m_type == SlowControlElementType(VARIABLE)){ | ||
| T min; | ||
|
|
@@ -104,13 +112,17 @@ namespace ToolFramework{ | |
| if(m_change_function!=0){ | ||
| std::stringstream tmp; | ||
| tmp<<value; | ||
| bool ret = false; | ||
| try{ | ||
| m_change_function(tmp.str().c_str()); | ||
| ret = m_change_function(tmp.str().c_str(), m_name.c_str(), response); | ||
| } | ||
| catch(...){ | ||
| std::cerr<<"failed to call change fucntion"<<std::endl; | ||
| mtx.unlock(); | ||
| return false; | ||
| ret = false; | ||
| } | ||
| if(!ret){ | ||
| std::cerr<<"failed to call change fucntion "<<m_name<<" : "<<response<<std::endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fucntion ಠ⌣ಠ |
||
| mtx.unlock(); | ||
| return false; | ||
| } | ||
| } | ||
| options.Set("value", value); | ||
|
|
@@ -123,29 +135,46 @@ namespace ToolFramework{ | |
| T tmp; | ||
| mtx.lock(); | ||
| if(m_read_function!=0){ | ||
| bool ret = false; | ||
| std::string response = ""; | ||
| try{ | ||
| options.Set("value",m_read_function("")); | ||
| ret = m_read_function("",m_name.c_str(), response); | ||
| if(ret) options.Set("value", response); | ||
| } | ||
| catch(...){ | ||
| std::cerr<<"failed to call read fucntion"<<std::endl; | ||
| ret = false; | ||
| } | ||
| if(!ret){ | ||
| std::cerr<<"failed to call read fucntion "<<m_name<<" : "<<response<<std::endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fucntion ◔ ◡ ◔ |
||
| mtx.unlock(); | ||
| return tmp; | ||
| } | ||
| } | ||
|
|
||
| options.Get("value", tmp); | ||
| mtx.unlock(); | ||
| return tmp; | ||
|
|
||
| } | ||
|
|
||
| template<typename T> bool GetValue(T &value){ | ||
| std::string tmp =""; | ||
| return GetValue(value, tmp); | ||
| } | ||
|
|
||
| template<typename T> bool GetValue(T &value, std::string& response){ | ||
| mtx.lock(); | ||
| if(m_read_function!=0){ | ||
| bool ret = false; | ||
| try{ | ||
| options.Set("value",m_read_function("")); | ||
| ret = m_read_function("", m_name.c_str(), response); | ||
| if(ret) options.Set("value", response); | ||
| } | ||
| catch(...){ | ||
| std::cerr<<"failed to call read fucntion"<<std::endl; | ||
| ret= false; | ||
| } | ||
| if(!ret){ | ||
| std::cerr<<"failed to call read fucntion "<<m_name<<" : "<<response<<std::endl; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fucntion! ٩( ❛ᴗ❛ )۶ |
||
| mtx.unlock(); | ||
| return false; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't set response. Might want to.