Service Configurator Framework는 동적 서비스 또는 정적 서비스를 제어할 수 있습니다. 정적 서비스는 대부분 서비스를 관리하고 운영하는 필수적이고, 보안적으로 중요한 서비스를 실행 파일과 함께 컴파일 단계에서 서비스로 등록해줍니다.
정적 서비스는 3개의 매크로 구문과 구현부에 넣어주는 매크로 구문으로 구현합니다.
ACE_FACTORY_DEFINE( ACE_Local_Service, ACE_Service_Manager);
ACE_STATIC_SVC_DEFINE( Service_Manager,
"MyService",
ACE_SVC_OBJ_T,
& ACE_SVC_NAME(ACE_Service_Manager),
ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
0);
ACE_STATIC_SVC_REQUIRE( Service_Manager );
int main(){
....
ACE_STATIC_SVC_REGISTER( Service_Manager );
....
}
서비스의 인자는 ACE_Service_Object:: init 함수를 확인하면 파라메타를 확인할 수 있습니다.
ACE는 기본적으로 2개의 정적 서비스(ACE_Naming_Context, ACE_Service_Manager)가 기본 등록됩니다.
서비스 로더 커멘드 옵션 정보
'-b'
Turn the application process into a daemon (see Sidebar 5 on page 32).
'-d'
Display diagnostic information as directives are processed.
'-f'
Supply a file containing directives other than the default svc.conf file. This argument can be repeated to supply multiple configuration files.
'-n'
Don't process static directives, which eliminates the need to initialize the ACE_Service_Repository statically.
'-s'
Designate the signal to be used to cause the ACE_Service_Config to reprocess its configuration file. By default, SIGHUP is used.
'-S'
Supply a directive to the ACE_Service_Config directly. This argument can be repeated to process multiple directives.
'-y'
Process static directives, which requires the static initialization of the ACE_Service_Repository.
svc.conf 기본 문법 (BNF)
<svc-conf-entries> ::= <svc-conf-entries> <svc-conf-entry> | NULL
<svc-conf-entry> ::= <dynamic> | <static> | <suspend> |
<resume> | <remove> | <stream>
<dynamic> ::= dynamic <svc-location> <parameters-opt>
<static> ::= static <svc-name> <parameters-opt>
<suspend> ::= suspend <svc-name>
<resume> ::= resume <svc-name>
<remove> ::= remove <svc-name>
<stream> ::= stream <streamdef> '{' <module-list> '}'
<streamdef> ::= <svc-name> | dynamic | static
<module-list> ::= <module-list> <module> | NULL
<module> ::= <dynamic> | <static> | <suspend> |
<resume> | <remove>
<svc-location> ::= <svc-name> <svc-type> <svc-factory> <status>
<svc-type> ::= Service_Object '*' | Module '*' | Stream '*' | NULL
<svc-factory> ::= PATHNAME ':' FUNCTION '(' ')'
<svc-name> ::= STRING
<status> ::= active | inactive | NULL
<parameters-opt> ::= '"' STRING '"' | NULL
ServiceLoader.cpp 파일
// ServiceLoader.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <ace/ACE.h>
#include <ace/Service_Config.h>
#include <ace/Reactor.h>
#include <ace/Service_Manager.h>
#include <ace/Naming_Context.h>
ACE_FACTORY_DEFINE( ACE_Local_Service, ACE_Service_Manager);
ACE_STATIC_SVC_DEFINE( Service_Manager,
"MyService",
ACE_SVC_OBJ_T,
& ACE_SVC_NAME(ACE_Service_Manager),
ACE_Service_Type::DELETE_THIS | ACE_Service_Type::DELETE_OBJ,
0);
ACE_STATIC_SVC_REQUIRE( Service_Manager );
int main(int argc, char* argv[])
{
ACE::init();
ACE_STATIC_SVC_REGISTER( Service_Manager );
ACE_Service_Config::open( argc, argv,ACE_DEFAULT_LOGGER_KEY,false ); //svc.conf
ACE_Reactor::instance() ->run_reactor_event_loop();
ACE::fini();
return 0;
}