0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ResponseCallbackAttrGet.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 
29 #include <Common/Compat.h>
30 
32 
33 #include <AsyncComm/CommBuf.h>
34 
35 #include <Common/Error.h>
36 
37 using namespace Hyperspace;
38 using namespace Hypertable;
39 
40 int ResponseCallbackAttrGet::response(const std::vector<DynamicBufferPtr> &buffers) {
41  CommHeader header;
43  if (buffers.size() == 1 && buffers.front()) {
44  StaticBuffer buffer(*buffers.front());
45  CommBufPtr cbp(new CommBuf(header, 12, buffer));
46  cbp->append_i32(Error::OK);
47  cbp->append_i32(1);
48  cbp->append_i32(buffer.size);
49  return m_comm->send_response(m_event->addr, cbp);
50  }
51 
52  size_t len = 0;
53  for (const auto &pdb : buffers) {
54  if (pdb)
55  len += pdb->fill();
56  }
57 
58  CommBufPtr cbp(new CommBuf(header, 8 + 4 * buffers.size() + len));
59  cbp->append_i32(Error::OK);
60  cbp->append_i32(buffers.size());
61  for (const auto &pdb : buffers) {
62  if (pdb)
63  Serialization::encode_bytes32(cbp->get_data_ptr_address(), pdb->base, pdb->fill());
64  else
65  cbp->append_i32(0);
66  }
67  return m_comm->send_response(m_event->addr, cbp);
68 }
69 
A memory buffer of static size.
Definition: StaticBuffer.h:45
void initialize_from_request_header(CommHeader &req_header)
Initializes header from req_header.
Definition: CommHeader.h:128
Declarations for ResponseCallbackAttrGet.
Comm * m_comm
Comm pointer.
Hyperspace definitions
std::shared_ptr< CommBuf > CommBufPtr
Smart pointer to CommBuf.
Definition: CommBuf.h:305
Compatibility Macros for C/C++.
int send_response(const CommAddress &addr, CommBufPtr &cbuf)
Sends a response message back over a connection.
Definition: Comm.cc:343
Hypertable definitions
Header for messages transmitted via AsyncComm.
Definition: CommHeader.h:40
Declarations for CommBuf.
Message buffer for holding data to be transmitted over a network.
Definition: CommBuf.h:79
EventPtr m_event
Smart pointer to event object.
Error codes, Exception handling, error logging.
void encode_bytes32(uint8_t **bufp, const void *data, int32_t len)
Encodes a variable sized byte array into the given buffer.
int response(const std::vector< Hypertable::DynamicBufferPtr > &buffers)
Sends back result of an attr_get request.