Created
November 24, 2015 13:07
-
-
Save lukpazera/f227531412fe1fb27a90 to your computer and use it in GitHub Desktop.
CLxCommandNotifier class can be used to create custom notifiers for use in commands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <lxu_command.hpp> | |
class CustomNotifier : public CLxCommandNotifier | |
{ | |
public: | |
CustomNotifier (); | |
virtual ~CustomNotifier () {} | |
virtual void cn_Parse (std::string &args) {}; | |
virtual unsigned int cn_Flags (int code) { return LXfCMDNOTIFY_VALUE; }; | |
}; | |
static const char *notifierName = "custom.notifier"; | |
CustomNotifier::CustomNotifier () | |
: CLxCommandNotifier (notifierName) | |
{ | |
} | |
template<class T> | |
void initializeCommandNotifier( const char* name ) | |
{ | |
CLxGenericPolymorph *srv = new CLxPolymorph<T>; | |
srv->AddInterface(new CLxIfc_Notifier<T>); | |
lx::AddServer(name, srv); | |
} | |
void initialize() | |
{ | |
initializeCommandNotifier<CustomNotifier>(notifierName); | |
} | |
/* This is how a notification can be sent using custom notifier to notify all the clients. | |
This can be done from the basic_Execute() commands' method. | |
*/ | |
CLxCommandNotifier::Notify (symmetryStateNotifierName, 0); | |
/* And this is how a command can subscribe to get events from the custom notifier. | |
Each command's argument can subscribe to different notifiers. In this case | |
we add the custom notifier for argument 0. | |
*/ | |
bool OtherCommand::basic_Notifier ( int index, std::string &name, std::string &args) | |
{ | |
bool result = false; | |
if (index == 0) { | |
name = notifierName; | |
result = true; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment