summaryrefslogtreecommitdiffstats
path: root/cmds/runtime/ServiceManager.cpp
blob: 758a95c07d56a71bbe664204de50cdb29bfb62b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//
// Copyright 2005 The Android Open Source Project
//

#define LOG_TAG "ServiceManager"

#include "ServiceManager.h"
#include "SignalHandler.h"

#include <utils/Debug.h>
#include <utils/Log.h>
#include <utils/Parcel.h>
#include <utils/String8.h>
#include <utils/ProcessState.h>

#include <private/utils/Static.h>

#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

namespace android {

BServiceManager::BServiceManager()
{
}

sp<IBinder> BServiceManager::getService(const String16& name) const
{
    AutoMutex _l(mLock);
    ssize_t i = mServices.indexOfKey(name);
    LOGV("ServiceManager: getService(%s) -> %d\n", String8(name).string(), i);
    if (i >= 0) return mServices.valueAt(i);
    return NULL;
}

sp<IBinder> BServiceManager::checkService(const String16& name) const
{
    AutoMutex _l(mLock);
    ssize_t i = mServices.indexOfKey(name);
    LOGV("ServiceManager: getService(%s) -> %d\n", String8(name).string(), i);
    if (i >= 0) return mServices.valueAt(i);
    return NULL;
}

status_t BServiceManager::addService(const String16& name, const sp<IBinder>& service)
{
    AutoMutex _l(mLock);
    LOGI("ServiceManager: addService(%s, %p)\n", String8(name).string(), service.get());
    const ssize_t res = mServices.add(name, service);
    if (res >= NO_ERROR) {
        mChanged.broadcast();
        return NO_ERROR;
    }
    return res;
}

Vector<String16> BServiceManager::listServices()
{
    Vector<String16> res;

    AutoMutex _l(mLock);
    const size_t N = mServices.size();
    for (size_t i=0; i<N; i++) {
        res.add(mServices.keyAt(i));
    }

    return res;
}

}; // namespace android