1
0
mirror of https://github.com/ioacademy-jikim/android_framwork synced 2025-06-07 16:06:29 +00:00
This commit is contained in:
ioacademy-jikim 2018-06-14 15:59:12 +09:00
parent ecb311055a
commit 46d02d8dd3
11 changed files with 236 additions and 1 deletions

Binary file not shown.

View File

@ -5,3 +5,11 @@ cc_binary {
"my_server.cpp",
],
}
cc_binary {
name: "my_client_cpp_1",
shared_libs: ["liblog", "libutils", "libbinder"],
srcs: [
"my_client.cpp",
],
}

View File

@ -0,0 +1,22 @@
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/Binder.h>
#include <binder/IPCThreadState.h>
#include <utils/String16.h>
using namespace android;
int main()
{
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm(defaultServiceManager());
sp<IBinder> binder = sm->getService( String16("led.service") );
Parcel data, reply;
binder->transact(1, data, &reply);
return 0;
}

View File

@ -7,11 +7,28 @@
using namespace android;
class LedService : public BBinder
{
public:
status_t onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch (code) {
case 1:
printf("LedService::LED_ON\n");
return NO_ERROR;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
};
int main()
{
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm(defaultServiceManager());
sm->addService( String16("led.service"), new BBinder );
sm->addService( String16("led.service"), new LedService );
IPCThreadState::self()->joinThreadPool();
return 0;

Binary file not shown.

View File

@ -0,0 +1,16 @@
cc_binary {
name: "my_server_cpp_2",
shared_libs: ["liblog", "libutils", "libbinder"],
srcs: [
"my_server.cpp",
],
}
cc_binary {
name: "my_client_cpp_2",
shared_libs: ["liblog", "libutils", "libbinder"],
srcs: [
"my_client.cpp",
"ILedService.cpp",
],
}

View File

@ -0,0 +1,31 @@
#define LOG_TAG "LedService"
#include "ILedService.h"
#include <binder/IPCThreadState.h>
#include <binder/Parcel.h>
#include <unistd.h>
namespace android {
// ----------------------------------------------------------------------
class BpLedService : public BpInterface<ILedService>
{
public:
explicit BpLedService(const sp<IBinder>& impl)
: BpInterface<ILedService>(impl)
{
}
virtual void ledOn(void)
{
printf("BpLedService::ledOn()\n");
Parcel data, reply;
remote()->transact(LED_ON, data, &reply);
}
};
IMPLEMENT_META_INTERFACE(LedService, "android.os.ILedService");
}; // namespace android

View File

@ -0,0 +1,26 @@
#ifndef ANDROID_ILED_SERVICE_H
#define ANDROID_ILED_SERVICE_H
#include <binder/IInterface.h>
#include <utils/String16.h>
namespace android {
// ----------------------------------------------------------------------
class ILedService : public IInterface
{
public:
DECLARE_META_INTERFACE(LedService)
virtual void ledOn() = 0;
enum {
LED_ON = IBinder::FIRST_CALL_TRANSACTION
};
};
}; // namespace android
#endif // ANDROID_ISERVICE_MANAGER_H

View File

@ -0,0 +1,54 @@
#if 1
#include <stdio.h>
class ProcessState
{
static ProcessState *gProcess;
ProcessState()
{
printf("fd=open(\"/dev/binder\", O_RDWR)\n");
}
public:
static ProcessState *self()
{
if( gProcess == 0 )
gProcess = new ProcessState;
return gProcess;
}
~ProcessState()
{
printf("close(fd)\n");
}
};
ProcessState *ProcessState::gProcess = 0;
int main()
{
ProcessState *p1 = ProcessState::self();
ProcessState *p2 = ProcessState::self();
//ProcessState process;
return 0;
}
#endif
#if 0
#include <stdio.h>
class ProcessState
{
public:
ProcessState()
{
printf("fd=open(\"/dev/binder\", O_RDWR)\n");
}
~ProcessState()
{
printf("close(fd)\n");
}
};
int main()
{
ProcessState p1;
ProcessState p2;
return 0;
}
#endif

View File

@ -0,0 +1,23 @@
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/Binder.h>
#include <binder/IPCThreadState.h>
#include <utils/String16.h>
#include "ILedService.h"
using namespace android;
int main()
{
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm(defaultServiceManager());
sp<IBinder> binder = sm->getService( String16("led.service") );
sp<ILedService> led = interface_cast<ILedService>( binder );
led->ledOn();
return 0;
}

View File

@ -0,0 +1,38 @@
#include <binder/ProcessState.h>
#include <binder/IServiceManager.h>
#include <binder/Binder.h>
#include <binder/IPCThreadState.h>
#include <utils/String16.h>
using namespace android;
class LedService : public BBinder
{
public:
status_t onTransact(
uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
{
switch (code) {
case 1:
printf("LedService::LED_ON\n");
return NO_ERROR;
default:
return BBinder::onTransact(code, data, reply, flags);
}
}
};
int main()
{
sp<ProcessState> proc(ProcessState::self());
sp<IServiceManager> sm(defaultServiceManager());
sm->addService( String16("led.service"), new LedService );
IPCThreadState::self()->joinThreadPool();
return 0;
}