{"action":"created","comment":{"url":"https://api.github.com/repos/ros2/demos/pulls/comments/92125906","pull_request_review_id":12633073,"id":92125906,"diff_hunk":"@@ -0,0 +1,161 @@\n+// Copyright 2016 Open Source Robotics Foundation, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+#include <memory>\n+#include <string>\n+\n+#include \"lifecycle_msgs/msg/state.hpp\"\n+#include \"lifecycle_msgs/msg/transition.hpp\"\n+#include \"lifecycle_msgs/srv/change_state.hpp\"\n+#include \"lifecycle_msgs/srv/get_state.hpp\"\n+\n+#include \"rclcpp/rclcpp.hpp\"\n+\n+// service topics for node-attached services\n+static constexpr char const * lifecycle_node = \"lc_talker\";\n+static constexpr char const * node_get_state_topic = \"lc_talker__get_state\";\n+static constexpr char const * node_change_state_topic = \"lc_talker__change_state\";\n+\n+class LifecycleServiceClient : public rclcpp::node::Node\n+{\n+public:\n+  explicit LifecycleServiceClient(const std::string & node_name)\n+  : rclcpp::node::Node(node_name)\n+  {}\n+\n+  void\n+  init()\n+  {\n+    // Service client pointing to each individual service\n+    client_get_state_ = this->create_client<lifecycle_msgs::srv::GetState>(\n+      node_get_state_topic);\n+    client_change_state_ = this->create_client<lifecycle_msgs::srv::ChangeState>(\n+      node_change_state_topic);\n+  }\n+\n+  unsigned int\n+  get_state(std::chrono::seconds time_out = 3_s)\n+  {\n+    auto request = std::make_shared<lifecycle_msgs::srv::GetState::Request>();\n+\n+    if (!client_get_state_->wait_for_service(time_out)) {\n+      fprintf(stderr, \"Service %s is not available.\\n\",\n+        client_get_state_->get_service_name().c_str());\n+      return lifecycle_msgs::msg::State::PRIMARY_STATE_UNKNOWN;\n+    }\n+\n+    auto result = client_get_state_->async_send_request(request);\n+    if (result.wait_for(std::chrono::milliseconds(time_out)) != std::future_status::ready) {\n+      fprintf(stderr, \"[%s] Failed to get current state for node %s. Server timed out.\\n\",\n+        get_name(), lifecycle_node);\n+      return lifecycle_msgs::msg::State::PRIMARY_STATE_UNKNOWN;\n+    }\n+\n+    if (result.get()) {\n+      printf(\"[%s] Node %s has current state %s.\\n\",\n+        get_name(), lifecycle_node, result.get()->current_state.label.c_str());\n+      return result.get()->current_state.id;\n+    } else {\n+      fprintf(stderr, \"[%s] Failed to get current state for node %s\\n\",\n+        get_name(), lifecycle_node);\n+      return lifecycle_msgs::msg::State::PRIMARY_STATE_UNKNOWN;\n+    }\n+  }\n+\n+  bool\n+  change_state(std::uint8_t transition, std::chrono::seconds time_out = 3_s)\n+  {\n+    auto request = std::make_shared<lifecycle_msgs::srv::ChangeState::Request>();\n+    request->transition.id = transition;\n+\n+    if (!client_change_state_->wait_for_service(time_out)) {\n+      fprintf(stderr, \"Service %s is not available.\\n\",\n+        client_change_state_->get_service_name().c_str());\n+      return false;\n+    }\n+\n+    auto result = client_change_state_->async_send_request(request);\n+    if (result.wait_for(std::chrono::milliseconds(time_out)) != std::future_status::ready) {","path":"lifecycle/src/lifecycle_service_client.cpp","position":89,"original_position":89,"commit_id":"e0512f23bc829d76880065943bee79e3d818fe43","original_commit_id":"e0512f23bc829d76880065943bee79e3d818fe43","user":{"login":"wjwwood","id":100427,"avatar_url":"https://avatars.githubusercontent.com/u/100427?v=3","gravatar_id":"","url":"https://api.github.com/users/wjwwood","html_url":"https://github.com/wjwwood","followers_url":"https://api.github.com/users/wjwwood/followers","following_url":"https://api.github.com/users/wjwwood/following{/other_user}","gists_url":"https://api.github.com/users/wjwwood/gists{/gist_id}","starred_url":"https://api.github.com/users/wjwwood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wjwwood/subscriptions","organizations_url":"https://api.github.com/users/wjwwood/orgs","repos_url":"https://api.github.com/users/wjwwood/repos","events_url":"https://api.github.com/users/wjwwood/events{/privacy}","received_events_url":"https://api.github.com/users/wjwwood/received_events","type":"User","site_admin":false},"body":"This is tricky, since it only works because you are spinning in a different thread. It might warrant a comment.","created_at":"2016-12-13T09:22:03Z","updated_at":"2016-12-13T09:26:03Z","html_url":"https://github.com/ros2/demos/pull/86#discussion_r92125906","pull_request_url":"https://api.github.com/repos/ros2/demos/pulls/86","_links":{"self":{"href":"https://api.github.com/repos/ros2/demos/pulls/comments/92125906"},"html":{"href":"https://github.com/ros2/demos/pull/86#discussion_r92125906"},"pull_request":{"href":"https://api.github.com/repos/ros2/demos/pulls/86"}}},"pull_request":{"url":"https://api.github.com/repos/ros2/demos/pulls/86","id":95624359,"html_url":"https://github.com/ros2/demos/pull/86","diff_url":"https://github.com/ros2/demos/pull/86.diff","patch_url":"https://github.com/ros2/demos/pull/86.patch","issue_url":"https://api.github.com/repos/ros2/demos/issues/86","number":86,"state":"open","locked":false,"title":"(refactor) add lifecycle demo","user":{"login":"Karsten1987","id":5419873,"avatar_url":"https://avatars.githubusercontent.com/u/5419873?v=3","gravatar_id":"","url":"https://api.github.com/users/Karsten1987","html_url":"https://github.com/Karsten1987","followers_url":"https://api.github.com/users/Karsten1987/followers","following_url":"https://api.github.com/users/Karsten1987/following{/other_user}","gists_url":"https://api.github.com/users/Karsten1987/gists{/gist_id}","starred_url":"https://api.github.com/users/Karsten1987/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karsten1987/subscriptions","organizations_url":"https://api.github.com/users/Karsten1987/orgs","repos_url":"https://api.github.com/users/Karsten1987/repos","events_url":"https://api.github.com/users/Karsten1987/events{/privacy}","received_events_url":"https://api.github.com/users/Karsten1987/received_events","type":"User","site_admin":false},"body":"demo applications for lifecycle (C++)\r\n\r\nConnects to ros2/rclcpp#265","created_at":"2016-11-29T04:21:34Z","updated_at":"2016-12-13T09:26:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b606e44ac499b0e2dd50eb71e044d7bb3fc5ad5","assignee":{"login":"Karsten1987","id":5419873,"avatar_url":"https://avatars.githubusercontent.com/u/5419873?v=3","gravatar_id":"","url":"https://api.github.com/users/Karsten1987","html_url":"https://github.com/Karsten1987","followers_url":"https://api.github.com/users/Karsten1987/followers","following_url":"https://api.github.com/users/Karsten1987/following{/other_user}","gists_url":"https://api.github.com/users/Karsten1987/gists{/gist_id}","starred_url":"https://api.github.com/users/Karsten1987/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karsten1987/subscriptions","organizations_url":"https://api.github.com/users/Karsten1987/orgs","repos_url":"https://api.github.com/users/Karsten1987/repos","events_url":"https://api.github.com/users/Karsten1987/events{/privacy}","received_events_url":"https://api.github.com/users/Karsten1987/received_events","type":"User","site_admin":false},"assignees":[{"login":"Karsten1987","id":5419873,"avatar_url":"https://avatars.githubusercontent.com/u/5419873?v=3","gravatar_id":"","url":"https://api.github.com/users/Karsten1987","html_url":"https://github.com/Karsten1987","followers_url":"https://api.github.com/users/Karsten1987/followers","following_url":"https://api.github.com/users/Karsten1987/following{/other_user}","gists_url":"https://api.github.com/users/Karsten1987/gists{/gist_id}","starred_url":"https://api.github.com/users/Karsten1987/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Karsten1987/subscriptions","organizations_url":"https://api.github.com/users/Karsten1987/orgs","repos_url":"https://api.github.com/users/Karsten1987/repos","events_url":"https://api.github.com/users/Karsten1987/events{/privacy}","received_events_url":"https://api.github.com/users/Karsten1987/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ros2/demos/pulls/86/commits","review_comments_url":"https://api.github.com/repos/ros2/demos/pulls/86/comments","review_comment_url":"https://api.github.com/repos/ros2/demos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ros2/demos/issues/86/comments","statuses_url":"https://api.github.com/repos/ros2/demos/statuses/e0512f23bc829d76880065943bee79e3d818fe43","head":{"label":"ros2:lifecycle_impl","ref":"lifecycle_impl","sha":"e0512f23bc829d76880065943bee79e3d818fe43","user":{"login":"ros2","id":3979232,"avatar_url":"https://avatars.githubusercontent.com/u/3979232?v=3","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"repo":{"id":39266291,"name":"demos","full_name":"ros2/demos","owner":{"login":"ros2","id":3979232,"avatar_url":"https://avatars.githubusercontent.com/u/3979232?v=3","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ros2/demos","description":null,"fork":false,"url":"https://api.github.com/repos/ros2/demos","forks_url":"https://api.github.com/repos/ros2/demos/forks","keys_url":"https://api.github.com/repos/ros2/demos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ros2/demos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ros2/demos/teams","hooks_url":"https://api.github.com/repos/ros2/demos/hooks","issue_events_url":"https://api.github.com/repos/ros2/demos/issues/events{/number}","events_url":"https://api.github.com/repos/ros2/demos/events","assignees_url":"https://api.github.com/repos/ros2/demos/assignees{/user}","branches_url":"https://api.github.com/repos/ros2/demos/branches{/branch}","tags_url":"https://api.github.com/repos/ros2/demos/tags","blobs_url":"https://api.github.com/repos/ros2/demos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ros2/demos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ros2/demos/git/refs{/sha}","trees_url":"https://api.github.com/repos/ros2/demos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ros2/demos/statuses/{sha}","languages_url":"https://api.github.com/repos/ros2/demos/languages","stargazers_url":"https://api.github.com/repos/ros2/demos/stargazers","contributors_url":"https://api.github.com/repos/ros2/demos/contributors","subscribers_url":"https://api.github.com/repos/ros2/demos/subscribers","subscription_url":"https://api.github.com/repos/ros2/demos/subscription","commits_url":"https://api.github.com/repos/ros2/demos/commits{/sha}","git_commits_url":"https://api.github.com/repos/ros2/demos/git/commits{/sha}","comments_url":"https://api.github.com/repos/ros2/demos/comments{/number}","issue_comment_url":"https://api.github.com/repos/ros2/demos/issues/comments{/number}","contents_url":"https://api.github.com/repos/ros2/demos/contents/{+path}","compare_url":"https://api.github.com/repos/ros2/demos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ros2/demos/merges","archive_url":"https://api.github.com/repos/ros2/demos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ros2/demos/downloads","issues_url":"https://api.github.com/repos/ros2/demos/issues{/number}","pulls_url":"https://api.github.com/repos/ros2/demos/pulls{/number}","milestones_url":"https://api.github.com/repos/ros2/demos/milestones{/number}","notifications_url":"https://api.github.com/repos/ros2/demos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ros2/demos/labels{/name}","releases_url":"https://api.github.com/repos/ros2/demos/releases{/id}","deployments_url":"https://api.github.com/repos/ros2/demos/deployments","created_at":"2015-07-17T17:24:00Z","updated_at":"2016-10-26T02:54:00Z","pushed_at":"2016-12-13T05:12:31Z","git_url":"git://github.com/ros2/demos.git","ssh_url":"git@github.com:ros2/demos.git","clone_url":"https://github.com/ros2/demos.git","svn_url":"https://github.com/ros2/demos","homepage":null,"size":1092,"stargazers_count":5,"watchers_count":5,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":12,"forks":7,"open_issues":12,"watchers":5,"default_branch":"master"}},"base":{"label":"ros2:master","ref":"master","sha":"70f98266d6fe2dbc379990c53e05eb93e5173ae1","user":{"login":"ros2","id":3979232,"avatar_url":"https://avatars.githubusercontent.com/u/3979232?v=3","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"repo":{"id":39266291,"name":"demos","full_name":"ros2/demos","owner":{"login":"ros2","id":3979232,"avatar_url":"https://avatars.githubusercontent.com/u/3979232?v=3","gravatar_id":"","url":"https://api.github.com/users/ros2","html_url":"https://github.com/ros2","followers_url":"https://api.github.com/users/ros2/followers","following_url":"https://api.github.com/users/ros2/following{/other_user}","gists_url":"https://api.github.com/users/ros2/gists{/gist_id}","starred_url":"https://api.github.com/users/ros2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ros2/subscriptions","organizations_url":"https://api.github.com/users/ros2/orgs","repos_url":"https://api.github.com/users/ros2/repos","events_url":"https://api.github.com/users/ros2/events{/privacy}","received_events_url":"https://api.github.com/users/ros2/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ros2/demos","description":null,"fork":false,"url":"https://api.github.com/repos/ros2/demos","forks_url":"https://api.github.com/repos/ros2/demos/forks","keys_url":"https://api.github.com/repos/ros2/demos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ros2/demos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ros2/demos/teams","hooks_url":"https://api.github.com/repos/ros2/demos/hooks","issue_events_url":"https://api.github.com/repos/ros2/demos/issues/events{/number}","events_url":"https://api.github.com/repos/ros2/demos/events","assignees_url":"https://api.github.com/repos/ros2/demos/assignees{/user}","branches_url":"https://api.github.com/repos/ros2/demos/branches{/branch}","tags_url":"https://api.github.com/repos/ros2/demos/tags","blobs_url":"https://api.github.com/repos/ros2/demos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ros2/demos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ros2/demos/git/refs{/sha}","trees_url":"https://api.github.com/repos/ros2/demos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ros2/demos/statuses/{sha}","languages_url":"https://api.github.com/repos/ros2/demos/languages","stargazers_url":"https://api.github.com/repos/ros2/demos/stargazers","contributors_url":"https://api.github.com/repos/ros2/demos/contributors","subscribers_url":"https://api.github.com/repos/ros2/demos/subscribers","subscription_url":"https://api.github.com/repos/ros2/demos/subscription","commits_url":"https://api.github.com/repos/ros2/demos/commits{/sha}","git_commits_url":"https://api.github.com/repos/ros2/demos/git/commits{/sha}","comments_url":"https://api.github.com/repos/ros2/demos/comments{/number}","issue_comment_url":"https://api.github.com/repos/ros2/demos/issues/comments{/number}","contents_url":"https://api.github.com/repos/ros2/demos/contents/{+path}","compare_url":"https://api.github.com/repos/ros2/demos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ros2/demos/merges","archive_url":"https://api.github.com/repos/ros2/demos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ros2/demos/downloads","issues_url":"https://api.github.com/repos/ros2/demos/issues{/number}","pulls_url":"https://api.github.com/repos/ros2/demos/pulls{/number}","milestones_url":"https://api.github.com/repos/ros2/demos/milestones{/number}","notifications_url":"https://api.github.com/repos/ros2/demos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ros2/demos/labels{/name}","releases_url":"https://api.github.com/repos/ros2/demos/releases{/id}","deployments_url":"https://api.github.com/repos/ros2/demos/deployments","created_at":"2015-07-17T17:24:00Z","updated_at":"2016-10-26T02:54:00Z","pushed_at":"2016-12-13T05:12:31Z","git_url":"git://github.com/ros2/demos.git","ssh_url":"git@github.com:ros2/demos.git","clone_url":"https://github.com/ros2/demos.git","svn_url":"https://github.com/ros2/demos","homepage":null,"size":1092,"stargazers_count":5,"watchers_count":5,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":12,"forks":7,"open_issues":12,"watchers":5,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ros2/demos/pulls/86"},"html":{"href":"https://github.com/ros2/demos/pull/86"},"issue":{"href":"https://api.github.com/repos/ros2/demos/issues/86"},"comments":{"href":"https://api.github.com/repos/ros2/demos/issues/86/comments"},"review_comments":{"href":"https://api.github.com/repos/ros2/demos/pulls/86/comments"},"review_comment":{"href":"https://api.github.com/repos/ros2/demos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ros2/demos/pulls/86/commits"},"statuses":{"href":"https://api.github.com/repos/ros2/demos/statuses/e0512f23bc829d76880065943bee79e3d818fe43"}}}}
{"actor":{"display_login":"wjwwood"}}