| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | // | 
|  | 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> | 
|  | 12 | #include <utils/Parcel.h> | 
|  | 13 | #include <utils/String8.h> | 
|  | 14 | #include <utils/ProcessState.h> | 
|  | 15 |  | 
|  | 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 |  | 
|  | 25 | namespace android { | 
|  | 26 |  | 
|  | 27 | BServiceManager::BServiceManager() | 
|  | 28 | { | 
|  | 29 | } | 
|  | 30 |  | 
|  | 31 | sp<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 |  | 
|  | 40 | sp<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 |  | 
|  | 49 | status_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 |  | 
|  | 61 | Vector<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 |