ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/frontend/tclient/tinput_handler.cpp
Revision: 1.3
Committed: Mon Oct 25 01:18:05 2010 UTC (15 years, 11 months ago) by sf-pippijn
Branch: MAIN
Changes since 1.2: +9 -0 lines
Log Message:
do not crash if inventory manager has no views attached

File Contents

# User Rev Content
1 sf-pippijn 1.1 #include "tinput_handler.h"
2    
3 sf-pippijn 1.3 #include "trenderer.h"
4    
5     #include "adt/string.h"
6    
7 sf-pippijn 1.1 input_handler::input_handler (communicator &comm)
8     : sender (comm)
9     {
10     stdin_watcher.set (STDIN_FILENO, ev::READ);
11     stdin_watcher.set<input_handler, &input_handler::stdin_read_cb> (this);
12     stdin_watcher.start ();
13     }
14    
15     input_handler::~input_handler ()
16     {
17     }
18    
19     void
20     input_handler::stdin_read_cb (ev::io &w, int revents)
21     {
22     char buf[BUFSIZ];
23     ssize_t len = read (w.fd, buf, sizeof buf);
24 sf-pippijn 1.2
25 sf-pippijn 1.1 if (len < 0)
26     throw "read error (stdin): " + std::string (strerror (errno));
27     if (len == 0)
28     throw "EOF from stdin";
29 sf-pippijn 1.2
30 sf-pippijn 1.1 if (buf[0] == '/')
31     send (buf + 1, size_t (len) - 2);
32 sf-pippijn 1.3 else if (buf[0] == '!')
33     {
34     if (false) ;
35     else if (!strncmp (buf, "!map-dump")) rend->draw_map ();
36     }
37 sf-pippijn 1.1 else
38     send ("command", std::string (buf, len - 1));
39     }