blob: b2bef07ff70e7c992e8d11ba1887e1739dc9f47d [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001//
2// Copyright 2005 The Android Open Source Project
3//
4
5#define LOG_TAG "ServiceManager"
6
7#include "ServiceManager.h"
8#include "SignalHandler.h"
9
10#include <utils/Debug.h>
11#include <utils/Log.h>
Mathias Agopian07952722009-05-19 19:08:10 -070012#include <binder/Parcel.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080013#include <utils/String8.h>
Mathias Agopian07952722009-05-19 19:08:10 -070014#include <binder/ProcessState.h>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080015
16#include <private/utils/Static.h>
17
18#include <ctype.h>
19#include <errno.h>
20#include <limits.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <sys/stat.h>
24
25namespace android {
26
27BServiceManager::BServiceManager()
28{
29}
30
31sp<IBinder> BServiceManager::getService(const String16& name) const
32{
33 AutoMutex _l(mLock);
34 ssize_t i = mServices.indexOfKey(name);
35 LOGV("ServiceManager: getService(%s) -> %d\n", String8(name).string(), i);
36 if (i >= 0) return mServices.valueAt(i);
37 return NULL;
38}
39
40sp<IBinder> BServiceManager::checkService(const String16& name) const
41{
42 AutoMutex _l(mLock);
43 ssize_t i = mServices.indexOfKey(name);
44 LOGV("ServiceManager: getService(%s) -> %d\n", String8(name).string(), i);
45 if (i >= 0) return mServices.valueAt(i);
46 return NULL;
47}
48
49status_t BServiceManager::addService(const String16& name, const sp<IBinder>& service)
50{
51 AutoMutex _l(mLock);
52 LOGI("ServiceManager: addService(%s, %p)\n", String8(name).string(), service.get());
53 const ssize_t res = mServices.add(name, service);
54 if (res >= NO_ERROR) {
55 mChanged.broadcast();
56 return NO_ERROR;
57 }
58 return res;
59}
60
61Vector<String16> BServiceManager::listServices()
62{
63 Vector<String16> res;
64
65 AutoMutex _l(mLock);
66 const size_t N = mServices.size();
67 for (size_t i=0; i<N; i++) {
68 res.add(mServices.keyAt(i));
69 }
70
71 return res;
72}
73
74}; // namespace android