grpc plugin: Split out identifier into it's own message type.
[collectd.git] / src / grpc.cc
index a1abe4a..45fb029 100644 (file)
@@ -62,11 +62,8 @@ using google::protobuf::util::TimeUtil;
  * proto conversion
  */
 
-static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg, value_list_t *vl)
+static grpc::Status unmarshal_ident(const collectd::types::Identifier &msg, value_list_t *vl)
 {
-       vl->time = NS_TO_CDTIME_T(TimeUtil::TimestampToNanoseconds(msg.time()));
-       vl->interval = NS_TO_CDTIME_T(TimeUtil::DurationToNanoseconds(msg.interval()));
-
        std::string s;
 
        s = msg.host();
@@ -88,16 +85,26 @@ static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg,
        sstrncpy(vl->type, s.c_str(), sizeof(vl->type));
 
        s = msg.plugin_instance();
-       if (s.length())
-               sstrncpy(vl->plugin_instance, s.c_str(), sizeof(vl->plugin_instance));
+       sstrncpy(vl->plugin_instance, s.c_str(), sizeof(vl->plugin_instance));
 
        s = msg.type_instance();
-       if (s.length())
-               sstrncpy(vl->type_instance, s.c_str(), sizeof(vl->type_instance));
+       sstrncpy(vl->type_instance, s.c_str(), sizeof(vl->type_instance));
+
+       return grpc::Status::OK;
+} /* unmarshal_ident() */
+
+static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg, value_list_t *vl)
+{
+       vl->time = NS_TO_CDTIME_T(TimeUtil::TimestampToNanoseconds(msg.time()));
+       vl->interval = NS_TO_CDTIME_T(TimeUtil::DurationToNanoseconds(msg.interval()));
+
+       auto status = unmarshal_ident(msg.identifier(), vl);
+       if (!status.ok())
+               return status;
 
        value_t *values = NULL;
        size_t values_len = 0;
-       auto status = grpc::Status::OK;
+       status = grpc::Status::OK;
 
        for (auto v : msg.value()) {
                value_t *val = (value_t *)realloc(values, (values_len + 1) * sizeof(*values));
@@ -126,7 +133,7 @@ static grpc::Status unmarshal_value_list(const collectd::types::ValueList &msg,
                        break;
                default:
                        status = grpc::Status(grpc::StatusCode::INVALID_ARGUMENT,
-                                       grpc::string("unkown value type"));
+                                       grpc::string("unknown value type"));
                        break;
                }
 
@@ -440,7 +447,7 @@ extern "C" {
 
                server->Start();
                for (i = 0; i < workers_num; i++) {
-                       pthread_create(&workers[i], /* attr = */ NULL,
+                       plugin_thread_create(&workers[i], /* attr = */ NULL,
                                        worker_thread, server);
                }
                INFO("grpc: Started %zu workers", workers_num);