mirror of
https://github.com/ioacademy-jikim/android_framwork
synced 2025-06-07 16:06:29 +00:00
63 lines
1.3 KiB
C
63 lines
1.3 KiB
C
/* Copyright 2008 The Android Open Source Project
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include "binder.h"
|
|
|
|
int svcmgr_publish(struct binder_state *bs, uint32_t target, const char *name, void *ptr)
|
|
{
|
|
int status;
|
|
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);
|
|
bio_put_obj(&msg, ptr);
|
|
|
|
if (binder_call(bs, &msg, &reply, target, SVC_MGR_ADD_SERVICE))
|
|
return -1;
|
|
|
|
status = bio_get_uint32(&reply);
|
|
|
|
binder_done(bs, &msg, &reply);
|
|
|
|
return status;
|
|
}
|
|
|
|
int my_handler(struct binder_state *bs,
|
|
struct binder_transaction_data *txn,
|
|
struct binder_io *msg,
|
|
struct binder_io *reply)
|
|
{
|
|
printf("my_handler %p %p %p %p\n", bs, txn, msg, reply);
|
|
return 0;
|
|
}
|
|
|
|
unsigned token;
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
struct binder_state *bs;
|
|
uint32_t svcmgr = BINDER_SERVICE_MANAGER;
|
|
|
|
bs = binder_open("/dev/binder", 128*1024);
|
|
if (!bs) {
|
|
fprintf(stderr, "failed to open binder driver\n");
|
|
return -1;
|
|
}
|
|
|
|
svcmgr_publish(bs, svcmgr, argv[argc-1], &token);
|
|
binder_loop(bs, my_handler);
|
|
return 0;
|
|
}
|
|
|
|
|
|
|