This commit is contained in:
ioacademy-jikim
2018-06-14 10:57:45 +09:00
parent c56f3d90b8
commit af0342feb7
13 changed files with 1444 additions and 3 deletions
+12 -3
View File
@@ -1,5 +1,5 @@
cc_defaults {
name: "my_flags",
name: "my_flags_2",
cflags: [
"-Wall",
@@ -16,11 +16,20 @@ cc_defaults {
}
cc_binary {
name: "my_server_1",
defaults: ["my_flags"],
name: "my_server_2",
defaults: ["my_flags_2"],
srcs: [
"my_server.c",
"binder.c",
],
}
cc_binary {
name: "my_client_2",
defaults: ["my_flags_2"],
srcs: [
"my_client.c",
"binder.c",
],
}
+54
View File
@@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "binder.h"
uint32_t svcmgr_lookup(struct binder_state *bs, uint32_t target, const char *name)
{
uint32_t handle;
unsigned iodata[512/4];
struct binder_io msg, reply;
bio_init(&msg, iodata, sizeof(iodata), 4);
bio_put_uint32(&msg, 0); // strict mode header
bio_put_string16_x(&msg, SVC_MGR_NAME);
bio_put_string16_x(&msg, name);
if (binder_call(bs, &msg, &reply, target, SVC_MGR_CHECK_SERVICE))
return 0;
handle = bio_get_ref(&reply);
if (handle)
binder_acquire(bs, handle);
binder_done(bs, &msg, &reply);
return handle;
}
int main(int argc, char **argv)
{
struct binder_state *bs;
uint32_t svcmgr = BINDER_SERVICE_MANAGER;
uint32_t handle;
unsigned iodata[512/4];
struct binder_io msg, reply;
bs = binder_open("/dev/binder", 128*1024);
if (!bs) {
fprintf(stderr, "failed to open binder driver\n");
return -1;
}
handle = svcmgr_lookup(bs, svcmgr, argv[argc-1]);
fprintf(stderr,"lookup(%s) = %x\n", argv[argc-1], handle);
bio_init(&msg, iodata, sizeof(iodata), 4);
binder_call(bs, &msg, &reply, handle, 1);
return 0;
}
+12
View File
@@ -36,6 +36,17 @@ int my_handler(struct binder_state *bs,
struct binder_io *reply)
{
printf("my_handler %p %p %p %p\n", bs, txn, msg, reply);
switch(txn->code) {
case 1:
printf("Server : LED_ON, %p\n", (void*)txn->target.ptr);
return 0;
default:
printf("unknown code %d\n", txn->code);
return -1;
}
bio_put_uint32(reply, 0);
return 0;
}
@@ -53,6 +64,7 @@ int main(int argc, char **argv)
return -1;
}
printf("Server : &token = %p\n", &token );
svcmgr_publish(bs, svcmgr, argv[argc-1], &token);
binder_loop(bs, my_handler);
return 0;