]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: entity_name_t::parse()
authorSage Weil <sage.weil@dreamhost.com>
Wed, 12 Oct 2011 03:57:24 +0000 (20:57 -0700)
committerSage Weil <sage@newdream.net>
Sat, 15 Oct 2011 03:43:23 +0000 (20:43 -0700)
Signed-off-by: Sage Weil <sage.weil@dreamhost.com>
src/msg/msg_types.h

index 8539f6b2b80b0defba505031d6caea45c6cc1998..d520e3554f7286bc0cfb5ff95abeef4577b8097e 100644 (file)
@@ -63,6 +63,36 @@ public:
     return n;
   }
 
+  bool parse(const string& s) {
+    const char *start = s.c_str();
+    char *end;
+    bool got = parse(start, &end);
+    return got && end == start + s.length();
+  }
+  bool parse(const char *start, char **end) {
+    if (strstr(start, "mon.") == start) {
+      _type = TYPE_MON;
+      start += 4;
+    } else if (strstr(start, "osd.") == start) {
+      _type = TYPE_OSD;
+      start += 4;
+    } else if (strstr(start, "mds.") == start) {
+      _type = TYPE_MDS;
+      start += 4;
+    } else if (strstr(start, "client.") == start) {
+      _type = TYPE_CLIENT;
+      start += 7;
+    } else {
+      return false;
+    }
+    if (isspace(*start))
+      return false;
+    _num = strtoll(start, end, 10);
+    if (*end == NULL || *end == start)
+      return false;
+    return true;
+  }
+
 };
 
 inline void encode(const entity_name_t &a, bufferlist& bl) {