Ejemplo n.º 1
0
// 默认的死亡通知函数,即释放service对应的binder_ref
void svcinfo_death(struct binder_state *bs, void *ptr)
{
    struct svcinfo *si = ptr;
    ALOGI("service '%s' died\n", str8(si->name));
    if (si->ptr) {
        binder_release(bs, si->ptr);
        si->ptr = 0;
    }   
}
void svcinfo_death(struct binder_state *bs, void *ptr)
{
    struct svcinfo *si = (struct svcinfo* ) ptr;

    ALOGI("service '%s' died\n", str8(si->name, si->len));
    if (si->handle) {
        binder_release(bs, si->handle);
        si->handle = 0;
    }
}
Ejemplo n.º 3
0
/* ./test_client hello
*  ./test_client hello <name>
*/
int main(int argc, char **argv)
{
    int fd;
    struct binder_state *bs;
    uint32_t svcmgr = BINDER_SERVICE_MANAGER;
    uint32_t handle;
	int ret;

	if(argc < 2){
		fprintf(stderr, "Usage:\n");
		fprintf(stderr, "%s <hello|goodbye>\n", argv[0]);
		fprintf(stderr, "%s <hello|goodbye> <name>\n", argv[0]);
		return -1;
	}

    bs = binder_open(128*1024);
    if (!bs) {
        fprintf(stderr, "failed to open binder driver\n");
        return -1;
    }
	g_bs = bs;

	handle = svcmgr_lookup(bs, svcmgr, "goodbye");
	if(!handle){
		fprintf(stderr, "failed to get goodbye service\n");
        return -1;
	}
	g_goodbye_handle = handle;
	fprintf(stderr, "Handle for goodbye service = %d\n", g_goodbye_handle);

	/* get service */
	handle = svcmgr_lookup(bs, svcmgr, "hello");
	if(!handle){
		fprintf(stderr, "failed to get hello service\n");
        return -1;
	}
	g_hello_handle = handle;
	fprintf(stderr, "Handle for hello service = %d\n", g_hello_handle);
	
	/* send data to server */
	if(!strcmp(argv[1], "hello"))
	{	
		if(argc == 2){
				sayhello();
			}else if(argc == 3){
				ret = sayhello_to(argv[2]);
				fprintf(stderr, "get ret of sayhello_to = %d\n",ret);
			}
	}
	else if(!strcmp(argv[1], "goodbye"))
	{	
		if(argc == 2){
				saygoodbye();
			}else if(argc == 3){
				ret = saygoodbye_to(argv[2]);
				fprintf(stderr, "get ret of saygoodbye_to = %d\n",ret);
			}
	}
	
	binder_release(bs, handle);
    return 0;
}