0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
DispatchHandlerSynchronizer.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 
31 #include "Protocol.h"
32 
33 #include <Common/Error.h>
34 #include <Common/Logger.h>
35 
36 using namespace Hypertable;
37 using namespace std;
38 
40  return;
41 }
42 
44  lock_guard<mutex> lock(m_mutex);
45  m_receive_queue.push(event_ptr);
46  m_cond.notify_one();
47 }
48 
49 
51  unique_lock<mutex> lock(m_mutex);
52 
53  m_cond.wait(lock, [this](){ return !m_receive_queue.empty(); });
54 
55  event_ptr = m_receive_queue.front();
56  m_receive_queue.pop();
57 
58  if (event_ptr->type == Event::MESSAGE
59  && Protocol::response_code(event_ptr.get()) == Error::OK)
60  return true;
61 
62  return false;
63 }
64 
65 
67  unique_lock<mutex> lock(m_mutex);
68 
69  m_cond.wait(lock, [this](){ return !m_receive_queue.empty(); });
70 
71  EventPtr event = m_receive_queue.front();
72  m_receive_queue.pop();
73 
74  if (event->type == Event::ERROR)
75  HT_THROW(event->error, "");
76 
77  if (event->type == Event::DISCONNECT)
78  return false;
79 
81 
82  return true;
83 }
static int32_t response_code(const Event *event)
Returns the response code from an event event generated in response to a request message.
Definition: Protocol.cc:39
virtual void handle(EventPtr &event)
Event Dispatch method.
std::shared_ptr< Event > EventPtr
Smart pointer to Event.
Definition: Event.h:228
STL namespace.
Error event
Definition: Event.h:64
Connection established event.
Definition: Event.h:61
bool wait_for_reply(EventPtr &event)
This method is used by a client to synchronize.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
Logging routines and macros.
Compatibility Macros for C/C++.
Connection disconnected event.
Definition: Event.h:62
Hypertable definitions
Declarations for Protocol.
Request/response message event.
Definition: Event.h:63
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
Definition: Error.h:478
Declarations for DispatchHandlerSynchronizer.
bool wait_for_connection()
Waits for CONNECTION_ESTABLISHED event.