]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
split out raw bit sof msg_types
authorsageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 9 Oct 2007 17:29:48 +0000 (17:29 +0000)
committersageweil <sageweil@29311d96-e01e-0410-9327-a35deaab8ce9>
Tue, 9 Oct 2007 17:29:48 +0000 (17:29 +0000)
git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@1896 29311d96-e01e-0410-9327-a35deaab8ce9

trunk/ceph/include/ceph_inttypes.h [new file with mode: 0644]
trunk/ceph/msg/ceph_msg_types.h [new file with mode: 0644]
trunk/ceph/msg/msg_types.h

diff --git a/trunk/ceph/include/ceph_inttypes.h b/trunk/ceph/include/ceph_inttypes.h
new file mode 100644 (file)
index 0000000..c31c76a
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __CEPH_INTTYPES_H
+#define __CEPH_INTTYPES_H
+
+typedef uint32_t __u32;
+typedef uint16_t __u16;
+typedef uint8_t __u8;
+
+#endif
diff --git a/trunk/ceph/msg/ceph_msg_types.h b/trunk/ceph/msg/ceph_msg_types.h
new file mode 100644 (file)
index 0000000..b641297
--- /dev/null
@@ -0,0 +1,38 @@
+/* -*- mode:C++; tab-width:8; c-basic-offset:8; indent-tabs-mode:t -*- 
+ * vim: ts=8 sw=8 smarttab
+ */
+#ifndef __CEPH_MSG_TYPES_H
+#define __CEPH_MSG_TYPES_H
+
+/*
+ * entity_name
+ */
+struct ceph_entity_name {
+       __u32 type;
+       __u32 num;
+};
+
+#define CEPH_ENTITY_TYPE_MON    1
+#define CEPH_ENTITY_TYPE_MDS    2
+#define CEPH_ENTITY_TYPE_OSD    3
+#define CEPH_ENTITY_TYPE_CLIENT 4
+#define CEPH_ENTITY_TYPE_ADMIN  5
+
+
+/*
+ * entity_addr
+ * ipv4 only for now
+ */
+struct ceph_entity_addr {
+       __u8  ipq[4];
+       __u32 port;
+       __u32 nonce;
+};
+
+
+struct ceph_entity_inst {
+       struct ceph_entity_name name;
+       struct ceph_entity_addr addr;
+};
+
+#endif
index 23c14c8c25c110bd8f7dc52ba343710d46b4dfc2..793520d4a446b6e25591d9fe73f8cb8014e9f1be 100644 (file)
 #ifndef __MSG_TYPES_H
 #define __MSG_TYPES_H
 
+// raw C structs
+#include "include/ceph_inttypes.h"
+#include "ceph_msg_types.h"
+
 #include "include/types.h"
 #include "include/blobhash.h"
 #include "tcp.h"
 
-// new typed msg_addr_t way!
 class entity_name_t {
-  int32_t _type;
-  int32_t _num;
+  struct ceph_entity_name v;
 
 public:
-  static const int TYPE_MON = 1;
-  static const int TYPE_MDS = 2;
-  static const int TYPE_OSD = 3;
-  static const int TYPE_CLIENT = 4;
-  static const int TYPE_ADMIN = 5;
+  static const int TYPE_MON = CEPH_ENTITY_TYPE_MON;
+  static const int TYPE_MDS = CEPH_ENTITY_TYPE_MDS;
+  static const int TYPE_OSD = CEPH_ENTITY_TYPE_OSD;
+  static const int TYPE_CLIENT = CEPH_ENTITY_TYPE_CLIENT;
+  static const int TYPE_ADMIN = CEPH_ENTITY_TYPE_ADMIN;
 
   static const int NEW = -1;
 
   // cons
-  entity_name_t() : _type(0), _num(0) {}
-  entity_name_t(int t, int n=NEW) : _type(t), _num(n) {}
+  entity_name_t() { v.type = v.num = 0; }
+  entity_name_t(int t, int n=NEW) { v.type = t; v.num = n; }
 
   // static cons
   static entity_name_t MON(int i=NEW) { return entity_name_t(TYPE_MON, i); }
@@ -44,8 +46,8 @@ public:
   static entity_name_t CLIENT(int i=NEW) { return entity_name_t(TYPE_CLIENT, i); }
   static entity_name_t ADMIN(int i=NEW) { return entity_name_t(TYPE_ADMIN, i); }
   
-  int num() const { return _num; }
-  int type() const { return _type; }
+  int num() const { return v.num; }
+  int type() const { return v.type; }
   const char *type_str() const {
     switch (type()) {
     case TYPE_MDS: return "mds"; 
@@ -105,34 +107,33 @@ namespace __gnu_cxx {
  * ipv4 for now.
  */
 struct entity_addr_t {
-  uint8_t  ipq[4];
-  uint32_t port;
-  uint32_t nonce;  // bind time, or pid, or something unique!
+  struct ceph_entity_addr v;
 
-  entity_addr_t() : port(0), nonce(0) {
-    ipq[0] = ipq[1] = ipq[2] = ipq[3] = 0;
+  entity_addr_t() { 
+    v.port = v.nonce = 0; 
+    v.ipq[0] = v.ipq[1] = v.ipq[2] = v.ipq[3] = 0;
   }
 
   void set_addr(tcpaddr_t a) {
-    memcpy((char*)ipq, (char*)&a.sin_addr.s_addr, 4);
-    port = ntohs(a.sin_port);
+    memcpy((char*)v.ipq, (char*)&a.sin_addr.s_addr, 4);
+    v.port = ntohs(a.sin_port);
   }
   void make_addr(tcpaddr_t& a) const {
     memset(&a, 0, sizeof(a));
     a.sin_family = AF_INET;
-    memcpy((char*)&a.sin_addr.s_addr, (char*)ipq, 4);
-    a.sin_port = htons(port);
+    memcpy((char*)&a.sin_addr.s_addr, (char*)v.ipq, 4);
+    a.sin_port = htons(v.port);
   }
 };
 
 inline ostream& operator<<(ostream& out, const entity_addr_t &addr)
 {
-  return out << (int)addr.ipq[0]
-            << '.' << (int)addr.ipq[1]
-            << '.' << (int)addr.ipq[2]
-            << '.' << (int)addr.ipq[3]
-            << ':' << addr.port
-            << '.' << addr.nonce;
+  return out << (int)addr.v.ipq[0]
+            << '.' << (int)addr.v.ipq[1]
+            << '.' << (int)addr.v.ipq[2]
+            << '.' << (int)addr.v.ipq[3]
+            << ':' << addr.v.port
+            << '.' << addr.v.nonce;
 }
 
 inline bool operator==(const entity_addr_t& a, const entity_addr_t& b) { return memcmp(&a, &b, sizeof(a)) == 0; }