0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Event.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
28 #include "Common/Compat.h"
29 
30 #include <iostream>
31 using namespace std;
32 
33 extern "C" {
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <netinet/in.h>
37 #include <arpa/inet.h>
38 }
39 
40 #include "Common/Error.h"
41 #include "Common/StringExt.h"
42 
43 #include "ReactorRunner.h"
44 #include "Event.h"
45 
46 using namespace Hypertable;
47 
48 String Event::to_str() const {
49  string dstr;
50 
51  dstr = "Event: type=";
52  if (type == CONNECTION_ESTABLISHED)
53  dstr += "CONNECTION_ESTABLISHED";
54  else if (type == DISCONNECT)
55  dstr += "DISCONNECT";
56  else if (type == MESSAGE) {
57  dstr += "MESSAGE";
58  dstr += (String)" version=" + (int)header.version;
59  dstr += (String)" total_len=" + (int)header.total_len;
60  dstr += (String)" header_len=" + (int)header.header_len;
61  dstr += (String)" header_checksum=" + (int)header.header_checksum;
62  dstr += (String)" flags=" + (int)header.flags;
63  dstr += (String)" id=" + (int)header.id;
64  dstr += (String)" gid=" + (int)header.gid;
65  dstr += (String)" timeout_ms=" + (int)header.timeout_ms;
66  dstr += (String)" payload_checksum=" + (int)header.payload_checksum;
67  dstr += (String)" command=" + (int)header.command;
68  }
69  else if (type == TIMER)
70  dstr += "TIMER";
71  else if (type == ERROR)
72  dstr += "ERROR";
73  else
74  dstr += (int)type;
75 
76  if (error != Error::OK)
77  dstr += (String)" \"" + Error::get_text(error) + "\"";
78 
79  if (type != TIMER) {
80  dstr += " from=";
81  dstr += addr.format();
82  }
83 
84  return dstr;
85 }
86 
87 
88 
Error condition
Definition: PollEvent.h:48
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
Declarations for ReactorRunner.
STL namespace.
Declarations for Event.
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
Compatibility Macros for C/C++.
Hypertable definitions
String extensions and helpers: sets, maps, append operators etc.
Error codes, Exception handling, error logging.