0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RequestHandlerAttrGet.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 
22 #include "Common/Compat.h"
23 #include "Common/Error.h"
24 #include "Common/Logger.h"
25 
27 #include "Common/Serialization.h"
28 
29 #include "Hyperspace/Master.h"
30 #include "RequestHandlerAttrGet.h"
32 
33 using namespace Hyperspace;
34 using namespace Hypertable;
35 using namespace Serialization;
36 
37 /*
38  *
39  */
41  ResponseCallbackAttrGet cb(m_comm, m_event);
42  size_t decode_remain = m_event->payload_len;
43  const uint8_t *decode_ptr = m_event->payload;
44 
45  try {
46  bool has_name = decode_bool(&decode_ptr, &decode_remain);
47  uint64_t handle = 0;
48  const char* name = 0;
49  if (has_name)
50  name = decode_vstr(&decode_ptr, &decode_remain);
51  else
52  handle = decode_i64(&decode_ptr, &decode_remain);
53 
54  std::vector<String> attrs;
55  uint32_t attr_cnt = decode_i32(&decode_ptr, &decode_remain);
56  attrs.reserve(attr_cnt);
57  while (attr_cnt-- > 0) {
58  const char *attr = decode_vstr(&decode_ptr, &decode_remain);
59  attrs.push_back(attr);
60  }
61  m_master->attr_get(&cb, m_session_id, handle, name, attrs);
62  }
63  catch (Exception &e) {
64  HT_ERROR_OUT << e << HT_END;
65  cb.error(e.code(), "Error handling ATTRGET message");
66  }
67 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
Declarations for ResponseCallbackAttrGet.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
virtual void run()
Carries out the request.
Hyperspace definitions
uint64_t decode_i64(const uint8_t **bufp, size_t *remainp)
Decode a 64-bit integer in little-endian order.
bool decode_bool(const uint8_t **bufp, size_t *remainp)
Decodes a boolean value from the given buffer.
Definition: Serialization.h:96
Logging routines and macros.
Compatibility Macros for C/C++.
Sends back result of an attr_get request.
#define HT_END
Definition: Logger.h:220
Functions to serialize/deserialize primitives to/from a memory buffer.
#define HT_ERROR_OUT
Definition: Logger.h:301
Hypertable definitions
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
This is a generic exception class for Hypertable.
Definition: Error.h:314
Declarations for ResponseCallback.
Error codes, Exception handling, error logging.
int code() const
Returns the error code.
Definition: Error.h:391