src/haptic/SDL_haptic.c
branchgsoc2008_force_feedback
changeset 2476 242d8a668ebb
parent 2475 4b874e3a3a2c
child 2477 97f75ea43a93
equal deleted inserted replaced
2475:4b874e3a3a2c 2476:242d8a668ebb
   111       SDL_memset(haptic, 0, (sizeof *haptic));
   111       SDL_memset(haptic, 0, (sizeof *haptic));
   112       haptic->index = device_index;
   112       haptic->index = device_index;
   113       if (SDL_SYS_HapticOpen(haptic) < 0) {
   113       if (SDL_SYS_HapticOpen(haptic) < 0) {
   114          SDL_free(haptic);
   114          SDL_free(haptic);
   115          haptic = NULL;
   115          haptic = NULL;
   116       } else {
       
   117       }
   116       }
   118    }
   117    }
   119    if (haptic) {
   118    if (haptic) {
   120       /* Add haptic to list */
   119       /* Add haptic to list */
   121       ++haptic->ref_count;
   120       ++haptic->ref_count;
   126    return haptic;
   125    return haptic;
   127 }
   126 }
   128 
   127 
   129 
   128 
   130 /*
   129 /*
       
   130  * Checks to see if the haptic device is valid
       
   131  */
       
   132 static int
       
   133 ValidHaptic(SDL_Haptic ** haptic)
       
   134 {
       
   135    int valid;
       
   136 
       
   137    if (*haptic == NULL) {
       
   138       SDL_SetError("Haptic device hasn't been opened yet");
       
   139       valid = 0;
       
   140    } else {
       
   141       valid = 1;
       
   142    }
       
   143    return valid;
       
   144 }
       
   145 
       
   146 
       
   147 /*
   131  * Closes a SDL_Haptic device.
   148  * Closes a SDL_Haptic device.
   132  */
   149  */
   133 void
   150 void
   134 SDL_HapticClose(SDL_Haptic * haptic)
   151 SDL_HapticClose(SDL_Haptic * haptic)
   135 {
   152 {
   136    (void)haptic;
   153    int i;
   137    /* TODO */
   154 
       
   155    /* Must be valid */
       
   156    if (!ValidHaptic(&haptic)) {
       
   157       return;
       
   158    }
       
   159 
       
   160    /* Check if it's still in use */
       
   161    if (--haptic->ref_count < 0) {
       
   162       return;
       
   163    }
       
   164 
       
   165    /* Close it */
       
   166    SDL_SYS_HapticClose(haptic);
       
   167 
       
   168    /* Remove from the list */
       
   169    for (i = 0; SDL_haptics[i]; ++i) {
       
   170       if (haptic == SDL_haptics[i]) {
       
   171          SDL_memcpy(&SDL_haptics[i], &SDL_haptics[i + 1],
       
   172                (SDL_numhaptics - i) * sizeof(haptic));
       
   173          break;
       
   174       }
       
   175    }
       
   176 
       
   177    /* Free */
       
   178    SDL_free(haptic);
   138 }
   179 }
   139 
   180 
   140 /*
   181 /*
   141  * Cleans up after the subsystem.
   182  * Cleans up after the subsystem.
   142  */
   183  */