/*
*/
#define LOG_TAG "SoundSourceLocationService"
#include <stdint.h>
#include <sys/types.h>
#include <binder/Parcel.h>
#include <utils/String8.h>
#include "NativeTestService.h"
namespace android
{
NativeTestService::NativeTestService()
{
printf("create!!!\n");
}
NativeTestService::~NativeTestService()
{
}
int NativeTestService::addTestListener(const sp<ITestListener> & listener)
{
printf("%s: Add listener %p\n", __FUNCTION__, listener.get());
if (listener == 0) {
printf("%s: Listener must not be null", __FUNCTION__);
return BAD_VALUE;
}
Mutex::Autolock lock(mListenersMutex);
Vector<sp<ITestListener> >::iterator it, end;
for (it = mTestListenerList.begin(); it != mTestListenerList.end(); ++it) {
if ((*it)->asBinder() == listener->asBinder()) {
ALOGW("%s: Tried to add listener %p which was already subscribed\n",
__FUNCTION__, listener.get());
return ALREADY_EXISTS;
}
}
mTestListenerList.push_back(listener);
addMonitorTestListener(listener);
return 0;
}
int NativeTestService::removeTestListener(const sp<ITestListener> & listener)
{
pid_t pid = IPCThreadState::self()->getCallingPid();
if(pid != getpid())
removeMonitorTestListener(pid);
if (listener == 0) {
printf("%s: Listener must not be null\n", __FUNCTION__);
return BAD_VALUE;
}
Mutex::Autolock lock(mListenersMutex);
Vector<sp<ITestListener> >::iterator it;
for (it = mTestListenerList.begin(); it != mTestListenerList.end(); ++it) {
if ((*it)->asBinder() == listener->asBinder()) {
mTestListenerList.erase(it);
return OK;
}
}
printf("%s: Tried to remove a listener %p which was not subscribed\n",
__FUNCTION__, listener.get());
return BAD_VALUE;
}
void NativeTestService::addMonitorTestListener(const sp<ITestListener> & listener)
{
Mutex::Autolock _l(mLock);
pid_t pid = IPCThreadState::self()->getCallingPid();
if (mMonitorTestListeners.indexOfKey(pid) < 0) {
sp<MonitorTestListener> monitorTestListener = new MonitorTestListener(this,
listener,
pid);
printf("addMonitorTestListener() client %p, pid %d\n", monitorTestListener.get(), pid);
mMonitorTestListeners.add(pid, monitorTestListener);
sp<IBinder> binder = listener->asBinder();
binder->linkToDeath(monitorTestListener);
}
}
void NativeTestService::removeMonitorTestListener(pid_t pid)
{
Mutex::Autolock _l(mLock);
printf("removeMonitorTestListener() pid %d\n", pid);
mMonitorTestListeners.removeItem(pid);
}
// ----------------------------------------------------------------------------
NativeTestService::MonitorTestListener::MonitorTestListener(const sp<NativeTestService>& nativeService,
const sp<ITestListener>& listener,
pid_t pid)
: mNativeService(nativeService), mPid(pid), mTestListener(listener)
{
}
NativeTestService::MonitorTestListener::~MonitorTestListener()
{
}
void NativeTestService::MonitorTestListener::binderDied(const wp<IBinder>& who)
{
//sp<NotificationClient> keep(this);
//mAudioFlinger->removeNotificationClient(mPid);
printf("%s: %d is died!!! MonitorTestListener::binderDied\n", __FUNCTION__, mPid);
mNativeService->removeMonitorTestListener(mPid);
mNativeService->removeTestListener(mTestListener);
}
}; /* namespace android */
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android本地服务示例代码.rar (12个子文件)
frameworks
native
include
ssl
NativeTestManager.h 1KB
ITestListener.h 862B
INativeTestService.h 854B
services
nativetestservice
NativeTestService.h 2KB
main_service.cpp 340B
NativeTestService.cpp 4KB
Android.mk 490B
libs
nativetest
NativeTestManager.cpp 1KB
Android.mk 654B
INativeTestService.cpp 3KB
NativeTestManagerTest.cpp 2KB
ITestListener.cpp 3KB
共 12 条
- 1
资源评论
JKingCHEN
- 粉丝: 168
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功