Exemplo n.º 1
0
void C1WireByOWFS::GetDevices(const std::string inDir, /*out*/std::vector<_t1WireDevice>& devices) const
{
    DIR *d=opendir(inDir.c_str());
    if (d != NULL)
    {
        struct dirent *de=NULL;
        // Loop while not NULL
        while((de=readdir(d)))
        {
            // Check dir
            if (!IsValidDir(de))
                continue;

            // Get the device from it's dirname
            _t1WireDevice device;
            GetDevice(inDir, de->d_name, device);

            // Add device to list
            devices.push_back(device);

            // If device is a hub, scan for all hub connected devices (recursively)
            if (device.family==microlan_coupler)
            {
                // Scan in "main" and "aux" dir
                GetDevices(inDir + "/" + de->d_name + HUB_MAIN_SUB_PATH, devices);
                GetDevices(inDir + "/" + de->d_name + HUB_AUX_SUB_PATH, devices);
            }
        }
    }

    closedir(d);
}
Exemplo n.º 2
0
DirectInput::DirectInput()
{
	///////////////////////////////////////////////////////////////////////////////
    // Constructor
    // Initialises Direct Input, sets up and aquires input devices. 
    ///////////////////////////////////////////////////////////////////////////////
	
	DIObject = NULL;				//set Directinput object pointer to null.
	DIKeyboardDevice = NULL;		//keyboard device set to null.
	
	bool InputInitialised =Initialise();
	assert(InputInitialised);

	bool DevicesInitialised = GetDevices();
	assert(DevicesInitialised);

	//Initialise the Analogue and digital control maps
	for (int i=0; i<DIGITALCONTROLMAPS; i++)
	{
		DigitalControlMap[i] = false;
	}
	for (int i=0; i<ANALOGUECONTROLMAPS; i++)
	{
		AnalogueControlMap[i];
	}

}
Exemplo n.º 3
0
/*****************************************************************************
 * config variable callback
 *****************************************************************************/
