コード例 #1
0
ファイル: h2devLib.c プロジェクト: openrobots/pocolibs
/**
 ** Retourne le semId des semaphores
 **/
int
h2devGetSemId(void)
{
    if (h2devAttach() == ERROR) {
	return ERROR;
    }
    if (h2Devs[0].type != H2_DEV_TYPE_SEM) {
	errnoSet(S_h2devLib_BAD_DEVICE_TYPE);
	return ERROR;
    }
    return h2Devs[0].data.sem.semId;
}
コード例 #2
0
ファイル: h2devLib.c プロジェクト: openrobots/pocolibs
STATUS
h2devClean(const char *name)
{
   int i, match = 0;
   unsigned char *pool;

   if (h2devAttach() == ERROR) {
      return ERROR;
   }
   /* Look for devices */
   for (i = 0; i < H2_DEV_MAX; i++) {
      if (H2DEV_TYPE(i) != H2_DEV_TYPE_NONE && 
	  fnmatch(name, H2DEV_NAME(i), 0) == 0) {
	 logMsg("Freeing %s\n", H2DEV_NAME(i));
	 match++;
	 switch (H2DEV_TYPE(i)) {
	      case H2_DEV_TYPE_MBOX:
		 mboxDelete(i);
		 break;
	      case H2_DEV_TYPE_POSTER:
		pool = smObjGlobalToLocal(H2DEV_POSTER_POOL(i));
		if (pool != NULL) 
		    smMemFree(pool);
		h2semDelete(H2DEV_POSTER_SEM_ID(i));
		h2devFree(i);
		break;
	      case H2_DEV_TYPE_TASK:
		h2semDelete(H2DEV_TASK_SEM_ID(i));
		h2devFree(i);
		break;
	      case H2_DEV_TYPE_SEM:
	      case H2_DEV_TYPE_NONE:
		break;
	      default:
		/* error */
		logMsg("comLib: unknown device type %d\n", H2DEV_TYPE(i));
		return ERROR;
		break;
	    } /* switch */
	} 
    } /* for */

    if (match == 0) {
	logMsg("No matching device\n");
	return ERROR;
    }
    return OK;
}
コード例 #3
0
ファイル: h2devLib.c プロジェクト: openrobots/pocolibs
/**
 ** Liberation d'un device h2
 **/
STATUS
h2devFree(int dev)
{
    uid_t uid = getuid();

    if (h2devAttach() == ERROR) {
	return ERROR;
    }
    if (uid != H2DEV_UID(dev) && uid != H2DEV_UID(0)) {
	errnoSet(S_h2devLib_NOT_OWNER);
	return ERROR;
    }
    h2semTake(0, WAIT_FOREVER);
    h2Devs[dev].type = H2_DEV_TYPE_NONE;
    h2semGive(0);
    return OK;
}
コード例 #4
0
STATUS
h2initGlob(int ticksPerSec)
{

#ifdef __XENO__
    /* Lock process in RAM */
    mlockall(MCL_CURRENT | MCL_FUTURE);
#endif
    /* init error msgs for sub-libraries without specific init functions */
    h2evnRecordH2ErrMsgs();
    h2semRecordH2ErrMsgs();
    smObjRecordH2ErrMsgs();

    /* OS level initialization */
    if (osInit(ticksPerSec) == ERROR) {
	return ERROR;
    }
    setvbuf(stdout, (char *)NULL, _IOLBF, 0);
    setvbuf(stderr, (char *)NULL, _IOLBF, 0);

    /* attach to h2 devices */
    if (h2devAttach() == ERROR) {
	printf("Error: could not find h2 devices\n"
		"Did you execute `h2 init' ?\n");
	return ERROR;
    }
    /* attach to shared memory */
    if (smMemAttach() == ERROR) {
	printf("Error: could not attach shared memory\n");
	return ERROR;
    }

    /* Start h2 timers if a clock is available */
    if (ticksPerSec != 0) {
	if (h2timerInit() == ERROR) {
	    return ERROR;
	}
    }
    h2timeInit();
    printf("%s execution environment version %s\n"
	"Copyright (c) 1999-2011 CNRS-LAAS\n",
	PACKAGE_NAME, PACKAGE_VERSION);

    return OK;
}
コード例 #5
0
ファイル: h2devLib.c プロジェクト: openrobots/pocolibs
/**
 ** Allocation d'un device h2
 **/
int
h2devAlloc(const char *name, H2_DEV_TYPE type)
{
    int i;

    if (h2devAttach() == ERROR) {
	return ERROR;
    }
    h2semTake(0, WAIT_FOREVER);

    /* Verifie que le nom n'existe pas */
    if (type != H2_DEV_TYPE_SEM && h2devFindAux(name, type) != ERROR) {
	h2semGive(0);
	errnoSet(S_h2devLib_DUPLICATE_DEVICE_NAME);
	return ERROR;
    }
    /* Recherche un device libre */
    for (i = 0; i < H2_DEV_MAX; i++) {
	if (h2Devs[i].type == H2_DEV_TYPE_NONE) {
	    /* Trouve' */
	    if (snprintf(h2Devs[i].name, H2_DEV_MAX_NAME, "%s", name) 
		>= H2_DEV_MAX_NAME) {
		h2semGive(0);
		LOGDBG(("comLib:h2devAlloc: device name too long\n"));
		errnoSet(S_h2devLib_BAD_PARAMETERS);
		return ERROR;
	    }
	    strncpy(h2Devs[i].name, name, H2_DEV_MAX_NAME);
	    h2Devs[i].type = type;
	    h2Devs[i].uid = getuid();
	    h2semGive(0);
	    LOGDBG(("comLib:h2devAlloc: created device %d\n", i));
	    return i;
	}
    } /* for */

    /* Pas de device libre */
    h2semGive(0);
    errnoSet(S_h2devLib_FULL);
    return ERROR;
}
コード例 #6
0
ファイル: h2devLib.c プロジェクト: openrobots/pocolibs
int
h2devFind(const char *name, H2_DEV_TYPE type)
{
    int i;

    if (name == NULL) {
	errnoSet(S_h2devLib_BAD_PARAMETERS);
	return ERROR;
    }
    if (h2devAttach() == ERROR) {
	return ERROR;
    }
    h2semTake(0, H2DEV_TIMEOUT);
    i = h2devFindAux(name, type);
    h2semGive(0);

    if (i >= 0) {
	return i;
    } else {
	errnoSet(S_h2devLib_NOT_FOUND);
	return ERROR;
    }
}