feat():initial version
This commit is contained in:
109
code_generator/someip_app/template.someip_service.cpp
Normal file
109
code_generator/someip_app/template.someip_service.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*============================================================================*/
|
||||
/* Copyright (C) huaxu (${YEAR}).
|
||||
*
|
||||
* All rights reserved. This software is huaxu property. Duplication
|
||||
* or disclosure without huaxu written authorization is prohibited.
|
||||
*
|
||||
* @file someip_service.cpp
|
||||
* @brief main entry of someip_service
|
||||
* @author ${AUTHOR}
|
||||
* @date ${TIME}
|
||||
*/
|
||||
/*============================================================================*/
|
||||
/*=======[R E V I S I O N H I S T O R Y]====================================*/
|
||||
/* <VERSION> <DATE> <AUTHOR> <REVISION LOG>
|
||||
* V0.0.1 ${DATE} ${AUTHOR} First version by auto generator
|
||||
*/
|
||||
/*============================================================================*/
|
||||
|
||||
/*=======[I N C L U D E S]====================================================*/
|
||||
|
||||
#include "someip_ids.hpp"
|
||||
#include "someip_type.hpp"
|
||||
#include "someip_service.hpp"
|
||||
#include <list>
|
||||
|
||||
using namespace vsomeip;
|
||||
/*=======[G L O B A L D A T A]==============================================*/
|
||||
|
||||
/*=======[M A C R O S]========================================================*/
|
||||
|
||||
/*=======[I N T E R N A L D A T A]==========================================*/
|
||||
|
||||
/*=======[L O C A L F U N C T I O N D E C L A R A T I O N S]==============*/
|
||||
|
||||
${ALL_FUNCS_DECLARATIONS}
|
||||
|
||||
/*=======[L O C A L F U N C T I O N I M P L E M E N T A T I O N S]========*/
|
||||
|
||||
${ALL_FUNCS_IMPLEMENTATIONS}
|
||||
|
||||
/*=======[G L O B A L F U N C T I O N I M P L E M E N T A T I O N S]======*/
|
||||
|
||||
|
||||
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
|
||||
service *server_ptr(nullptr);
|
||||
void handle_signal(int _signal)
|
||||
{
|
||||
if (server_ptr != nullptr &&
|
||||
(_signal == SIGINT || _signal == SIGTERM
|
||||
|| _signal == SIGKILL))
|
||||
server_ptr->stop();
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
service server;
|
||||
|
||||
std::vector<offer_method_t> offer_methods;
|
||||
std::vector<offer_event_t> offer_events;
|
||||
std::vector<offer_service_t> my_services;
|
||||
|
||||
#ifndef VSOMEIP_ENABLE_SIGNAL_HANDLING
|
||||
server_ptr = &server;
|
||||
signal(SIGINT, handle_signal);
|
||||
signal(SIGTERM, handle_signal);
|
||||
signal(SIGKILL, handle_signal);
|
||||
#endif
|
||||
offer_methods.clear();
|
||||
${ALL_OFFER_METHODS}
|
||||
|
||||
offer_events.clear();
|
||||
${ALL_OFFER_EVENTS}
|
||||
|
||||
my_services.clear();
|
||||
${ALL_OFFER_SERVICES}
|
||||
|
||||
if (server.init())
|
||||
{
|
||||
for (auto const&service: my_services){
|
||||
server.start_offer_service(service._service, service._instance,
|
||||
service._major, service._minor);
|
||||
}
|
||||
|
||||
for (auto const&method: offer_methods){
|
||||
server.start_offer_method(method._service,method._instance,method._method,method._get_response_data_func);
|
||||
}
|
||||
|
||||
for (auto const&event: offer_events){
|
||||
server.start_offer_event(event._service, event._instance, event._eventgroup,
|
||||
event._event, event._type, event._cycle, event._change_resets_cycle,
|
||||
event._update_on_change, event._epsilon_change_func,
|
||||
event._reliability);
|
||||
}
|
||||
|
||||
server.start(); //block function
|
||||
|
||||
// stop:
|
||||
for (auto const&service: my_services){
|
||||
server.stop_offer_service(service._service, service._instance,
|
||||
service._major, service._minor);
|
||||
}
|
||||
server.stop();
|
||||
return 0;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user