blob: 8caa56f8021ecaa2685179936e66dc93e47ced2d [file] [log] [blame]
Christopher Wileyb5e698c2015-10-17 09:32:22 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <iostream>
18
19#include <binder/IServiceManager.h>
20#include <utils/String16.h>
21#include <utils/StrongPointer.h>
22
23#include "android/os/IPingResponder.h"
24
25// libutils:
26using android::OK;
27using android::sp;
28using android::status_t;
29using android::String16;
30
31// libbinder:
32using android::getService;
33
34// generated
35using android::os::IPingResponder;
36
37using std::cerr;
38using std::cout;
39using std::endl;
40
41namespace {
42
43const char kServiceName[] = "android.os.IPingResponder";
44
45} // namespace
46
47int main(int argc, char *argv[]) {
48 sp<IPingResponder> service;
49 cout << "helloc: Retrieving ping service binder" << endl;
50 status_t status = getService(String16(kServiceName), &service);
51 if (status != OK) {
52 cerr << "Failed to get service binder: '" << kServiceName
53 << "' status=" << status << endl;
54 return 1;
55 }
56
57 int32_t token = 1;
58 while (true) {
59 int32_t reply = -1;
60 cout << "Pinging service with " << token << "...";
61 status_t status = service->Ping(token, &reply);
62 if (status == OK)
63 cout << "received " << reply << endl;
64 else
65 cout << "got error " << status << endl;
66 token++;
67 sleep(1);
68 }
69
70 return 0;
71}