examples/ubuntu: add vendor greeter command

Change-Id: Idc61161f9152c88e15b77563a4413519f6155992
Reviewed-on: https://weave-review.googlesource.com/1150
Reviewed-by: Vitaly Buka <vitalybuka@google.com>
diff --git a/libweave/examples/ubuntu/file_config_store.cc b/libweave/examples/ubuntu/file_config_store.cc
index b2bfd0a..d8440b1 100644
--- a/libweave/examples/ubuntu/file_config_store.cc
+++ b/libweave/examples/ubuntu/file_config_store.cc
@@ -91,6 +91,13 @@
       "updateBaseConfiguration": {},
       "identify": {},
       "updateDeviceInfo": {}
+    },
+    "_greeter": {
+      "_greet": {
+        "minimalRole": "user",
+        "parameters": { "_name": "string"},
+        "results": { "_greeting": "string" }
+      }
     }
   })"}};
 }
diff --git a/libweave/examples/ubuntu/main.cc b/libweave/examples/ubuntu/main.cc
index e4c4db7..00f9b86 100644
--- a/libweave/examples/ubuntu/main.cc
+++ b/libweave/examples/ubuntu/main.cc
@@ -35,9 +35,20 @@
  private:
   void OnNewCommand(weave::Command* cmd) {
     LOG(INFO) << "received command: " << cmd->GetName();
-    if (cmd->GetName() == "base.identify") {
+    if (cmd->GetName() == "_greeter._greet") {
+      std::string name;
+      cmd->GetParameters()->GetString("_name", &name);
+      if (name.empty()) {
+        name = cmd->GetOrigin() == weave::CommandOrigin::kCloud
+            ? "cloud user"
+            : "local user";
+      }
+      LOG(INFO) << "vendor _greeter._greet command: in progress";
       cmd->SetProgress(base::DictionaryValue{}, nullptr);
-      LOG(INFO) << "base.identify command: completed";
+      base::DictionaryValue result;
+      result.SetString("_greeting", "Hello " + name);
+      cmd->SetResults(result, nullptr);
+      LOG(INFO) << "vendor _greeter._greet command: finished";
       cmd->Done();
     } else {
       LOG(INFO) << "unimplemented command: ignored";