static int FindDevicesCallback( vlc_object_t *p_this, char const *psz_name,
                               vlc_value_t newval, vlc_value_t oldval, void *p_unused )
{
    module_config_t *p_item;
    int i;
    (void)newval;
    (void)oldval;
    (void)p_unused;

    p_item = config_FindConfig( p_this, psz_name );
    if( !p_item ) return VLC_SUCCESS;

    /* Clear-up the current list */
    if( p_item->i_list )
    {
        /* Keep the first entrie */
        for( i = 1; i < p_item->i_list; i++ )
        {
            free( (char *)p_item->ppsz_list[i] );
            free( (char *)p_item->ppsz_list_text[i] );
        }
        /* TODO: Remove when no more needed */
        p_item->ppsz_list[i] = NULL;
        p_item->ppsz_list_text[i] = NULL;
    }
    p_item->i_list = 1;

    GetDevices( p_item );

    /* Signal change to the interface */
    p_item->b_dirty = true;

    return VLC_SUCCESS;
}
Exemplo n.º 4
0
int main(int argc, char *argv[] )
{
    unsigned long productId, nameSize, numDIOBytes, numCounters;
    const int MAX_NAME_SIZE = 20;
    char name[ MAX_NAME_SIZE + 2 ];
    int stopval;

    unsigned long deviceIndex = 0;
    AIOUSB_BOOL deviceFound = AIOUSB_FALSE;
    printf(
           "  AIOUSB library version %s, %s\n"
           "  This program demonstrates controlling a USB-IIRO or USB-IDIO device on\n"
           "  the USB bus. For simplicity, it uses the first such device found\n"
           "  on the bus.\n"
           , AIOUSB_GetVersion(), AIOUSB_GetVersionDate()
           );

    /*
     * Must call AIOUSB_Init() before any meaningful AIOUSB functions;
     * AIOUSB_GetVersion() above is an exception
     */
    unsigned long result = AIOUSB_Init();

    /*
     * call GetDevices() to obtain "list" of devices found on the bus
     */
    unsigned long deviceMask = GetDevices();
    if( deviceMask != 0 ) {
        /*
         * at least one ACCES device detected, but we want one of a specific type
         */
        AIOUSB_ListDevices(); /* print list of all devices found on the bus */

        while( deviceMask != 0 ) {
            if( ( deviceMask & 1 ) != 0 ) {
                // found a device, but is it the correct type?
                nameSize = MAX_NAME_SIZE;
                result = QueryDeviceInfo( deviceIndex, &productId, &nameSize, name, &numDIOBytes, &numCounters );
                if( result == AIOUSB_SUCCESS ) {
                    if( (productId >= USB_IIRO_16 && productId <= USB_IIRO_4 ) || 
                        (productId >= USB_IDIO_16 && productId <= USB_IDIO_4 )) {
                        // found a USB-AI16-16A family device
                        deviceFound = AIOUSB_TRUE;
                        break;				// from while()
                    }
                } else
                    printf( "Error '%s' querying device at index %lu\n"
                            , AIOUSB_GetResultCodeAsString( result ), deviceIndex );
            }
            deviceIndex++;
            deviceMask >>= 1;
        }
    }
Exemplo n.º 5
0
/**
 * Initializes list of devices.
 */
static void Probe (vlc_object_t *obj, const char *dev)
{
    vlc_value_t text;

    var_Create (obj, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE);
    text.psz_string = _("Audio Device");
    var_Change (obj, "audio-device", VLC_VAR_SETTEXT, &text, NULL);

    GetDevices (obj, NULL, dev);

    var_AddCallback (obj, "audio-device", aout_ChannelsRestart, NULL);
}
Exemplo n.º 6
0
/**
 * Initializes list of devices.
 */
static void Probe (vlc_object_t *obj)
{
    /* Due to design bug in audio output core, this hack is required: */
    if (var_Type (obj, "audio-device"))
        return;

    /* The variable does not exist - first call. */
    vlc_value_t text;

    var_Create (obj, "audio-device", VLC_VAR_STRING | VLC_VAR_HASCHOICE);
    text.psz_string = _("Audio Device");
    var_Change (obj, "audio-device", VLC_VAR_SETTEXT, &text, NULL);

    GetDevices (obj, NULL);

    var_AddCallback (obj, "audio-device", aout_ChannelsRestart, NULL);
    var_TriggerCallback (obj, "intf-change");
}
Exemplo n.º 7
0
int main( int argc, char **argv ) {
    const int DEVICES_REQUIRED = 1;
    const int MAX_DIO_BYTES = 4;
    const int MASK_BYTES = ( MAX_DIO_BYTES + BITS_PER_BYTE - 1 ) / BITS_PER_BYTE;
    const int MAX_NAME_SIZE = 20;
    int devicesFound = 0;
    int index = 0;
    typedef enum { 
      SUCCESS = 0,
      USB_ERROR = -1,
      NO_DEVICE_FOUND = -2
    } EXIT_CODE;
    EXIT_CODE exit_code = SUCCESS;

    struct DeviceInfo {
        unsigned char outputMask[ MASK_BYTES ];
        unsigned char readBuffer[ MAX_DIO_BYTES ];		// image of data read from board
        unsigned char writeBuffer[ MAX_DIO_BYTES ];		// image of data written to board
        char name[ MAX_NAME_SIZE + 2 ];
        unsigned long productID;
        unsigned long nameSize;
        unsigned long numDIOBytes;
        unsigned long numCounters;
        uint64_t serialNumber;
        int index;
    } deviceTable[ DEVICES_REQUIRED ];
    struct DeviceInfo *device;

    printf(
           "USB-DIO-32 sample program version 1.17, 26 November 2009\n"
           "  AIOUSB library version %s, %s\n"
           "  This program demonstrates communicating with %d USB-DIO-32 devices on\n"
           "  the same USB bus. For simplicity, it uses the first %d such devices\n"
           "  found on the bus.\n",
           AIOUSB_GetVersion(),
           AIOUSB_GetVersionDate(),
           DEVICES_REQUIRED,
           DEVICES_REQUIRED
           );

    unsigned long result = AIOUSB_Init(); /* Call AIOUSB_Init() before any meaningful AIOUSB functions; */
    if( result != AIOUSB_SUCCESS ) {
        printf("Can't initialize AIOUSB USB device\n");
        exit_code = USB_ERROR;
    }

    unsigned long deviceMask = GetDevices(); /**< @ref GetDevices */
    if( deviceMask == 0 ) {
        printf( "No ACCES devices found on USB bus\n" );
        exit_code = USB_ERROR;
        goto exit_sample;
    }

    AIOUSB_ListDevices();

    /*
     * search for required number of USB-DIO-32 devices
     */


    while( deviceMask != 0 && devicesFound < DEVICES_REQUIRED ) {
        if( ( deviceMask & 1 ) != 0 ) {
            // found a device, but is it the correct type?
            device = &deviceTable[ devicesFound ];
            device->nameSize = MAX_NAME_SIZE;
            result = QueryDeviceInfo( index, &device->productID,
                                      &device->nameSize,
                                      device->name,
                                      &device->numDIOBytes,
                                      &device->numCounters
                                      );
            if( result == AIOUSB_SUCCESS ) {
                if( device->productID == USB_DIO_32 ) { // found a USB-DIO-32
                    device->index = index;
                    devicesFound++;
                }
            } else
              printf( "Error '%s' querying device at index %d\n",
                      AIOUSB_GetResultCodeAsString( result ),
                      index
                      );
        }
        index++;
        deviceMask >>= 1;
    }

    if( devicesFound < DEVICES_REQUIRED ) {
        printf( "Error: You need at least %d devices connected to run this sample\n", DEVICES_REQUIRED );
        goto exit_sample;
    }
    unsigned port, pattern;
    AIOUSB_BOOL correct;

    for( index = 0; index < devicesFound; index++ ) {
        device = &deviceTable[ index ];
        result = GetDeviceSerialNumber( device->index, &device->serialNumber );
        if( result == AIOUSB_SUCCESS )
            printf( "Serial number of device at index %d: %llx\n", device->index, ( long long ) device->serialNumber );
        else
            printf( "Error '%s' getting serial number of device at index %d\n", AIOUSB_GetResultCodeAsString( result ), device->index );
    }

    /*
     * DIO configuration
     */
    device = &deviceTable[ 0 ]; /* select first device */
    AIOUSB_SetCommTimeout( device->index, 1000 ); /* set timeout for all USB operations */
    /*
     * set all ports to output mode (we could just write "device->outputMask[ 0 ] = 0x0f"
     * here since there are only 4 ports)
     */
    memset( device->outputMask, 0xff, MASK_BYTES );
    
    for( port = 0; port < device->numDIOBytes; port++ )
        device->writeBuffer[ port ] = 0x11 * ( port + 1 );
    

    /* for ( port =0 ; port < 0xff ; port ++ ) {  */
    device->outputMask[0] = (unsigned char )0xff;

    for( port = 0; port <= 0xff; port ++ ) { 
        device->writeBuffer[0] = port;
        result = DIO_ConfigureRaw( device->index, AIOUSB_FALSE, device->outputMask, device->writeBuffer );
        usleep(10000);
    }

    for( port = 0; port <= 0xff; port ++ ) { 
        device->writeBuffer[1] = port;
        result = DIO_ConfigureRaw( device->index, AIOUSB_FALSE, device->outputMask, device->writeBuffer );
        usleep(10000);
    }

    for( port = 0; port <= 0xff; port ++ ) { 
        device->writeBuffer[2] = port;
        result = DIO_ConfigureRaw( device->index, AIOUSB_FALSE, device->outputMask, device->writeBuffer );
        usleep(10000);
    }

    for( port = 0; port <= 0xff; port ++ ) { 
        device->writeBuffer[3] = port;
        result = DIO_ConfigureRaw( device->index, AIOUSB_FALSE, device->outputMask, device->writeBuffer );
        usleep(10000);
    }

    for ( port = 0; port < 4 ; port ++ )  {
        device->writeBuffer[port] = 0xff;
    }
    result = DIO_ConfigureRaw( device->index, AIOUSB_FALSE, device->outputMask, device->writeBuffer );

    for ( int i =0 ; i <= 0xf ; i ++ ) { 
            device->outputMask[0] = (unsigned char )i;
            result = DIO_ConfigureRaw( device->index, AIOUSB_FALSE, device->outputMask, device->writeBuffer );
            if ( result != AIOUSB_SUCCESS ) 
                break;
            usleep(100000);
    }

    if( result == AIOUSB_SUCCESS )
        printf( "Device at index %d successfully configured\n", device->index );
    else
        printf( "Error '%s' configuring device at index %d\n", AIOUSB_GetResultCodeAsString( result ), device->index );


exit_sample:
    AIOUSB_Exit();


    return ( int ) 0;
} 
Exemplo n.º 8
0
void C1WireByOWFS::GetDevices(/*out*/std::vector<_t1WireDevice>& devices) const
{
    return GetDevices(OWFS_Base_Dir, devices);
}
Exemplo n.º 9
0
/** Function Configs_FromPattern
 *  @brief   CMM_NICK oyCMMapi8_s scanner devices
 *
 *  @param[in] 	registration	a string to compare ??????
 *  @param[in]		options			read what to do from the options object
 *  @param[out]	s					Return a configuration for each device found
 *
 *  @version Oyranos: 0.1.10
 *  @since   2009/01/19 (Oyranos: 0.1.10)
 *  @date    2009/02/09
 */
int Configs_FromPattern(const char *registration, oyOptions_s * options, oyConfigs_s ** s)
{
   oyConfig_s *device = NULL;
   oyConfigs_s *devices = NULL;
   oyOption_s *context_opt = NULL,
              *handle_opt = NULL,
              *version_opt = NULL,
              *name_opt = NULL;
   int i, num_devices, g_error = 0, status, call_sane_exit = 0;
   const char *device_name = 0, *command_list = 0, *command_properties = 0;
   const SANE_Device **device_list = NULL;
   int rank;
   oyAlloc_f allocateFunc = malloc;

   printf(PRFX "Entering %s(). Options:\n%s", __func__, oyOptions_GetText(options, oyNAME_NICK));

   rank = oyFilterRegistrationMatch(_api8.registration, registration,
                                        oyOBJECT_CMM_API8_S);
   command_list = oyOptions_FindString(options, "command", "list");
   command_properties = oyOptions_FindString(options, "command", "properties");
   device_name = oyOptions_FindString(options, "device_name", 0);

   /* "error handling" section */
   if (rank == 0) {
      SANE_msg(oyMSG_WARN, (oyStruct_s *) options, _DBG_FORMAT_ "\n "
              "Registration match Failed. Options:\n%s", _DBG_ARGS_,
              oyOptions_GetText(options, oyNAME_NICK));
      return 1;
   }
   if (s == NULL) {
      SANE_msg(oyMSG_WARN, (oyStruct_s *) options, _DBG_FORMAT_ "\n "
              "oyConfigs_s is NULL! Options:\n%s", _DBG_ARGS_,
              oyOptions_GetText(options, oyNAME_NICK));
      return 1;
   }
   if (*s != NULL) {
      SANE_msg(oyMSG_WARN, (oyStruct_s *) options, _DBG_FORMAT_ "\n "
              "Devices struct already present! Options:\n%s", _DBG_ARGS_,
              oyOptions_GetText(options, oyNAME_NICK));
      return 1;
   }

   if (!device_name && command_properties) {
      SANE_msg(oyMSG_WARN, (oyStruct_s *) options, _DBG_FORMAT_ "\n "
              "Device_name is mandatory for properties command:\n%s",
              _DBG_ARGS_, oyOptions_GetText(options, oyNAME_NICK));
      return 1;
   }

   /* "help" call section */
   if (oyOptions_FindString(options, "command", "help") || !options || !oyOptions_Count(options)) {
    /** oyMSG_WARN should make shure our message is visible. */
      ConfigsFromPatternUsage((oyStruct_s *) options);
      return 0;
   }

   context_opt = oyOptions_Find(options, "device_context", oyNAME_PATTERN);
   handle_opt = oyOptions_Find(options, "device_handle", oyNAME_PATTERN);
   name_opt = oyOptions_Find(options, "oyNAME_NAME", oyNAME_PATTERN);

   /*Handle "driver_version" option [IN] */
   check_driver_version(options, &version_opt, &call_sane_exit);

   devices = oyConfigs_New(0);
   if (command_list) {
      /* "list" call section */

      if (device_name &&   /*If a user provides a device_name option,*/
          !context_opt &&  /*and does not need the device_context data,*/
          !name_opt        /*or the oyNAME_NAME description*/
         )
         num_devices = 1;  /*then we can get away without calling GetDevices()*/
      else if (GetDevices(&device_list, &num_devices) != 0) {
         num_devices = 0; /*So that for loop will not run*/
         ++g_error;
      }

      for (i = 0; i < num_devices; ++i) {
         int error = 0;
         const char *sane_name = NULL,
                    *sane_model = NULL;

         if (device_list) {
            sane_name = device_list[i]->name;
            sane_model = device_list[i]->model;
         } else {
            sane_name = device_name;
         }

         /*Handle "device_name" option [IN] */
         if (device_name &&                        /*device_name is provided*/
             sane_name &&                          /*and sane_name has been retrieved*/
             strcmp(device_name, sane_name) != 0)  /*and they don't match,*/
            continue;                              /*then try the next*/

         device = oyConfig_FromRegistration(CMM_BASE_REG, 0);

         /*Handle "driver_version" option [OUT] */
         if (version_opt) {
            oyOption_s * tmp = oyOption_Copy(version_opt, 0);
            oyOptions_MoveIn(*oyConfig_GetOptions(device,"backend_core"), &tmp, -1);
         }

         /*Handle "device_name" option [OUT] */
         oyOptions_SetFromString(oyConfig_GetOptions(device,"backend_core"),
                               CMM_BASE_REG OY_SLASH "device_name",
                               sane_name,
                               OY_CREATE_NEW);

         /*Handle "oyNAME_NAME" option */
         if (name_opt)
            oyOptions_SetFromString(oyConfig_GetOptions(device,"backend_core"),
                                  CMM_BASE_REG OY_SLASH "oyNAME_NAME",
                                  sane_model,
                                  OY_CREATE_NEW);

         /*Handle "device_context" option */
         /* SANE Backend protocol states that device_context is *always* returned
          * This is a slight variation: Only when GetDevices() is called will it be returned,
          * unless we call sane_exit*/
         if (device_list && !call_sane_exit) {
            oyBlob_s *context_blob = oyBlob_New(NULL);
            oyOption_s *context_opt = oyOption_FromRegistration(
                                     CMM_BASE_REG OY_SLASH "device_context", 0);

            oyBlob_SetFromData(context_blob, (oyPointer) device_list[i], sizeof(SANE_Device), "sane");
            oyOption_MoveInStruct(context_opt, (oyStruct_s **) & context_blob);
            oyOptions_MoveIn(*oyConfig_GetOptions(device,"data"), &context_opt, -1);
         }

         /*Handle "device_handle" option */
         if (handle_opt && !call_sane_exit) {
            oyPointer_s *handle_ptr = NULL;
            SANE_Handle h;
            status = sane_open(sane_name, &h);
            if (status == SANE_STATUS_GOOD) {
               handle_ptr = oyPointer_New(0);
               oyPointer_Set(handle_ptr,
                            "SANE",
                            "handle",
                            (oyPointer)h,
                            "sane_release_handle",
                            sane_release_handle);
               oyOptions_MoveInStruct(oyConfig_GetOptions(device,"data"),
                                      CMM_BASE_REG OY_SLASH "device_handle",
                                      (oyStruct_s **) &handle_ptr, OY_CREATE_NEW);
            } else
               printf(PRFX "Unable to open sane device \"%s\": %s\n", sane_name, sane_strstatus(status));
         }

         oyConfig_SetRankMap( device, _api8.rank_map );

         error = oyConfigs_MoveIn(devices, &device, -1);

         /*Cleanup*/
         if (error) {
            oyConfig_Release(&device);
            ++g_error;
         }
      }

      *s = devices;
   } else if (command_properties) {
      /* "properties" call section */
      const SANE_Device *device_context = NULL;
      SANE_Device *aux_context = NULL;
      SANE_Handle device_handle = NULL;

      /*Return a full list of scanner H/W &
       * SANE driver S/W color options
       * with the according rank map */

      device = oyConfig_FromRegistration(CMM_BASE_REG, 0);

      /*Handle "driver_version" option [OUT] */
      if (version_opt) {
         oyOption_s *tmp = oyOption_Copy(version_opt, 0);
         oyOptions_MoveIn(*oyConfig_GetOptions(device,"backend_core"), &tmp, -1);
      }

      /*1a. Get the "device_context"*/
      if (!context_opt) { /*we'll have to get it ourselves*/
         if (GetDevices(&device_list, &num_devices) == 0) {
            device_context = *device_list;
            while (device_context) {
               if(device_name && device_context->name &&
                  strcmp(device_name,device_context->name) == 0)
                  break;
               device_context++;
            }
            if (!device_context) {
               printf(PRFX "device_name does not match any installed device.\n");
               g_error++;
            }
         } else {
            g_error++;
         }
      } else {
         aux_context = (SANE_Device*)oyOption_GetData(context_opt, NULL, allocateFunc);
         device_context = aux_context;
      }

      /*1b. Use the "device_context"*/
      if (device_context)
         DeviceInfoFromContext_(device_context, oyConfig_GetOptions(device,"backend_core"));

      /*2a. Get the "device_handle"*/
      if (!handle_opt) {
         status = sane_open( device_name, &device_handle );
         if (status != SANE_STATUS_GOOD) {
            printf(PRFX "Unable to open sane device \"%s\": %s\n", device_name, sane_strstatus(status));
            g_error++;
         }
      } else {
        oyPointer_s * oy_struct = (oyPointer_s*) oyOption_GetStruct( handle_opt,
                                                           oyOBJECT_POINTER_S );
        device_handle = (SANE_Handle)oyPointer_GetPointer(oy_struct);
        oyPointer_Release( &oy_struct );
      }

      if (device_handle) {
         /*2b. Use the "device_handle"*/
         ColorInfoFromHandle(device_handle, oyConfig_GetOptions(device,"backend_core"));

         /*3. Set the rank map*/
         oyConfig_SetRankMap( device, _api8.rank_map );
      }
      oyConfigs_MoveIn(devices, &device, -1);

      /*Cleanup*/
      free(aux_context);

      *s = devices;
   } else {
      /*unsupported, wrong or no command */
      SANE_msg(oyMSG_WARN, (oyStruct_s *) options, _DBG_FORMAT_ "\n "
              "No supported commands in options:\n%s", _DBG_ARGS_,
              oyOptions_GetText(options, oyNAME_NICK) );
      ConfigsFromPatternUsage((oyStruct_s *) options);
      g_error = 1;
   }

   /*Global Cleanup*/
   if (call_sane_exit) {
      printf(PRFX "sane_exit()\n");
      sane_exit();
   }

   oyOption_Release(&context_opt);
   oyOption_Release(&handle_opt);
   oyOption_Release(&version_opt);
   oyOption_Release(&name_opt );

   printf(PRFX "Leaving %s\n", __func__);
   return g_error;
}
Exemplo n.º 10
0
/* nsIVariant getDeviceIDs (in T_WebCLDeviceType aType); */
NS_IMETHODIMP WebCLPlatform::GetDeviceIDs(T_WebCLDeviceType aType, JSContext *cx, nsIVariant **_retval)
{
  return GetDevices (aType, cx, _retval);
}
Exemplo n.º 11
0
/*
 * Initialize table of media libraries for stager.  This function
 * builds tables for the libraries, removable media drives and manual
 * drives from shared memory.
 */
static void
initLibraryTable(void)
{
    extern char *program_name;
    int jmap;
    dev_ent_t *dev;
    size_t size;
    LibraryInfo_t *lib;
    DriveInfo_t *drive;
    int ldx;
    int ddx;
    dev_ent_t *dev_head;
    int numDiskVols;
    int numHoneycombVols;
    DiskVolsDictionary_t *diskvols;
    boolean_t found_historian = B_FALSE;

    /*
     * If table already exists, free current table
     * and re-initialize.
     */
    if (libraryTable.data != NULL) {
        SamFree(libraryTable.data);
        SamFree(driveTable.data);

        libraryTable.data = NULL;
        driveTable.data = NULL;
    }

    if (vsnTable.data != NULL) {
        SamFree(vsnTable.data);

        vsnTable.data = NULL;
        if (vsnTable.catalog == B_TRUE) {
            CatalogTerm();
            vsnTable.catalog = B_FALSE;
        }
    }

    libraryTable.entries = 0;
    driveTable.entries = 0;
    vsnTable.entries = 0;

    dev_head = GetDevices(B_FALSE);

    for (dev = dev_head; dev != NULL;
            dev = (struct dev_ent *)SHM_REF_ADDR(dev->next)) {

        if (dev->equ_type == DT_HISTORIAN) {
            libraryTable.entries++;
            found_historian = B_TRUE;

        } else if (IS_THIRD_PARTY(dev)) {
            libraryTable.entries++;
            foundThirdParty = B_TRUE;

        } else if (IS_ROBOT(dev) || dev->equ_type == DT_PSEUDO_SC) {
            dev_ent_t *find;

            libraryTable.entries++;

            /*
             * Find all drives belonging to this library.
             */
            for (find = dev_head; find != NULL;
                    find = (struct dev_ent *)SHM_REF_ADDR(find->next)) {
                if (find->eq != dev->eq) {
                    if (find->fseq == dev->eq) {
                        driveTable.entries++;
                    }
                }
            }

        } else if (dev->fseq == 0) {
            /*
             * Manual drive.
             */
            libraryTable.entries++;
            driveTable.entries++;
            manualDrives++;
        }
    }

    Trace(TR_MISC, "Removable media libraries: %d drives: %d",
          found_historian ? libraryTable.entries - 1 : libraryTable.entries,
          driveTable.entries);

    /*
     * If defined, allocate a library table for disk archiving.
     * The disk archiving library will have a disk drive defined
     * for each vsn.
     */
    numDiskVols = 0;
    numHoneycombVols = 0;

    diskvols = DiskVolsNewHandle(program_name, DISKVOLS_VSN_DICT, 0400);
    if (diskvols != NULL) {
        (void) diskvols->Numof(diskvols, &numDiskVols, DV_numof_disk);
        (void) diskvols->Numof(diskvols, &numHoneycombVols,
                               DV_numof_honeycomb);
        (void) DiskVolsDeleteHandle(DISKVOLS_VSN_DICT);
    }

    if (numDiskVols > 0) {
        libraryTable.entries++;
        driveTable.entries += numDiskVols * STREAMS_PER_DISKVOL;
        Trace(TR_MISC, "Disk volumes: %d", numDiskVols);
    }

    if (numHoneycombVols > 0) {
        libraryTable.entries++;
        driveTable.entries += numHoneycombVols;
        Trace(TR_MISC, "Stk5800 volumes: %d", numHoneycombVols);
    }

    /*
     * Issue message if no removable media or disk archive volumes
     * were found.
     */
    if (libraryTable.entries == 0 ||
            (found_historian && libraryTable.entries == 1)) {
        SendCustMsg(HERE, 19007);
    }


    /*
     * Allocate library and drive tables and enter data.  If the
     * table count is zero, allocate one table entry anyway.
     */

    size = (libraryTable.entries ? libraryTable.entries : 1)
           * sizeof (LibraryInfo_t);
    SamMalloc(libraryTable.data, size);
    (void) memset(libraryTable.data, 0, size);

    size = (driveTable.entries ? driveTable.entries : 1)
           * sizeof (DriveInfo_t);
    SamMalloc(driveTable.data, size);
    (void) memset(driveTable.data, 0, size);

    lib = libraryTable.data;
    drive = driveTable.data;
    ldx = 0;
    ddx = 0;

    for (dev = dev_head; dev != NULL;
            dev = (struct dev_ent *)SHM_REF_ADDR(dev->next)) {

        lib->li_flags = 0;
        lib->li_device = dev;

        if (dev->type == DT_HISTORIAN) {
            (void) strncpy(lib->li_name, "Historian",
                           sizeof (lib->li_name));
            SET_LIB_HISTORIAN(lib);
            lib->li_eq = dev->eq;
            lib->li_numDrives = manualDrives;

        } else if (IS_THIRD_PARTY(dev)) {
            (void) strncpy(lib->li_name, "ThirdParty",
                           sizeof (lib->li_name));
            SET_LIB_THIRDPARTY(lib);
            lib->li_eq = dev->eq;
            (void) InitMigration(dev);

        } else if (IS_ROBOT(dev) || dev->equ_type == DT_PSEUDO_SC) {
            dev_ent_t *find;

            memcpy(lib->li_name, dev->set, sizeof (lib->li_name));
            lib->li_eq = dev->eq;

            /* Check if remote sam client */
            if (dev->equ_type == DT_PSEUDO_SC) {
                SET_LIB_REMOTE(lib);
            }

            /*
             * Find all drives belonging to this library.
             */
            find = dev_head;	/* Head of dev entries */
            for (find = dev_head; find != NULL;
                    find = (struct dev_ent *)SHM_REF_ADDR(find->next)) {
                if (find->eq != dev->eq) {
                    if (find->fseq == dev->eq) {
                        lib->li_numDrives++;

                        sprintf(drive->dr_name, "%s%d",
                                sam_mediatoa(find->type),
                                find->eq);
                        drive->dr_device = find;
                        drive->dr_lib = ldx;

                        /*
                         * Increment to next drive
                         * table entry.
                         */
                        drive++;
                        ddx++;
                    }
                }
            }

        } else if (dev->fseq == 0) {
            /*
             * Manual drive.
             */
            sprintf(lib->li_name, "%s%d", sam_mediatoa(dev->type),
                    dev->eq);
            SET_LIB_MANUAL(lib);
            lib->li_numDrives = 1;
            lib->li_manual = ddx;
            lib->li_eq = dev->eq;

            sprintf(drive->dr_name, "%s%d", sam_mediatoa(dev->type),
                    dev->eq);
            drive->dr_device = dev;
            drive->dr_lib = ldx;

            /* Increment to next drive table entry. */
            drive++;
            ddx++;

        } else {
            /* Not a library, continue to next dev entry. */
            continue;
        }

        /*
         * Set number of drives allowed.  Increment to next
         * library table entry.
         */
        lib->li_numAllowedDrives = lib->li_numDrives;
        lib++;
        ldx++;
    }

    if (numDiskVols > 0) {
        char *mtype;

        mtype = sam_mediatoa(DT_DISK);
        (void) strncpy(lib->li_name, mtype, sizeof (lib->li_name));
        SET_LIB_DISK(lib);
        SET_LIB_AVAIL(lib);
        lib->li_numDrives = numDiskVols * STREAMS_PER_DISKVOL;
        lib->li_numAllowedDrives = numDiskVols * STREAMS_PER_DISKVOL;
        lib->li_numAvailDrives = numDiskVols * STREAMS_PER_DISKVOL;

        /*
         * Define drives belonging to disk archive library.
         */
        for (jmap = 0; jmap < numDiskVols * STREAMS_PER_DISKVOL;
                jmap++) {

            sprintf(drive->dr_name, "%s%d", mtype, jmap);
            drive->dr_lib = ldx;
            SET_DRIVE_AVAIL(drive);

            /* Increment to next drive table entry. */
            drive++;
            ddx++;
        }

        lib++;
        ldx++;
    }

    if (numHoneycombVols > 0) {
        char *mtype;

        mtype = sam_mediatoa(DT_STK5800);
        (void) strncpy(lib->li_name, mtype, sizeof (lib->li_name));
        SET_LIB_HONEYCOMB(lib);
        SET_LIB_AVAIL(lib);
        lib->li_numDrives = numHoneycombVols;
        lib->li_numAllowedDrives = numHoneycombVols;
        lib->li_numAvailDrives = numHoneycombVols;

        /*
         * Define drives belonging to honeycomb archive library.
         */
        for (jmap = 0; jmap < numHoneycombVols; jmap++) {

            sprintf(drive->dr_name, "%s%d", mtype, jmap);
            drive->dr_lib = ldx;
            SET_DRIVE_AVAIL(drive);

            /* Increment to next drive table entry. */
            drive++;
            ddx++;
        }
    }

    (void) setDriveState(B_FALSE);		/* get current drive state */
}
Exemplo n.º 12
0
/*
 * Status drives and set state accordingly.  Returns
 * TRUE if a library state has changed.
 */
static int
setDriveState(
    boolean_t check)
{
    int changed = 0;

    int i;
    int manual_drives;
    int avail_drives;
    LibraryInfo_t *lib;
    DriveInfo_t *drive;
    dev_ent_t *dev;
    dev_ent_t *ent;
    int flags;

    dev_ent_t *dev_head;

    dev_head = GetDevices(check);

    manual_drives = 0;
    drive = driveTable.data;

    for (i = 0; i < libraryTable.entries; i++) {

        lib = &libraryTable.data[i];
        if (lib->li_flags & (LI_DISK | LI_HONEYCOMB))
            continue;

        dev = lib->li_device;
        avail_drives = 0;
        flags = 0;

        if (IS_LIB_HISTORIAN(lib)) {

            lib->li_numAllowedDrives = manual_drives;
            lib->li_numAvailDrives = manual_drives;
            avail_drives = manual_drives;

        } else if (IS_LIB_THIRDPARTY(lib)) {

            lib->li_numAllowedDrives = 1;
            lib->li_numAvailDrives = 1;
            avail_drives = 1;

            if (dev->state == DEV_ON) {
                flags = LI_AVAIL;
            } else {
                flags = LI_OFF;
            }

        } else if (IS_LIB_MANUAL(lib)) {

            /*
             * Manual drive is available if drive is on and ready.
             */

            drive->dr_flags = 0;
            if (dev->state == DEV_ON && dev->status.b.ready) {
                flags = LI_AVAIL;
                SET_DRIVE_AVAIL(drive);
                if (dev->status.b.opened) {
                    SET_DRIVE_BUSY(drive);
                }
                getDriveVsn(drive);
                avail_drives++;

            } else {
                CLEAR_DRIVE_AVAIL(drive);
                (void) memset(&drive->dr_vi, 0,
                              sizeof (VsnInfo_t));
            }
            if (IS_LIB_MANUAL(lib))
                manual_drives++;
            drive++;

        } else {

            /*
             * Robot.
             */

            if (dev == NULL) {
                /*
                 * This shouldn't happen.
                 */
                continue;
            }

            if ((dev->state == DEV_ON) &&
                    (dev->eq == 0 || dev->status.b.ready) &&
                    (dev->status.b.audit == 0)) {

                flags = LI_AVAIL; /* mark library available */
            } else if (dev->state == DEV_OFF) {
                flags = LI_OFF;		/* library is off */
            }

            /*
             * Check each drive belonging to this robot.
             */
            for (ent = dev_head; ent != NULL;
                    ent = (struct dev_ent *)SHM_REF_ADDR(ent->next)) {

                if (ent->eq == dev->eq) {
                    continue;
                }
                if (ent->fseq != dev->eq) {
                    continue;
                }

                /*
                 * Drive is available if library is available
                 * drive is on.
                 */
                drive->dr_flags = 0;
                if ((flags & LI_AVAIL) &&
                        ent->state == DEV_ON) {
                    SET_DRIVE_AVAIL(drive);
                    avail_drives++;
                    if (ent->status.b.ready) {
                        getDriveVsn(drive);
                        if (dev->status.b.opened) {
                            SET_DRIVE_BUSY(drive);
                        }
                    }
                } else {
                    CLEAR_DRIVE_AVAIL(drive);
                    (void) memset(&drive->dr_vi, 0,
                                  sizeof (VsnInfo_t));
                }
                drive++;
            }
        }

        if ((lib->li_flags & (LI_AVAIL | LI_OFF)) != flags ||
                lib->li_numAvailDrives != avail_drives) {

            /*
             * Library state has changed.
             */

            lib->li_flags &= ~(LI_AVAIL | LI_OFF);
            lib->li_flags |= flags;
            lib->li_numAvailDrives = avail_drives;
            Trace(TR_MISC, "Library %d state change: 0x%x %d",
                  lib->li_eq, lib->li_flags, avail_drives);
            changed = TRUE;
        }
    }
    return (changed);
}
Exemplo n.º 13
0
TEST(Engine, GetDevices) {
	auto engine = new pm::Engine();
	auto devices = engine->GetDevices();
}