Пример #1
0
int main(int argc, char **argv)
{
    struct binder_state *bs;
    uint32_t svcmgr = BINDER_SERVICE_MANAGER;
    uint32_t handle;

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

    argc--;
    argv++;
    while (argc > 0) {
        if (!strcmp(argv[0],"alt")) {
            handle = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
            if (!handle) {
                fprintf(stderr,"cannot find alt_svc_mgr\n");
                return -1;
            }
            svcmgr = handle;
            fprintf(stderr,"svcmgr is via %x\n", handle);
        } else if (!strcmp(argv[0],"lookup")) {
            if (argc < 2) {
                fprintf(stderr,"argument required\n");
                return -1;
            }
            handle = svcmgr_lookup(bs, svcmgr, argv[1]);
            fprintf(stderr,"lookup(%s) = %x\n", argv[1], handle);
            argc--;
            argv++;
        } else if (!strcmp(argv[0],"publish")) {
            if (argc < 2) {
                fprintf(stderr,"argument required\n");
                return -1;
            }
            svcmgr_publish(bs, svcmgr, argv[1], &token);
            argc--;
            argv++;
        } else {
            fprintf(stderr,"unknown command %s\n", argv[0]);
            return -1;
        }
        argc--;
        argv++;
    }
    return 0;
}
Пример #2
0
int main(int argc, char **argv)
{
    int fd;
    struct binder_state *bs;
    void *svcmgr = BINDER_SERVICE_MANAGER;

    bs = binder_open(128*1024);
    LOG_IF_RETURN(bs == NULL, "ERR: bs is NULL!");

    argc--;
    argv++;
    while (argc > 0) {
        if (!strcmp(argv[0],"alt")) {
            void *ptr = svcmgr_lookup(bs, svcmgr, "alt_svc_mgr");
            if (!ptr) {
                fprintf(stderr,"cannot find alt_svc_mgr\n");
                return -1;
            }
            svcmgr = ptr;
            fprintf(stderr,"svcmgr is via %p\n", ptr);
        } else if (!strcmp(argv[0],"lookup")) {
            void *ptr;
            if (argc < 2) {
                fprintf(stderr,"argument required\n");
                return -1;
            }
            ptr = svcmgr_lookup(bs, svcmgr, argv[1]);
            fprintf(stderr,"lookup(%s) = %p\n", argv[1], ptr);
            argc--;
            argv++;
        } else if (!strcmp(argv[0],"publish")) {
            if (argc < 2) {
                fprintf(stderr,"argument required\n");
                return -1;
            }
            svcmgr_publish(bs, svcmgr, argv[1], &token);
            argc--;
            argv++;
        } else {
            fprintf(stderr,"unknown command %s\n", argv[0]);
            return -1;
        }
        argc--;
        argv++;
    }
    return 0;
}
Пример #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;
}