コード例 #1
0
ファイル: shm_mgr.c プロジェクト: djbclark/bb10qnx
int shm_resinit(dispatch_t *dpp)
{
	int ret;
	
	/* shmget() doesn't talk about umask but shm_open() does. */
	umask(0);

	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &shm_connect,
	    _RESMGR_IO_NFUNCS, &shm_io);
	shm_io.msg = shm_msg;
    
	iofunc_attr_init(&shm_ioattr, 0666, 0, 0);
	shm_resid = resmgr_attach(dpp, 0, PATH_SHMMGR, _FTYPE_ANY, 0,
	    &shm_connect, &shm_io, &shm_ioattr);
	if (shm_resid == -1) {
		return -1;
	}
    
	if ((ret = pthread_create(NULL, NULL, shmres_handle, dpp)) != EOK) {
		errno = ret;
		resmgr_detach(dpp, shm_resid, _RESMGR_DETACH_ALL);
		return -1;
	}
	
	return 0;
}
コード例 #2
0
ファイル: ResourceManager.c プロジェクト: msholsve/rtkos
int main(int argc, char *argv[])
{
	dispatch_t              *dpp;
	resmgr_attr_t           resmgr_attr;
	dispatch_context_t      *ctp;
	resmgr_connect_funcs_t  connect_funcs;
	resmgr_io_funcs_t       io_funcs;
	iofunc_attr_t           io_attr;

	printf("Start resource manager\n");

	fifoHandler = init_fifo();
	pthread_mutex_init(&resource_mutex, NULL);

	// create dispatch.
	if (!(dpp = dispatch_create()))
		error("dispatch_create()");

	// initialize resource manager attributes.
	memset(&resmgr_attr, 0, sizeof(resmgr_attr));
	resmgr_attr.nparts_max = 1;
	resmgr_attr.msg_max_size = 2048;

	// set standard connect and io functions.
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
	_RESMGR_IO_NFUNCS, &io_funcs);
	iofunc_attr_init(&io_attr, S_IFNAM | 0666, 0, 0);

	io_funcs.read = io_read;
	io_funcs.write = io_write;

	// establish resource manager
	if (resmgr_attach(dpp, &resmgr_attr, "/dev/myresource", _FTYPE_ANY, 0, &connect_funcs, &io_funcs, &io_attr) < 0)
		error("resmgr_attach()");

	// wait forever, handling messages.
	ctp = dispatch_context_alloc(dpp);
	while(1)
	{
		if (!(ctp = dispatch_block(ctp)))
			error("dispatch_block()");
		dispatch_handler(ctp);
	}
	exit(EXIT_SUCCESS);
}
コード例 #3
0
ファイル: example.c プロジェクト: ejoonie/mutex
main (int argc, char *argv[])
{
    int pathID;

    setvbuf (stdout, NULL, _IOLBF, 0);

    printf ("%s:  starting...\n", progname);

    options (argc, argv);

    /*
     * allocate and initialize a dispatch structure for use by our
     * main loop
    */
    
    dpp = dispatch_create ();
    if (dpp == NULL) {
        fprintf (stderr, "%s:  couldn't dispatch_create: %s\n",
                         progname, strerror (errno));
        exit (1);
    }
    
    /*
     * set up the resource manager attributes structure, we'll
     * use this as a way of passing information to resmgr_attach().
     * For now, we just use defaults.
    */
    
    memset (&rattr, 0, sizeof (rattr)); /* using the defaults for rattr */
    
    /*
     * intialize the connect functions and I/O functions tables to
     * their defaults by calling iofunc_func_init().
     * 
     * connect_funcs, and io_funcs variables are already declared.
     * 
    */
     iofunc_func_init (_RESMGR_CONNECT_NFUNCS, &connect_funcs,
                      _RESMGR_IO_NFUNCS, &io_funcs);
    
                      
    /* over-ride the connect_funcs handler for open with our io_open,
     * and over-ride the io_funcs handlers for read and write with our
     * io_read and io_write handlers
     */
    connect_funcs.open = io_open;
    io_funcs.read = io_read;
    io_funcs.write = io_write;

    
    /* initialize our device description structure
     */
     
    iofunc_attr_init (&ioattr, S_IFCHR | 0666, NULL, NULL);
    /*
     *  call resmgr_attach to register our prefix with the
     *  process manager, and also to let it know about our connect
     *  and I/O functions.
     *
     *  On error, returns -1 and errno is set.
    */
    pathID = resmgr_attach (dpp, &rattr, EXAMPLE_NAME, _FTYPE_ANY, 0,
                                     &connect_funcs, &io_funcs, &ioattr);
    if (pathID == -1) {
        fprintf (stderr, "%s:  couldn't attach pathname: %s\n",
                         progname, strerror (errno));
        exit (1);
    }

    ctp = dispatch_context_alloc (dpp);
    
    while (1) {
        if ((ctp = dispatch_block (ctp)) == NULL) {
            fprintf (stderr, "%s:  dispatch_block failed: %s\n",
                             progname, strerror (errno));
            exit (1);
        }
        dispatch_handler (ctp);
    }
}
コード例 #4
0
ファイル: main.c プロジェクト: vocho/openqnx
int main(int argc, char *argv[]) {
	dispatch_t				*dpp;
	resmgr_context_t		*ctp;
	resmgr_attr_t			res_attr;
	resmgr_connect_funcs_t	connect_funcs1;
	resmgr_connect_funcs_t	connect_funcs2;
	resmgr_io_funcs_t		io_funcs1;
	resmgr_io_funcs_t		io_funcs2;
	struct slogdev			*trp;
	int				daemon_flag = 0;

	// Parse any options.
	options(argc, argv);

	//	
	// Buffer allocation.
	// The design puts all the data structures in one big contiguious
	// chunk of memory. Makes it easy to analyze if it was in a memory
	// mapped SRAM card which survives a crash or power failure.
	//
	trp = &SlogDev;
	trp->beg = malloc(NumInts*sizeof(int));
	trp->end = trp->beg + NumInts;
	if(trp->beg == NULL) {
		fprintf(stderr, "%s: Insufficient memory to allocate buffers.\n", __progname);
		exit(EXIT_FAILURE);
	}
	slogger_init(trp);

	// Create a dispatch context to receive messages.
	if((dpp = dispatch_create()) == NULL) {
		fprintf(stderr, "%s: Unable to allocate dispatch context\n", __progname);
		exit(EXIT_FAILURE);
	}

	// Init resmgr attributes
	memset(&res_attr, 0, sizeof res_attr);
	res_attr.nparts_max = 2;
	// All slogf/slogb calls should fit in the intial receive
	res_attr.msg_max_size = _SLOG_MAXSIZE + _SLOG_HDRINTS + sizeof(io_msg_t);

	// Init funcs for handling /dev/slog messages
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs1, _RESMGR_IO_NFUNCS, &io_funcs1);
	connect_funcs1.unlink = io_unlink;
	io_funcs1.read        = io_read;
	io_funcs1.write       = io_write;
	io_funcs1.unblock     = io_unblock;

	// Create /dev/slog in the pathname space. At this point we can get opens.
	iofunc_attr_init(&trp->attr, S_IFCHR | 0666, 0, 0);
	if((trp->id = resmgr_attach(dpp, &res_attr, "/dev/slog", _FTYPE_ANY, _RESMGR_FLAG_SELF,
		&connect_funcs1, &io_funcs1, &trp->attr)) == -1) {
		fprintf(stderr, "%s: Unable to allocate device %s (%s)\n", __progname, "/dev/slog", strerror(errno));
		exit(EXIT_FAILURE);
	}

	// Init funcs for handling /dev/slog messages
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs2, _RESMGR_IO_NFUNCS, &io_funcs2);
	io_funcs2.write       = io_console_write;

	// Create /dev/console in the pathname space. At this point we can get opens.
	if(resmgr_attach(dpp, &res_attr, "/dev/console", _FTYPE_ANY, 0,
		&connect_funcs2, &io_funcs2, &trp->attr) == -1) {
		fprintf(stderr, "%s: Unable to allocate device %s (%s)\n", __progname, "/dev/console", strerror(errno));
		exit(EXIT_FAILURE);
	}

	// If a logfile was specified then create a thread to write it
	if(LogFname) {
		sigset_t	signalset;

		if(pthread_create(0, NULL, &logger, NULL) != 0) {
			fprintf(stderr, "%s: Unable to create logger thread.\n", __progname);
			exit(EXIT_FAILURE);
		}

	// We want the logger thread to catch signals. Not us!
	sigemptyset(&signalset);
	sigfillset(&signalset);
	pthread_sigmask(SIG_BLOCK, &signalset, NULL);
	}

	// Run in backgound
	if(Verbose) {
		daemon_flag = PROCMGR_DAEMON_NODEVNULL;
	}
	if (procmgr_daemon(EXIT_SUCCESS, daemon_flag) == -1) {
		fprintf(stderr, "%s: Couldn't become daemon.\n", argv[0]);
	}

	// Slogger is single-threaded
	ctp = resmgr_context_alloc(dpp);

	for(;;) {
		if((ctp = resmgr_block(ctp)) == NULL)
			exit(EXIT_FAILURE);

		resmgr_handler(ctp);
	}

	exit(EXIT_SUCCESS);
}
コード例 #5
0
int
resmgr_create_device(event_bus_line_t *line)
{
        devi_attr_t				*attr;
        resmgr_attr_t				res_attr;
	static resmgr_connect_funcs_t		connect_funcs;
	static resmgr_io_funcs_t		io_funcs;
        static int				once = 0;
        int					i;
	char					name[48];
        char					path[_POSIX_PATH_MAX];
	int					id;
        dev_t					d;

	if ((attr = malloc(sizeof(devi_attr_t))) == NULL) {
                errno_print("malloc");
                return (-1);
        }

	if (!once) {
                iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs,
                                 _RESMGR_IO_NFUNCS, &io_funcs);
                connect_funcs.open = devi_open;
                io_funcs.devctl = devi_devctl;
                io_funcs.read = devi_read;
                io_funcs.close_ocb = devi_close;
                io_funcs.unblock = devi_unblock;
                io_funcs.notify = devi_notify;
                once = 1;
        }

        iofunc_attr_init(&attr->attr, 0666 | S_IFCHR, NULL, NULL);
	attr->flags = line->type;
        attr->ocb_list = NULL;
        line->attr = attr;

	switch (attr->flags) {

        case DEVI_CLASS_KBD:
                strcpy(name, "keyboard");
                break;
                
        case DEVI_CLASS_REL:
                strcpy(name, "mouse");
                break;
                
        case DEVI_CLASS_ABS:
                strcpy(name, "touch");
                break;
        }

        attr->line = line;

        memset(&res_attr, 0, sizeof(res_attr));
        res_attr.msg_max_size = 2048;
        res_attr.nparts_max = 3;

        for (i = 0; i < 10; i++) {

                sprintf(path, DEVICE_NAME, name, i);
                if (access(path, F_OK) != 0)
                        break;
        }
        if (i == 10) {

                char * pMsgTxt = "Error: unable to create device %s\n";
                fprintf(stderr, pMsgTxt, path);
                slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt, path);
                free(attr);
                return (-1);
        }

        id = resmgr_attach(devi_get_dispatch_handle(), &res_attr, path, 
                           _FTYPE_ANY, 0, &connect_funcs, 
                           &io_funcs, (void *) &attr->attr);

        if (id < 0) {
                char * pMsgTxt = "Error: could not attach resource manager\n";
                fprintf(stderr, pMsgTxt);
                slogf(_SLOG_SETCODE(_SLOGC_INPUT, 0), _SLOG_ERROR, pMsgTxt);
                free(attr);
                return (-1);
        }

        attr->attr.rdev = rsrcdbmgr_devno_attach(name, -1, 0);
        resmgr_devino(id, &d, &attr->attr.inode);

        return (0);
}
コード例 #6
0
main( int argc, char **argv)
{
  resmgr_attr_t resmgr_attr;
  dispatch_t *dpp;
  dispatch_context_t *ctp;
  int id;
  int pci_id;
  char *device;

  /* check to see if device number is specified when invoked */
  if( argc == 1 ){
    fprintf(stderr, "%s: Invoke with device number (i.e. 1 = /dev/ics660-1)\n",argv[0]);
    return EXIT_FAILURE;
  }
  
  device = calloc((size_t) 64, sizeof(char));
  strcat(device,"/dev/ics660-");
  strcat(device,(const char *) argv[1]);
  printf("_ICS660_DRV: INITIALIZING DEVICE %s\n",device);
  
  sscanf(argv[1],"%d",&pci_id);
  printf("_ICS660_DRV: DEVICE ID %d\n",pci_id);

  ics660 = (struct ics660b *)ics660_drv_init((int) pci_id);

  /* initialize dispatch interface */
  if((dpp = dispatch_create()) == NULL){
    fprintf(stderr, "%s: Unable to allocate dispatch handle.\n", argv[0]);
    return EXIT_FAILURE;
  }
  /* initialize resource manager attributes */
  memset(&resmgr_attr, 0, sizeof resmgr_attr);
  resmgr_attr.nparts_max = 1;
  resmgr_attr.msg_max_size = 2048;

  /* initialize functions for handling messages */
  iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs, 
		   _RESMGR_IO_NFUNCS, &io_funcs);
  io_funcs.read = io_read;
  io_funcs.write = io_write;
  io_funcs.devctl = io_devctl;

 /* initialize attribute structure used by the device */
  iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
  //attr.nbytes = strlen(buffer)+1;

  /* attach our device name */
  id = resmgr_attach(dpp,            // dispatch handle
		     &resmgr_attr,   // resource manager attrs
		     device,  // device name
		     _FTYPE_ANY,     // open type
		     0,              // flags
		     &connect_funcs, // connect routines
		     &io_funcs,      // I/O routines
		     &attr);         // handle
  if(id == -1){
    fprintf(stderr, "%s: Unable to attach name.\n",argv[0]);
    return EXIT_FAILURE;
  }
  /* allocate a context structure */
  ctp = dispatch_context_alloc(dpp);

  /* start the resource manager messager loop */
  while(1){
    if((ctp = dispatch_block(ctp)) == NULL) {
      fprintf(stderr,"block_error\n");
      return EXIT_FAILURE;
    }
    dispatch_handler(ctp);
  }
}
コード例 #7
0
int main(int argc, char **argv)
{
    /* declare variables we'll be using */
    thread_pool_attr_t   pool_attr;
    resmgr_attr_t        resmgr_attr;
    dispatch_t           *dpp;
    thread_pool_t        *tpp;
    dispatch_context_t   *ctp;
    int                  id;

    /* initialize dispatch interface */
    if((dpp = dispatch_create()) == NULL) {
        fprintf(stderr,
                "%s: Unable to allocate dispatch handle.\n",
                argv[0]);
        return EXIT_FAILURE;
    }

    /* initialize resource manager attributes */
    memset(&resmgr_attr, 0, sizeof resmgr_attr);
    resmgr_attr.nparts_max = 1;
    resmgr_attr.msg_max_size = 2048;

    /* initialize functions for handling messages */
    iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect_funcs, 
                     _RESMGR_IO_NFUNCS, &io_funcs);
    io_funcs.read = io_read;
    io_funcs.write = io_write;
    io_funcs.devctl = io_devctl;

    /* initialize attribute structure used by the device */
    iofunc_attr_init(&attr, S_IFNAM | 0666, 0, 0);
    attr.nbytes = strlen (buffer)+1;

    /* attach our device name */
    id = resmgr_attach(
            dpp,            /* dispatch handle        */
            &resmgr_attr,   /* resource manager attrs */
            "/dev/sample",  /* device name            */
            _FTYPE_ANY,     /* open type              */
            0,              /* flags                  */
            &connect_funcs, /* connect routines       */
            &io_funcs,      /* I/O routines           */
            &attr);         /* handle                 */
    if(id == -1) {
        fprintf(stderr, "%s: Unable to attach name.\n", argv[0]);
        return EXIT_FAILURE;
    }

    /* initialize thread pool attributes */
    memset(&pool_attr, 0, sizeof pool_attr);
    pool_attr.handle = dpp;
    pool_attr.context_alloc = dispatch_context_alloc;
    pool_attr.block_func = dispatch_block;
    pool_attr.unblock_func = dispatch_unblock;
    pool_attr.handler_func = dispatch_handler;
    pool_attr.context_free = dispatch_context_free;
    pool_attr.lo_water = 4;
    pool_attr.hi_water = 8;
    pool_attr.increment = 2;
    pool_attr.maximum = 50;

    /* allocate a thread pool handle */
    if((tpp = thread_pool_create(&pool_attr, 
                                 POOL_FLAG_EXIT_SELF)) == NULL) {
        fprintf(stderr, "%s: Unable to initialize thread pool.\n",
                argv[0]);
        return EXIT_FAILURE;
    }

    /* start the threads, will not return */
    thread_pool_start(tpp);
    
    return EXIT_SUCCESS;
}
コード例 #8
0
ファイル: dumper.c プロジェクト: vocho/openqnx
int main(int argc, char *argv[])
{
	int 				c;
	char				*size_suffix;
	pid_t 				process = 0;
	dispatch_t			*dpp;
	resmgr_attr_t		resmgr_attr;
	resmgr_context_t	*ctp;

	umask(0222);

	/* We want some pshysical memory reserved for dumper process. */
	init_memory();

	/* We also want some physical memory for our stack.  */
	init_stack();
	
	while ( (c = getopt( argc, argv, "Dd:p:ns:vmPwtz:" )) != -1 ) {
		switch(c) {
		case 'd':
			dump_dir = optarg;
			break;
		case 'n':
			sequential_dumps = 1;
			break;
		case 'p':
			process = atoi(optarg);
			break;
		case 's':
			max_core_size = strtol(optarg, &size_suffix, 10);
			switch(*size_suffix){
				case 'g':
				case 'G':
					max_core_size *= 1024;
				case 'm':
				case 'M':
					max_core_size *= 1024;
				case 'k':
				case 'K':
					max_core_size *= 1024;
					break;
				case 0:
					break;
				default:
					fprintf(stderr, "Warning: suffix '%c' unrecognized\n", *size_suffix);
			}
			break;
		case 'v':
			verbose = 1;
			break;
		case 'm':
			nodumpmem = 1;
			break;
		case 'P':
			nodumpphys = 0;
			break;
		case 't':
			cur_tid_only = 1;
			break;
		case 'w':
			world_readable = 1;
			break;
	    case 'z':
			gzlevel = strtol(optarg, &size_suffix, 10);
			if (gzlevel < 1 || gzlevel > 9) {
				fprintf(stderr, "Compress level must between 1 and 9.\n");
				exit(EXIT_FAILURE);
			}
			break;
		}
	}

	if ( process ) {
		requested = 1;
		return dump( ND_LOCAL_NODE, process, max_core_size );
	}

	if((dpp = dispatch_create()) == NULL) {
		fprintf(stderr, "%s: Unable to allocate dispatch handle.\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	memset(&resmgr_attr, 0, sizeof resmgr_attr);
	resmgr_attr.nparts_max = 1;
	resmgr_attr.msg_max_size = 2048;

	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &connect, _RESMGR_IO_NFUNCS, &io);
	io.write = dumper_write;
	io.devctl = dumper_devctl; 
	io.close_ocb = dumper_close_ocb; 

	iofunc_attr_init(&attr, S_IFNAM | 0600, 0, 0);

	if ( -1 == resmgr_attach(dpp, &resmgr_attr, "/proc/dumper", _FTYPE_DUMPER, 0, &connect, &io, &attr)) {
		fprintf( stderr, "%s: Couldn't attach as /proc/dumper: %s\n", argv[0], strerror(errno) );
		exit(EXIT_FAILURE);
	}

	if((ctp = resmgr_context_alloc(dpp)) == NULL) {
		fprintf(stderr, "%s: Unable to allocate dispatch handle.\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	if ( -1 == procmgr_daemon(EXIT_SUCCESS, verbose ? 
		PROCMGR_DAEMON_NODEVNULL | PROCMGR_DAEMON_KEEPUMASK :
		PROCMGR_DAEMON_KEEPUMASK) ) {
		fprintf(stderr, "%s: Couldn't become daemon.\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	while(1) {
		if((ctp = resmgr_block(ctp)) == NULL) {
			fprintf(stderr, "block error\n");
			exit(EXIT_FAILURE);
		}
		resmgr_handler(ctp);
	}
	return EXIT_SUCCESS;
}
コード例 #9
0
int main(int argc, char *argv[]) {
	dispatch_t *dpp;
	resmgr_attr_t resmgr_attr;
	dispatch_context_t *ctp;
	resmgr_connect_funcs_t connect_funcs;
	resmgr_io_funcs_t io_funcs;
	iofunc_attr_t io_attr;

	printf("Start resource manager\n");

	/* Init mutex for counter variable */
	if (pthread_mutex_init(&lock, NULL) != 0){
	        printf("\n mutex init failed\n");
	        return 1;
	}

	/* Create dispatch. */
	if (!(dpp = dispatch_create()))
		error("dispatch_create()");

	/* Initialize resource manager attributes. */
	memset(&resmgr_attr, 0, sizeof(resmgr_attr));
	resmgr_attr.nparts_max = 1;
	resmgr_attr.msg_max_size = 2048;

	/* Set standard connect and io functions. */
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS,
				&connect_funcs,
				_RESMGR_IO_NFUNCS,
				&io_funcs);
	iofunc_attr_init(&io_attr, S_IFNAM | 0666, 0, 0);

	/* Override functions */
	io_funcs.read = io_read;
	io_funcs.write = io_write;

	/* Establish resource manager */
	if (resmgr_attach(dpp,
				&resmgr_attr,
				"/dev/myresource",
				_FTYPE_ANY,
				0,
				&connect_funcs,
				&io_funcs,
				&io_attr)
					< 0)
		error("resmgr_attach()");

	/* Create counter thread */
	if (pthread_create(&tid, NULL, &counter, NULL) != 0)
		printf("can't create counter thread\n");

	/* Wait forever, handling messages. */
	ctp = dispatch_context_alloc(dpp);
	while(1){
		if (!(ctp = dispatch_block(ctp)))
			error("dispatch_block()");
		dispatch_handler(ctp);
	}
	pthread_mutex_destroy(&lock);

	exit(EXIT_SUCCESS);
}
コード例 #10
0
ファイル: bttvx_dev.c プロジェクト: robotology-legacy/yarp1
//int init_bttvx(int video_mode, int device_number, int w, int h) //Video format, device id, width and height
int 
main (int argc, char * argv[])
{
	int i; 
	/* declare variables we'll be using */
	resmgr_attr_t		resmgr_attr;
	dispatch_t			*dpp;
	dispatch_context_t  *ctp;
	int                 id;
	int video_format = 0;
	int device_id = 0;
	char device_name[100];
	char shell_command[100];
	char buffer[20];
	char buffer2[20];
	int bus, dev_func;


	//Check the arguments
	
	if ( argc == 1 || argc > 3)
	{
		printf("Use: ./bttvx video_format [device_id]\n");
		printf("0 ----> PAL\n");
		printf("1 ----> NTSC\n"); 
		printf("2 ----> S-Video\n");
		exit(0);
	}
	

	//Get video format
	video_format = atoi(argv[1]);

	//Check driver index
	if (argv[2] != NULL)
	{
		device_id = atoi(argv[2]);
		if (device_id < 0 || device_id > BTTV_MAX)
		{
			printf("bttvx: Sorry!, the device id overcomes the maximum number of devices allowed\n");
			exit(0);
		}
	}
	

	//Filling passed width and height
	
	width = W;
	height= H;
	
	image_buffer = (unsigned char *) malloc (width*height*deep);
		
	strcpy(device_name,"/dev/bttvx");
	strcat(device_name,itoa(device_id,buffer,10)); //Complete the name

	init_bttvx(video_format,device_id, width,height, 0, 0);
	
	/* initialize dispatch interface */
	
	if((dpp = dispatch_create()) == NULL) 
	{
		fprintf(stderr, 
			    "%s: Unable to allocate dispatch handle.\n",
				argv[0]);
		return EXIT_FAILURE;
	}
	

	/* initialize resource manager attributes */
	memset(&resmgr_attr, 0, sizeof resmgr_attr);
	
	resmgr_attr.nparts_max = 1;
	resmgr_attr.msg_max_size=VBIBUF_SIZE;

	/* initialize functions for handling messages */
	
	iofunc_func_init(_RESMGR_CONNECT_NFUNCS, 
					 &connect_funcs,
					 _RESMGR_IO_NFUNCS, 
					 &io_funcs);

	io_funcs.read = io_read;
	//io_funcs.devctl = io_devctl;
	connect_funcs.open = io_open;
	
	/* initialize attribute structure used by the device */
	iofunc_attr_init(&attr, 
					 S_IFNAM | 0666, 
					 0, 0);
	//attr.nbytes = VBIBUF_SIZE + 1;
	attr.nbytes = VBIBUF_SIZE;

    /* attach our device name */
    id = resmgr_attach(dpp,            /* dispatch handle        */
                       &resmgr_attr,   /* resource manager attrs */
                       device_name,  /* device name            */
                       _FTYPE_ANY,     /* open type              */
                       0,              /* flags                  */
                       &connect_funcs, /* connect routines       */
                       &io_funcs,      /* I/O routines           */
                       &attr);         /* handle                 */
    if(id == -1) {
        fprintf(stderr, "%s: Unable to attach name.\n", argv[0]);
        return EXIT_FAILURE;
    }

	/* allocate a context structure */
	ctp = dispatch_context_alloc(dpp);

	/* start the resource manager message loop */
	
	while(1) 
	{
		if((ctp = dispatch_block(ctp)) == NULL) 
		{
			fprintf(stderr, "block error\n");
			return EXIT_FAILURE;
		}
		dispatch_handler(ctp);
	}
}