38 # include <dsn/service_api_c.h> 39 # include <dsn/cpp/auto_codes.h> 40 # include <dsn/cpp/address.h> 55 : _started(
false), _gpid(gpid) { }
59 virtual ::dsn::error_code start(
int argc,
char** argv) = 0;
61 virtual ::dsn::error_code stop(
bool cleanup =
false) = 0;
66 bool is_started()
const {
return _started; }
70 const std::string& name()
const {
return _name; }
72 dsn_gpid get_gpid()
const {
return _gpid; }
81 template<
typename TServiceApp>
82 static void* app_create(
const char* ,
dsn_gpid gpid)
84 auto svc =
new TServiceApp(gpid);
88 static dsn_error_t app_start(
void* app,
int argc,
char** argv)
92 sapp->_name = std::string(argv[0]);
94 auto r = sapp->start(argc, argv);
95 if (r == ::dsn::ERR_OK)
97 sapp->_started =
true;
102 static dsn_error_t app_destroy(
void* app,
bool cleanup)
105 auto err = sapp->stop(cleanup);
106 if (ERR_OK == err) sapp->_started =
false;
112 template<
typename TServiceApp>
116 memset(&app, 0,
sizeof(app));
119 app.layer1.
create = service_app::app_create<TServiceApp>;
120 app.layer1.
start = service_app::app_start;
121 app.layer1.
destroy = service_app::app_destroy;
developers define the following dsn_app data structure, and passes it to rDSN through dsn_register_ap...
Definition: app_model.h:333
DSN_API dsn_address_t dsn_primary_address()
get the primary address of the rpc engine attached to the current thread
dsn_app_start start
callback to start the app, similar to main
Definition: app_model.h:342
dsn_app_destroy destroy
callback to stop and destroy the app
Definition: app_model.h:343
Definition: auto_codes.h:105
Definition: api_layer1.h:683
dsn_app_create create
callback to create the context for the app
Definition: app_model.h:341
#define DSN_APP_MASK_APP
app mask
Definition: app_model.h:290
DSN_API bool dsn_register_app(dsn_app *app_type)
register application/framework into rDSN runtime
Definition: service_app.h:51
char type_name[DSN_MAX_APP_TYPE_NAME_LENGTH]
type
Definition: app_model.h:336
void register_app(const char *type_name)
C++ wrapper of the dsn_register_app function.
Definition: service_app.h:113
uint64_t mask
application capability mask
Definition: app_model.h:335