[DEV] signal is better
This commit is contained in:
parent
749b7a09c0
commit
006ed42f38
@ -52,6 +52,7 @@ namespace ewol {
|
|||||||
|
|
||||||
bool connect(std::shared_ptr<ewol::Object> _obj, const char* _destId=nullptr, const std::string& _data="" ) {
|
bool connect(std::shared_ptr<ewol::Object> _obj, const char* _destId=nullptr, const std::string& _data="" ) {
|
||||||
m_serializedCallerList.push_back(std::make_tuple(_obj, _destId, _data));
|
m_serializedCallerList.push_back(std::make_tuple(_obj, _destId, _data));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
bool release(std::shared_ptr<ewol::Object> _obj) {
|
bool release(std::shared_ptr<ewol::Object> _obj) {
|
||||||
for (auto it(m_serializedCallerList.begin()) ; it != m_serializedCallerList.end(); ++it) {
|
for (auto it(m_serializedCallerList.begin()) ; it != m_serializedCallerList.end(); ++it) {
|
||||||
@ -88,7 +89,6 @@ namespace ewol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool emit(const std::shared_ptr<ewol::Object>& _source, const T& _data) {
|
bool emit(const std::shared_ptr<ewol::Object>& _source, const T& _data) {
|
||||||
// note : this can not emit on function ....
|
// note : this can not emit on function ....
|
||||||
std::string stringData;
|
std::string stringData;
|
||||||
@ -120,6 +120,78 @@ namespace ewol {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<> class Signal<void> : public SignalBase {
|
||||||
|
private:
|
||||||
|
//std::vector<std::funtion<void(const T&)>> m_callerList;
|
||||||
|
std::vector<std::tuple<std::weak_ptr<ewol::Object>, const char*, std::string>> m_serializedCallerList;
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Create a parameter with a specific type.
|
||||||
|
* @param[in] _objectLink reference on the parameter lister.
|
||||||
|
* @param[in] _name Static name of the parameter.
|
||||||
|
* @param[in] _defaultValue Default value of the parameter.
|
||||||
|
* @param[in] _min Minumum value.
|
||||||
|
* @param[in] _max Maximum value.
|
||||||
|
* @param[in] _description description of the parameter.
|
||||||
|
*/
|
||||||
|
Signal(ewol::object::SignalList& _objectLink,
|
||||||
|
const std::string& _name,
|
||||||
|
const std::string& _description = "") :
|
||||||
|
SignalBase(_objectLink, _name, _description) {
|
||||||
|
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* @brief Destructor.
|
||||||
|
*/
|
||||||
|
virtual ~Signal() { };
|
||||||
|
|
||||||
|
const std::string& getName() {
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
const std::string& getDescription() {
|
||||||
|
return m_description;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool connect(std::shared_ptr<ewol::Object> _obj, const char* _destId=nullptr, const std::string& _data="" ) {
|
||||||
|
m_serializedCallerList.push_back(std::make_tuple(_obj, _destId, _data));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool release(std::shared_ptr<ewol::Object> _obj) {
|
||||||
|
for (auto it(m_serializedCallerList.begin()) ; it != m_serializedCallerList.end(); ++it) {
|
||||||
|
if (std::get<0>(it) == _obj) {
|
||||||
|
m_serializedCallerList.erase(it);
|
||||||
|
it = m_serializedCallerList.begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool emit(const std::shared_ptr<ewol::Object>& _source) {
|
||||||
|
// note : this can not emit on function ....
|
||||||
|
std::string stringData;
|
||||||
|
for (auto &it : m_serializedCallerList) {
|
||||||
|
std::shared_ptr<ewol::Object> destObject = std::get<0>(it).lock();
|
||||||
|
if (destObject == nullptr) {
|
||||||
|
// TODO : Remove instance ...
|
||||||
|
EWOL_VERBOSE(" nullptr dest");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const char* eventId = m_name.c_str();
|
||||||
|
if (std::get<1>(it) != nullptr) {
|
||||||
|
eventId = std::get<1>(it);
|
||||||
|
}
|
||||||
|
if (std::get<2>(it).size() <= 0){
|
||||||
|
ewol::object::Message tmpMsg(_source, eventId, stringData);
|
||||||
|
EWOL_VERBOSE("send message " << tmpMsg);
|
||||||
|
destObject->onReceiveMessage(tmpMsg);
|
||||||
|
} else {
|
||||||
|
// set the user requested data ...
|
||||||
|
ewol::object::Message tmpMsg(_source, eventId, std::get<2>(it));
|
||||||
|
EWOL_VERBOSE("send message " << tmpMsg);
|
||||||
|
destObject->onReceiveMessage(tmpMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
@ -31,12 +31,11 @@ namespace ewol {
|
|||||||
public:
|
public:
|
||||||
// Event list of properties
|
// Event list of properties
|
||||||
ewol::object::Signal<int> signalPressed;
|
ewol::object::Signal<int> signalPressed;
|
||||||
static const char* const eventPressed;
|
ewol::object::Signal<void> signalDown;
|
||||||
static const char* const eventDown;
|
ewol::object::Signal<void> signalUp;
|
||||||
static const char* const eventUp;
|
ewol::object::Signal<void> signalEnter;
|
||||||
static const char* const eventEnter;
|
ewol::object::Signal<void> signalLeave;
|
||||||
static const char* const eventLeave;
|
ewol::object::Signal<void> signalValue;
|
||||||
static const char* const eventValue;
|
|
||||||
enum buttonLock{
|
enum buttonLock{
|
||||||
lockNone, //!< normal status of the button
|
lockNone, //!< normal status of the button
|
||||||
lockWhenPressed, //!< When the state is set in pressed, the status stay in this one
|
lockWhenPressed, //!< When the state is set in pressed, the status stay in this one
|
||||||
|
Loading…
x
Reference in New Issue
Block a user