forked from aregtech/areg-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
73 lines (59 loc) · 2.43 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* \file twothreads/src/main.cpp
* \brief Runs service and the client in one thread.
**/
#include "areg/base/GEGlobal.h"
#include "areg/base/NEUtilities.hpp"
#include "areg/appbase/Application.hpp"
#include "areg/component/ComponentLoader.hpp"
#include "common/src/ServiceComponent.hpp"
#include "common/src/ClientComponent.hpp"
#include <string>
// Use these options if compile for Windows with MSVC
// It links with areg library (dynamic or static) and generated static library
#ifdef WINDOWS
#pragma comment(lib, "areg")
#pragma comment(lib, "00_generated.lib")
#endif // WINDOWS
namespace
{
//!< The name of model
constexpr char const _modelName[] { "ServiceModel" };
//! Service component role
constexpr char const _service[] { "ServiceComponent" };
//!< Client component name. Let's generate the name for client service, we'll use it later.
const std::string _client( NEUtilities::generateName("ServiceClient").getString() );
}
// Describe model, register the service and the client in 2 different threads "Thread1" and "Thread2"
BEGIN_MODEL(_modelName)
// Thread 1, provides a service
BEGIN_REGISTER_THREAD( "Thread1" )
BEGIN_REGISTER_COMPONENT( _service, ServiceComponent )
REGISTER_IMPLEMENT_SERVICE( NEHelloService::ServiceName, NEHelloService::InterfaceVersion )
END_REGISTER_COMPONENT( _service )
END_REGISTER_THREAD( "Thread1" )
// Thread 2, is a client / service consumer.
BEGIN_REGISTER_THREAD( "Thread2" )
BEGIN_REGISTER_COMPONENT( _client.c_str(), ClientComponent )
REGISTER_DEPENDENCY( _service ) /* reference to the service*/
END_REGISTER_COMPONENT( _client )
END_REGISTER_THREAD( "Thread2" )
// end of model description
END_MODEL(_modelName)
//////////////////////////////////////////////////////////////////////////
// main method
//////////////////////////////////////////////////////////////////////////
int main( void )
{
// Initialize application, enable logging, servicing and the timer.
Application::initApplication(true, true, true, true, nullptr, nullptr );
// load model to initialize components
Application::loadModel(_modelName);
// wait until Application quit signal is set.
Application::waitAppQuit(NECommon::WAIT_INFINITE);
// stop and unload components
Application::unloadModel(_modelName);
// release and cleanup resources of application.
Application::releaseApplication();
return 0;
}