0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
RequestHandlerOpen.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 "Hyperspace/Protocol.h"
31 #include "RequestHandlerOpen.h"
32 
33 using namespace Hyperspace;
34 using namespace Hypertable;
35 using namespace Serialization;
36 
38  ResponseCallbackOpen cb(m_comm, m_event);
39  size_t decode_remain = m_event->payload_len;
40  const uint8_t *decode_ptr = m_event->payload;
41  Attribute attr;
42  std::vector<Attribute> attrs;
43  int32_t version = -1;
44 
45  try {
46  version = Serialization::decode_i32(&decode_ptr, &decode_remain);
47  }
48  catch (Exception &e) {
49  HT_ERROR_OUT << e << HT_END;
50  cb.error(e.code(), "Error handling Hyperspace open");
51  return;
52  }
53 
54  if (version != Protocol::Version) {
56  "Hyperspace client/server version mismatch");
57  return;
58  }
59 
60  try {
61  uint32_t flags = decode_i32(&decode_ptr, &decode_remain);
62  uint32_t event_mask = decode_i32(&decode_ptr, &decode_remain);
63  const char *name = decode_vstr(&decode_ptr, &decode_remain);
64  uint32_t attr_count = decode_i32(&decode_ptr, &decode_remain);
65 
66  while (attr_count--) {
67  attr.name = decode_vstr(&decode_ptr, &decode_remain);
68  attr.value = decode_vstr(&decode_ptr, &decode_remain, &attr.value_len);
69  attrs.push_back(attr);
70  }
71  m_master->open(&cb, m_session_id, name, flags, event_mask, attrs);
72  }
73  catch (Exception &e) {
75  || e.code() == Error::HYPERSPACE_FILE_NOT_FOUND) // warning should be sufficient
76  HT_WARN_OUT << e << HT_END;
77  else
78  HT_ERROR_OUT << e << HT_END;
79  cb.error(e.code(), "Error handling Hyperspace open");
80  }
81 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
Declarations for Protocol.
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
Hyperspace definitions
const char * name
Name of extended attribute.
Definition: Protocol.h:59
Logging routines and macros.
Compatibility Macros for C/C++.
#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
#define HT_WARN_OUT
Definition: Logger.h:291
Hypertable definitions
virtual void run()
Carries out the request.
virtual int error(int error, const String &msg)
Sends a standard error response back to the client.
const void * value
Pointer to attribute value.
Definition: Protocol.h:62
This is a generic exception class for Hypertable.
Definition: Error.h:314
Holds extended attribute and value.
Definition: Protocol.h:48
Declarations for ResponseCallback.
Error codes, Exception handling, error logging.
uint32_t value_len
Length of attribute value.
Definition: Protocol.h:65
int code() const
Returns the error code.
Definition: Error.h:391