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); }
static int _spi_register_interface(void *data) { spi_dev_t *dev = data; SPIDEV *drvhdl; resmgr_attr_t rattr; char devname[PATH_MAX + 1]; struct passwd* pw; uid_t uid = 0; gid_t gid = 0; if ((drvhdl = dev->funcs->init(dev, dev->opts)) == NULL) { free(dev->opts); dev->opts = NULL; return (!EOK); } dev->drvhdl = drvhdl; /* set up i/o handler functions */ memset(&rattr, 0, sizeof(rattr)); rattr.nparts_max = SPI_RESMGR_NPARTS_MIN; rattr.msg_max_size = SPI_RESMGR_MSGSIZE_MIN; iofunc_attr_init(&drvhdl->attr, S_IFCHR | devperm, NULL, NULL); drvhdl->attr.mount = &_spi_mount; /* register device name */ snprintf(devname, PATH_MAX, "/dev/spi%d", dev->devnum); if (-1 == (dev->id = resmgr_attach(dev->dpp, &rattr, devname, _FTYPE_ANY, 0, &_spi_connect_funcs, &_spi_io_funcs, (void *)drvhdl))) { perror("resmgr_attach() failed"); goto failed1; } resmgr_devino(dev->id, &drvhdl->attr.mount->dev, &drvhdl->attr.inode); if (UserParm != NULL) { if(*UserParm >= '0' && *UserParm <= '9') { uid = strtol(UserParm, &UserParm, 0); if(*UserParm++ == ':') { gid = strtol(UserParm, NULL, 0); } } else if (( pw = getpwnam( UserParm ) ) != NULL ) { uid = pw->pw_uid; gid = pw->pw_gid; } if(setgid(gid) == -1 || setuid(uid) == -1 ) { perror("setgid() / setuid() failed"); } } if ((dev->ctp = dispatch_context_alloc(dev->dpp)) != NULL) return (EOK); perror("dispatch_context_alloc() failed"); resmgr_detach(dev->dpp, dev->id, _RESMGR_DETACH_ALL); failed1: dev->funcs->fini(drvhdl); return (!EOK); }
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); } }
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); } }
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); }
//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); } }