2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_BINDER_SERVICE_H
18 #define ANDROID_BINDER_SERVICE_H
22 #include <utils/Errors.h>
23 #include <utils/String16.h>
25 #include <binder/IServiceManager.h>
26 #include <binder/IPCThreadState.h>
27 #include <binder/ProcessState.h>
28 #include <binder/IServiceManager.h>
30 // ---------------------------------------------------------------------------
33 template<typename SERVICE>
37 static status_t publish(bool allowIsolated = false) {
38 sp<IServiceManager> sm(defaultServiceManager());
39 return sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated);
42 static void publishAndJoinThreadPool(bool allowIsolated = false) {
43 sp<ProcessState> proc(ProcessState::self());
44 sp<IServiceManager> sm(defaultServiceManager());
45 sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated);
46 ProcessState::self()->startThreadPool();
47 IPCThreadState::self()->joinThreadPool();
50 static void instantiate() { publish(); }
52 static status_t shutdown() {
58 }; // namespace android
59 // ---------------------------------------------------------------------------
60 #endif // ANDROID_BINDER_SERVICE_H