summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalph Nathan <ralphnathan@google.com>2015-12-03 15:24:30 -0800
committerRalph Nathan <ralphnathan@google.com>2015-12-03 15:26:30 -0800
commit6eb09da358e241055155f2ef1886f3a6c684df4a (patch)
treee53f6b1de681928dae1aa5729048aae5f4885328
parent763c33d2c58595cda69809531d2fc1ac9b2e8aa5 (diff)
downloadcommon-6eb09da358e241055155f2ef1886f3a6c684df4a.tar.gz
Move service example from device/generic/brillo.
Centralize all the example code for Brillo by moving the service example from device/generic/brillo. BUG=25927954 TEST=none Change-Id: I121f09243784c5e75e585cdaa6668cfa8a5c1982
-rw-r--r--service_example/Android.mk39
-rw-r--r--service_example/init.testservice.rc.example4
-rw-r--r--service_example/testservice.cpp31
3 files changed, 74 insertions, 0 deletions
diff --git a/service_example/Android.mk b/service_example/Android.mk
new file mode 100644
index 0000000..50eb925
--- /dev/null
+++ b/service_example/Android.mk
@@ -0,0 +1,39 @@
+# Copyright 2015 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := testservice
+LOCAL_REQUIRED_MODULES := init.testservice.rc
+LOCAL_SRC_FILES := testservice.cpp
+LOCAL_SHARED_LIBRARIES := libc libbase
+LOCAL_CFLAGS := -Werror
+include $(BUILD_EXECUTABLE)
+
+ifdef INITRC_TEMPLATE
+include $(CLEAR_VARS)
+LOCAL_MODULE := init.testservice.rc
+LOCAL_MODULE_CLASS := ETC
+LOCAL_MODULE_PATH := $(PRODUCT_OUT)/$(TARGET_COPY_OUT_INITRCD)
+
+include $(BUILD_SYSTEM)/base_rules.mk
+
+.PHONY: $(LOCAL_BUILT_MODULE)
+$(LOCAL_BUILT_MODULE): my_args := arg1 arg2
+$(LOCAL_BUILT_MODULE): my_groups := inet
+$(LOCAL_BUILT_MODULE): $(INITRC_TEMPLATE)
+ $(call generate-initrc-file,testservice,$(my_args),\
+ $(my_groups))
+endif
diff --git a/service_example/init.testservice.rc.example b/service_example/init.testservice.rc.example
new file mode 100644
index 0000000..572d5f3
--- /dev/null
+++ b/service_example/init.testservice.rc.example
@@ -0,0 +1,4 @@
+service testservice /system/bin/testservice
+ class main
+ user system
+ group system
diff --git a/service_example/testservice.cpp b/service_example/testservice.cpp
new file mode 100644
index 0000000..1e579b3
--- /dev/null
+++ b/service_example/testservice.cpp
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "testservice"
+
+#include <unistd.h>
+
+#include <base/logging.h>
+
+int main(int argc __unused, char **argv __unused) {
+ LOG(INFO) << "starting";
+ while (1) {
+ LOG(INFO) << "loop iteration";
+ sleep(5);
+ }
+ LOG(INFO) << "exiting";
+ return 0;
+}