521xueweihan / HelloGitHub

:octocat: 分享 GitHub 上有趣、入门级的开源项目。Share interesting, entry-level open source projects on GitHub.
https://hellogithub.com
85.13k stars 9.43k forks source link

AREG Framework #2560

Open aregtech opened 10 months ago

aregtech commented 10 months ago

推荐项目

Easy hierarchical modeling and object initialization for multithreading and multiprocessing. Here is an example for multithreading application initialization (simiar in IPC):

// Define the model and describe components
BEGIN_MODEL("ServiceModel")
    BEGIN_REGISTER_THREAD( "Thread1", NECommon::WATCHDOG_IGNORE )
        BEGIN_REGISTER_COMPONENT( "ServiceComponent", ServiceComponent )
            REGISTER_IMPLEMENT_SERVICE( NEHelloService::ServiceName, NEHelloService::InterfaceVersion )
        END_REGISTER_COMPONENT( "ServiceComponent" )
    END_REGISTER_THREAD( "Thread1" )

    BEGIN_REGISTER_THREAD( "Thread2", NECommon::WATCHDOG_IGNORE )
        BEGIN_REGISTER_COMPONENT( "ServiceClient", ClientComponent )
            REGISTER_DEPENDENCY( "ServiceComponent" )
        END_REGISTER_COMPONENT( "ServiceClient" )
    END_REGISTER_THREAD( "Thread2" )

END_MODEL("ServiceModel")

int main( void )
{
    constexpr char const model[]{ "ServiceModel" };

    Application::initApplication();   // initialize internals
    Application::loadModel(model);    // load model, initialize components
    Application::waitAppQuit();       // wait to receive quit signal
    Application::unloadModel(model);  // stop and unload components
    Application::releaseApplication();// release resources

    return 0;
}
Horsediedmanrun commented 10 months ago

Really useful.

aregtech commented 10 months ago

@Horsediedmanrun, thank you for opinion