subevent
1.0.0
C++ 이벤트 기반 및 네트워크 애플리케이션 라이브러리
-std=c++11 (또는 이후 옵션)-pthread 또는 -lpthread-lssl 및 -lcrypt (OpenSSL용)# include < subevent/subevent.hpp >
SEV_USING_NS
// ---------------------------------------------------------------------------//
// Main
// ---------------------------------------------------------------------------//
SEV_IMPL_GLOBAL
int main ( int , char **)
{
NetApplication app;
// your code here.
return app. run ();
}# include < subevent/subevent.hpp >
SEV_USING_NS
// ---------------------------------------------------------------------------//
// MyApp
// ---------------------------------------------------------------------------//
class MyApp : public NetApplication
{
protected:
bool onInit () override
{
NetApplication::onInit ();
// Your initialization code here.
return true ;
}
void onExit () override
{
// Your deinitialization code here.
NetApplication::onExit ();
}
};
// ---------------------------------------------------------------------------//
// Main
// ---------------------------------------------------------------------------//
SEV_IMPL_GLOBAL
int main ( int , char **)
{
MyApp app;
return app. run ();
} // call "void NetApplication::stop()"
stop (); class MyThread : public NetThread
{
protected:
bool onInit () override
{
NetThread::onInit ();
// Your initialization code here.
return true ;
}
void onExit () override
{
// Your deinitialization code here.
NetThread::onExit ();
}
}; // Start
MyThread* myThread = new MyThread();
myThread-> start (); // End
myThread-> stop ();
myThread-> wait ();
delete myThread; // Declare MyEvent
// <Unique Id, ParamType1, ParamType2, ...>
typedef UserEvent< 1 , int , std::string> MyEvent; // Send (to another thread or self)
int param1 = 20 ;
std::string param2 = " data " ;
myThread-> post ( new MyEvent(param1, param2)); // Receive
setUserEventHandler<MyEvent>([&]( const MyEvent* myEvent) {
int param1;
std::string param2;
myEvent-> getParams (param1, param2);
});myThread-> post ([&]() {
// Executed on myThread.
});Timer* timer = new Timer();
uint32_t msec = 60000 ;
bool repeat = false ;
// start
timer-> start (msec, repeat, [&](Timer*) {
// Called from the same thread when time out.
}); $ cmake .
$ make