Introduction to ACE service configurator

Source: Internet
Author: User
Tags perl interpreter perl script

A few days ago, I read the task framework of C ++ npv2 and used ACE service config, which is also useful for projects currently maintained. I am also idle, let's take a look at it as a pastime.

This serviceconfig framework is actually used for network service configuration, which can be static or powerful dynamic configuration. You do not need to change the main program, configure the configuration file, and restart to load it. It is said that what is more powerful is that in operation, you can send signals to control the dynamic loading, and even the program does not have to stop. It is really tough.

The sample code I wrote is partly from the network reference.

Static service code to generate exe.

# Include "stdafx. H "# include" ACE/reactor. H "# include" ACE/service_object.h "# include" ACE/service_config.h "# include <iostream> using namespace STD; Class ace_staticsvc: Public ace_service_object {public: ace_staticsvc (ace_reactor * r = ace_reactor: instance (): ace_service_object (r) {;} virtual ~ Ace_staticsvc () {;} // initialization. Virtual int Init (INT argc, ace_tchar * argv []) {// The parameters are placed after the startup command and separated by spaces. For example, "static service" is actually two parameters, one being static, one is service. Argc> 0? Cout <"ace_staticsvc: init with Arg:" <argv [0] <Endl: cout <"ace_staticsvc: init" <Endl; return 0 ;} // The service ends. Virtual int Fini () {cout <"ace_staticsvc: fini" <Endl; return 0 ;}// the service suspends virtual int suspend () {cout <"ace_staticsvc :: suspend "<Endl; return 0;} // Service Restoration virtual int resume () {cout <" ace_staticsvc: Resume "<Endl; return 0 ;}}; merge (ace_local_service, ace_staticsvc) Merge (merge, ace_text ("ace_staticsvc"), merge, & Merge (ace_staticsvc), ace_service_type: delete_this | ace_service_type: delete_obj, 0) struct (struct) int ace_tmain (INT argc, ace_tchar * argv []) {ace_static_svc_register (region); ace_service_config: open (argc, argv, substring, 0); ace_reactor :: instance ()-> run_reactor_event_loop (); Return 0 ;}

Dynamic service code to generate ace_dll.dll.
The macro definition of ace_dll_build_dll is inexplicable, but it cannot be forgotten.

# Include "stdafx. H "# define ace_dll_build_dll // This definition is abnormal # include" ace_dll_export.h "# include" ACE/service_object.h "# include <iostream> using namespace STD; Class ace_dll_export ace_dynamicsvc: public ace_service_object {public: ace_dynamicsvc () {} virtual ~ Ace_dynamicsvc () {} virtual int Init (INT argc, ace_tchar * argv []) {argc> 0? Cout <"ace_dynamicsvc: init with Arg:" <argv [0] <Endl: cout <"ace_dynamicsvc: init" <Endl; return 0 ;} virtual int Fini () {cout <"ace_dynamicsvc: fini" <Endl; return 0 ;}; ace_factory_define (ace_dll, ace_dynamicsvc)

The imported export file is generated using the Perl script of ACE. Command: $ ace_root/bin/generate_export_file.pl name.
The command here is generate_export_file.pl ace_dll (to install the perl interpreter ).

Another is the configuration file, which must be placed in the same path as the running program.
SVC. conf

Static ace_staticsvc "staticservice"
Suspend ace_staticsvc
Resume ace_staticsvc
Remove ace_staticsvc
Dynamic ace_dynamicsvc service_object * ace_dll.dll: _ make_ace_dynamicsvc () "dynamicservice"
Remove ace_dynamicsvc

Okay. Run the command to see if it is easy?

Post: http://fanged.ycool.com/post.2606992.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.