📄 main.cpp
字号:
/***************************************************************** * * * This file is a part of the eXtremeDB-HA Application Framework * * Copyright (c) 2001-2006 McObject LLC * * All Rights Reserved * * * ***************************************************************** * ++ * * PROJECT: eXtremeDB(tm) (c) 2003 McObject LLC * * SUBSYSTEM: HA framework * * MODULE: main.cpp * * ABSTRACT: The main module of HA framework * * * VERSION: 1.0 * * HISTORY: * 1.0- 1 SS 18-Feb-2004 Created it was * * -- *****************************************************************/#include "mcoha.hpp"App app; // global App instance/* * static variables & constants *//*************************** * program banners * ***************************/void usage(void){ Printf ("Usage: \tmcoha [-m][number_of_replicated_databases] | \n"); Printf ("\t [-ms][number_of_replicated_databases] | \n"); Printf ("\t [-r][database_index] | \n"); Printf ("\t [-s][database_index] | \n"); Printf ("\t [-sm][database index] | \n"); Printf ("\t [-h]\n"); }void help(void){ Printf ("Usage: \tmcoha [OPTIONS]\n\n"); Printf ("Demonstrates the eXtremeDB High Availability Framework.\n\n" "Note that this example program illustrates how the HA Framework \"can\" be\n" "used, not how it \"must\" be used. For instance, this example uses multiple\n" "replica processes, one for each database, when a \"master\" has more than one\n" "database to replicate. Another implementation could use multiple threads\n" "instead of processes.\n\n"); Printf ("Options:\n\n"); Printf ("-m[N] Runs the application as a \"main master\" that replicates\n" " N \"master\" databases.\n" " \"Main master\" creates a \"commit thread\" that provides the\n" " context in which all (main and secondary) master node\n" " applications execute their database commits\n" " N = 1,2,3 or 4, N = 1 by default\n\n" " Example: mcoha -m\n" " Runs as the \"main master\" process that replicates one database\n\n"); Printf ("-ms[N] Runs the application as a \"secondary master\" that replicates\n" " N \"master\" databases\n" " \"Secondary master\" database commits are executed in the context\n" " of the \"main master\" commit thread\n" " N = 1,2,3 or 4, N = 1 by default\n\n" " Example: mcoha -ms\n" " Runs as a \"secondary master\" process that replicates one database\n\n"); Printf ("-r[I] Runs the application as a \"replica\" attached to the database\n" " with the index I. When multiple master databases are replicated,\n" " each \"master\" database is replicated by its own \"replica\" process\n" " I = 1,2,4 or 4, I = 1 by default\n\n" " Example: mcoha -r\n" " Runs as a \"replica\" process attached to the first master\n" " database\n\n"); Printf ("-s[I] The same as rI, except the replica becomes the \"master\"\n" " if the current \"master\" process has failed\n" " I = 1,2,3 or 4, I = 1 by default\n\n" " Example: mcoha -s\n" " Runs as a \"replica\" process attached to the first replicated\n" " database and takes over in the case of the current \"master\"\n" " failure\n\n"); Printf ("-sm[I] Runs as a \"replica\". Synchronizes the database referenced by the\n" " index I and continues running as a \"master\" process.\n" " I = 1,2,3 or 4, I = 1 by default\n\n" " This mode is used when re-starting a failed \"master\" and you\n" " want it to resume the role of \"master\" after re-synchronizing\n" " with the replica that became master during the failover.\n" " The replica turned master will revert to a replica\n\n" " Example: mcoha -sm\n" " Runs as a \"replica\" process attached to the first replicated\n" " database and becomes a \"master\" after the initial database\n" " synchronization is complete\n\n"); Printf ("-h help\n");}/***************************************************** * main program entry *****************************************************/#ifndef WIN32_WCEint main( int argc, char **argv )#elseint __cdecl main( int argc, char **argv )#endif{ app.init(argc, argv); /* initialize the application and run working thread */ return 0;}/* * banner output (& command input for WINCE) */void App::SH(void){#ifndef _WIN32_WCE Printf("eXtremeDB-HA runtime version %d.%d, build %d\n\n", MCO_COMP_VER_MAJOR, MCO_COMP_VER_MINOR, MCO_COMP_BUILD_NUM);#else Printf("eXtremeDB-HA runtime v. %d.%d, build %d\n\n", MCO_COMP_VER_MAJOR, MCO_COMP_VER_MINOR, MCO_COMP_BUILD_NUM); { char s[128]; Printf(" Enter command:\n"); fgets(s,128,stdin); }#endif}/************************************************** * command line parser procedure **************************************************/int App::parse_cmd_line(int argc, char **argv){ int i; char *p; if (argc == 1) { usage(); return 1; } for (i=1;i<argc;i++) { p=argv[i]; if ( (p[0] == '/')||(p[0] == '-') ) { if(p[1] == 'h') { help(); return 1; } if(p[1] == 'r') { if( (CurrentDbInstance = atoi((const char*) &p[2])) ) CurrentDbInstance--; }else if(p[1] == 'm') { main_master = 0; if( p[2] != 's') { main_master ++; if(!( NumberOfDb=atoi((const char*) &p[2]) ) ) NumberOfDb = 1; else { if( NumberOfDb > MAX_HA_INSTANCES ) NumberOfDb = MAX_HA_INSTANCES; } } else { if(!(NumberOfDb=atoi((const char*) &p[3]))) NumberOfDb = 1; else { if( NumberOfDb > MAX_HA_INSTANCES ) NumberOfDb = MAX_HA_INSTANCES; } } }else if(p[1] == 's') { replica_mode = 0; if(p[2] == 'm') { replica_mode++; if( (CurrentDbInstance = atoi((const char*) &p[3])) ) CurrentDbInstance--; } else { if( (CurrentDbInstance = atoi((const char*) &p[2])) ) CurrentDbInstance--; } } }else { return 1; } return 0; } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -