/* * branch.cpp * * Simulation of Chandy-Lamport algorithm * * This file is a part of Distributed Systems term thesis * Department KIV, ZCU Plzen * Author: Martin Sloup, msloup@students.zcu.cz */ #include #include #include #include "server.h" #include "client.h" #include "marker.h" using namespace std; const char *clientConfig = "clients.conf"; int port = 2000; void show_help(char *filename) { cout << "Usage:" << endl; cout << " " << filename << " branch_id [[port] config_file]" << endl; cout << endl; cout << "branch_if - id of branch" << endl; cout << "port - port, where baranchg bind to (default: " << port << ")" << endl; cout << "config_file - filename with definition of connection between braches. (default: " << clientConfig << ")" << endl; } void parse_args(int argc, char **argv) { if (argc < 2 || strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { show_help(argv[0]); exit(0); } for(int i = 1; i < argc; i++) { switch(i) { case 1: branch_id = strtol(argv[i], NULL, 10); break; case 2: port = strtol(argv[i], NULL, 10); break; case 3: clientConfig = argv[i]; break; default: break; } } } int main(int argc, char **argv) { parse_args(argc, argv); server_start(port); cout << "Please start other branches and press enter..." << endl; cin.get(); client_parse_and_connect(clientConfig); cout << "Please press enter on other branches to print this message and then press enter again..." << endl; cin.get(); client_start(); marker_start(); server_loop(); return 0; }