source: trunk/FACT++/src/chatclient.cc@ 19369

Last change on this file since 19369 was 19237, checked in by tbretz, 6 years ago
Added missing include for DNS_PORT
File size: 2.9 KB
Line 
1#include <boost/filesystem.hpp>
2
3#include "dim.h"
4
5#include "Configuration.h"
6#include "ChatClient.h"
7#include "DimSetup.h"
8
9using namespace std;
10
11template <class T>
12void RunShell(Configuration &conf)
13{
14 // A normal kill will call its destructor! (Very nice feature ;) )
15 static T shell(conf.GetName().c_str(), conf.Get<int>("console")!=1);
16
17 WindowLog &win = shell.GetStreamIn();
18 WindowLog &wout = shell.GetStreamOut();
19
20 if (conf.Has("log"))
21 if (!wout.OpenLogFile(conf.Get<string>("log")))
22 win << kRed << "ERROR - Couldn't open log-file " << conf.Get<string>("log") << ": " << strerror(errno) << endl;
23
24 shell.Run();
25}
26
27
28// ========================================================================
29void SetupConfiguration(Configuration &conf)
30{
31 const string n = conf.GetName()+".log";
32
33 po::options_description config("Program options");
34 config.add_options()
35 ("dns", var<string>("localhost"), "Dim nameserver (overwites DIM_DNS_NODE environment variable)")
36 ("port", var<uint16_t>(DNS_PORT), "Port to connect to dim nameserver.")
37 ("host", var<string>(""), "Address with which the Dim nameserver can connect to this host (overwites DIM_HOST_NODE environment variable)")
38 ("log,l", var<string>(n), "Write log-file")
39 ("console,c", var<int>(0), "Use console (0=shell, 1=simple buffered, X=simple unbuffered)")
40 ;
41
42 conf.AddEnv("dns", "DIM_DNS_NODE");
43 conf.AddEnv("port", "DIM_DNS_PORT");
44 conf.AddEnv("host", "DIM_HOST_NODE");
45
46 conf.AddOptions(config);
47}
48
49/*
50 Extract usage clause(s) [if any] for SYNOPSIS.
51 Translators: "Usage" and "or" here are patterns (regular expressions) which
52 are used to match the usage synopsis in program output. An example from cp
53 (GNU coreutils) which contains both strings:
54 Usage: cp [OPTION]... [-T] SOURCE DEST
55 or: cp [OPTION]... SOURCE... DIRECTORY
56 or: cp [OPTION]... -t DIRECTORY SOURCE...
57 */
58void PrintUsage()
59{
60 cout << "\n"
61 "The chatclient is a simple Dim based chatclient.\n"
62 "\n"
63 "The chatclient is always started with user intercation. "
64 "Just enter a message. It will be broadcasted through the chatserv, "
65 "which need to be running."
66 "\n"
67 "Usage: chatclient [-c type] [OPTIONS]\n"
68 " or: chatclient [OPTIONS]\n";
69 cout << endl;
70
71}
72
73void PrintHelp()
74{
75 /* Additional help text which is printed after the configuration
76 options goes here */
77}
78
79int main(int argc, const char *argv[])
80{
81 Configuration conf(argv[0]);
82 conf.SetPrintUsage(PrintUsage);
83 SetupConfiguration(conf);
84
85 if (!conf.DoParse(argc, argv, PrintHelp))
86 return 127;
87
88 Dim::Setup(conf.Get<string>("dns"), conf.Get<string>("host"), conf.Get<uint16_t>("port"));
89
90 if (conf.Get<int>("console")==0)
91 RunShell<ChatShell>(conf);
92 else
93 RunShell<ChatConsole>(conf);
94
95
96 return 0;
97}
Note: See TracBrowser for help on using the repository browser.