示例#1
0
void CEXIChannel::DoState(PointerWrap &p)
{
	p.Do(m_Status);
	p.Do(m_DMAMemoryAddress);
	p.Do(m_DMALength);
	p.Do(m_Control);
	p.Do(m_ImmData);

	for (int d = 0; d < NUM_DEVICES; ++d)
	{
		IEXIDevice* pDevice = m_pDevices[d];
		TEXIDevices type = pDevice->m_deviceType;
		p.Do(type);
		IEXIDevice* pSaveDevice = (type == pDevice->m_deviceType) ? pDevice : EXIDevice_Create(type, m_ChannelId);
		pSaveDevice->DoState(p);
		if(pSaveDevice != pDevice)
		{
			// if we had to create a temporary device, discard it if we're not loading.
			// also, if no movie is active, we'll assume the user wants to keep their current devices
			// instead of the ones they had when the savestate was created,
			// unless the device is NONE (since ChangeDevice sets that temporarily).
			if(p.GetMode() != PointerWrap::MODE_READ)
			{
				delete pSaveDevice;
			}
			else
			{
				AddDevice(pSaveDevice, d, false);
			}
		}
	}
}
void FDeviceSDL::IgnoreGameControllers(bool bIgnore)
{
	if (bIgnore && !bIgnoreGameControllers)
	{
		bIgnoreGameControllers = true;
		for (auto &Device : Devices)
		{
			if (DeviceMapping.Contains(Device.Value.InstanceId) && SDL_IsGameController(Device.Value.DeviceIndex.value))
			{
				RemoveDevice(Device.Key);
			}
		}
	}
	else if (!bIgnore && bIgnoreGameControllers)
	{
		bIgnoreGameControllers = false;
		int Joysticks = SDL_NumJoysticks();
		for (int i = 0; i < Joysticks; i++)
		{
			if (SDL_IsGameController(i))
			{
				AddDevice(FDeviceIndex(i));
			}
		}
	}
}
示例#3
0
DevCall
NDev *
DevInit(register __a0 APTR seg)
{
    static func_ptr DevVectors[] = {
	(func_ptr)DevOpen,
	(func_ptr)DevClose,
	(func_ptr)DevExpunge,
	(func_ptr)DevReserved,
	(func_ptr)DevBeginIO,
	(func_ptr)DevAbortIO,
	(func_ptr)-1
    };
    NDev *db;

    DevBase = db = (NDev *)MakeLibrary((long **)DevVectors,NULL,NULL,sizeof(NDev),NULL);
    db->Lib.lib_Node.ln_Type = NT_DEVICE;
    db->Lib.lib_Node.ln_Name = DeviceName;
    db->Lib.lib_Flags = LIBF_CHANGED|LIBF_SUMUSED;
    db->Lib.lib_Version = 1;
    db->Lib.lib_IdString= (APTR)IdString;

    DevSegment = seg;
    AddDevice((DEV *)db);
    return(db);
}
示例#4
0
IDevice* CDeviceList::AddDevice(voidinstancefunc InstanceFunction, const int ID, void* MainWindow)
{
    instancefunc initializer=(instancefunc)InstanceFunction;
    IDevice* D=initializer();
    D->Init(ID,MainWindow);
    return AddDevice(D);
}
示例#5
0
INT_PTR CALLBACK BtrfsDeviceAdd::DeviceAddDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
    try {
        switch (uMsg) {
            case WM_INITDIALOG:
            {
                EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
                populate_device_tree(GetDlgItem(hwndDlg, IDC_DEVICE_TREE));
                EnableWindow(GetDlgItem(hwndDlg, IDOK), false);
                break;
            }

            case WM_COMMAND:
                switch (HIWORD(wParam)) {
                    case BN_CLICKED:
                        switch (LOWORD(wParam)) {
                            case IDOK:
                                AddDevice(hwndDlg);
                            return true;

                            case IDCANCEL:
                                EndDialog(hwndDlg, 0);
                            return true;
                        }
                    break;
                }
            break;

            case WM_NOTIFY:
                switch (((LPNMHDR)lParam)->code) {
                    case TVN_SELCHANGEDW:
                    {
                        NMTREEVIEWW* nmtv = (NMTREEVIEWW*)lParam;
                        TVITEMW tvi;
                        bool enable = false;

                        RtlZeroMemory(&tvi, sizeof(TVITEMW));
                        tvi.hItem = nmtv->itemNew.hItem;
                        tvi.mask = TVIF_PARAM | TVIF_HANDLE;

                        if (SendMessageW(GetDlgItem(hwndDlg, IDC_DEVICE_TREE), TVM_GETITEMW, 0, (LPARAM)&tvi))
                            sel = tvi.lParam == 0 ? nullptr : (device*)tvi.lParam;
                        else
                            sel = nullptr;

                        if (sel)
                            enable = (!sel->is_disk || !sel->has_parts) && !sel->multi_device;

                        EnableWindow(GetDlgItem(hwndDlg, IDOK), enable);
                        break;
                    }
                }
            break;
        }
    } catch (const exception& e) {
        error_message(hwndDlg, e.what());
    }

    return false;
}
示例#6
0
文件: nitrofs.c 项目: kusma/nds
//Figure out if its gba or ds, setup stuff
int nitroFSInit(const char *ndsfile) {
	unsigned int pos=0;
	char romstr[0x10];
	chdirpathid=NITROROOT;
	ndsFileLastpos=0;
	ndsFile=NULL;
	REG_EXMEMCNT &= ~ARM7_OWNS_CARD; //give us gba slot ownership
	if(strncmp(((const char *)GBAROM)+LOADERSTROFFSET,LOADERSTR,strlen(LOADERSTR))==0) {	// We has gba rahm
		if(strncmp(((const char *)GBAROM)+LOADERSTROFFSET+LOADEROFFSET,LOADERSTR,strlen(LOADERSTR))==0) { //Look for second magic string, if found its a sc.nds or nds.gba
			fntOffset=((u32)*(u32*)(((const char *)GBAROM)+FNTOFFSET+LOADEROFFSET))+LOADEROFFSET;	
			fatOffset=((u32)*(u32*)(((const char *)GBAROM)+FATOFFSET+LOADEROFFSET))+LOADEROFFSET;
			hasLoader=true;
			AddDevice(&nitroFSdevoptab);
			return(1);
		} else {	//Ok, its not a .gba build, so must be emulator
			fntOffset=((u32)*(u32*)(((const char *)GBAROM)+FNTOFFSET));	
			fatOffset=((u32)*(u32*)(((const char *)GBAROM)+FATOFFSET));
			hasLoader=false;
			AddDevice(&nitroFSdevoptab);
			return(1);
		}
	} else {	//okay then try something else ~_~ (like dldi)
		if((ndsFile=fopen(ndsfile,"rb"))) {
			nitroSubRead(&pos,romstr,strlen(LOADERSTR));
			if(strncmp(romstr,LOADERSTR,strlen(LOADERSTR))==0) {	
				nitroSubSeek(&pos,LOADEROFFSET+FNTOFFSET,SEEK_SET);
				nitroSubRead(&pos,&fntOffset,sizeof(fntOffset));
				nitroSubSeek(&pos,LOADEROFFSET+FATOFFSET,SEEK_SET);
				nitroSubRead(&pos,&fatOffset,sizeof(fatOffset));
				fatOffset+=LOADEROFFSET;
				fntOffset+=LOADEROFFSET;
				hasLoader=true;
			} else {
				nitroSubSeek(&pos,FNTOFFSET,SEEK_SET);
				nitroSubRead(&pos,&fntOffset,sizeof(fntOffset));
				nitroSubSeek(&pos,FATOFFSET,SEEK_SET);
				nitroSubRead(&pos,&fatOffset,sizeof(fatOffset));
				hasLoader=false;
			}
			setvbuf(ndsFile,NULL,_IONBF,0);		//we dont need double buffs u_u
			AddDevice(&nitroFSdevoptab);
			return(1);
		} 
	}
	return(0);
}
示例#7
0
void GOptimizingBench::CreateOptimizer()
{
	if(m_pOpt)
		delete m_pOpt;
	m_pOpt = new GOptimizer(this);
	GDeviceWidget* pDevWid = AddDevice(m_pOpt);
	setCentralWidget(pDevWid);
}
示例#8
0
int CEnumerator::OnEnumFindDevice(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, PSP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceDetailData, int a5)
{
	if(PowerUp(0, DeviceInfoData->DevInst))
	{
		return 1;
	}
	return AddDevice(DeviceInfoSet, DeviceInfoData, DeviceInterfaceDetailData, a5);
}
示例#9
0
文件: wrapper.c 项目: cod5/kielder
int cd_init (void *elf)
{
	KPRINTF ("cd_init()");

	elf_header = elf;
	AddDevice (&cd_device);
	
	return 0;
}
示例#10
0
GBenchDockWidget* GWorkBench::AddDeviceInNewDock( GDevice* pTheDevice, bool putOnStack /*= true*/ )
{
    GDeviceWidget* pDevWid = AddDevice(pTheDevice);
    if(!pDevWid)
        return 0;
    GBenchDockWidget* pNewDock = new GBenchDockWidget(this, Qt::AllDockWidgetAreas);
    pNewDock->InsertDeviceWidget(pDevWid);
    return pNewDock;
}
NS_IMETHODIMP
sbCDDeviceMarshall::OnMediaInserted(sbICDDevice *aDevice)
{
  NS_ENSURE_ARG_POINTER(aDevice);

  nsresult rv = AddDevice(aDevice);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
示例#12
0
文件: random.c 项目: osstudy/glidix
MODULE_INIT(const char *opt)
{
	devRandom = AddDevice("random", NULL, openRandom, 0);
	if (devRandom == NULL)
	{
		kprintf("could not add the random device!\n");
		return 1;
	};
	return 0;
};
// nsIDNSServiceResolveListener
NS_IMETHODIMP
LegacyMDNSDeviceProvider::OnServiceResolved(nsIDNSServiceInfo* aServiceInfo)
{
  MOZ_ASSERT(NS_IsMainThread());

  if (NS_WARN_IF(!aServiceInfo)) {
    return NS_ERROR_INVALID_ARG;
  }

  nsresult rv;

  nsAutoCString serviceName;
  if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceName(serviceName)))) {
    return rv;
  }

  LOG_I("OnServiceResolved: %s", serviceName.get());

  nsAutoCString host;
  if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetHost(host)))) {
    return rv;
  }

  nsAutoCString address;
  if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetAddress(address)))) {
    return rv;
  }

  uint16_t port;
  if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetPort(&port)))) {
    return rv;
  }

  nsAutoCString serviceType;
  if (NS_WARN_IF(NS_FAILED(rv = aServiceInfo->GetServiceType(serviceType)))) {
    return rv;
  }

  uint32_t index;
  if (FindDeviceById(host, index)) {
    return UpdateDevice(index,
                        serviceName,
                        serviceType,
                        address,
                        port);
  } else {
    return AddDevice(host,
                     serviceName,
                     serviceType,
                     address,
                     port);
  }

  return NS_OK;
}
示例#14
0
/**
 * Fetch a list of all FTDI widgets and create a new device for each of them.
 */
bool FtdiDmxPlugin::StartHook() {
  typedef vector<FtdiWidgetInfo> FtdiWidgetInfoVector;
  FtdiWidgetInfoVector widgets;
  FtdiWidget::Widgets(&widgets);

  FtdiWidgetInfoVector::const_iterator iter;
  for (iter = widgets.begin(); iter != widgets.end(); ++iter) {
    AddDevice(new FtdiDmxDevice(this, *iter, GetFrequency()));
  }
  return true;
}
示例#15
0
static void CreateDeviceList(IXMLDOMDocument* pDoc,IXMLDOMElement* pParent,const DEVICELIST& l)
{
	HRESULT hr;
	for(size_t n=0;n<l.size();n++)
	{
		IXMLDOMElementPtr device;
		CreateElement(pDoc,L"device",&device);
		AddDevice(pDoc,device,l[n]);
		AppendChild(device,pParent);
	}
}
示例#16
0
OpenNi2Video::OpenNi2Video(const std::string& device_uri)
{
    InitialiseOpenNI();

    const int dev_id = AddDevice(device_uri);
    AddStream(OpenNiStreamMode( OpenNiDepth_1mm, ImageDim(), 30, dev_id) );
    AddStream(OpenNiStreamMode( OpenNiRgb,   ImageDim(), 30, dev_id) );

    SetupStreamModes();
    Start();
}
示例#17
0
//---------------------------------------------------------------------------------
int ramdiskFS_Mount(const char *mountpoint, void *handle) {
//---------------------------------------------------------------------------------
	devoptab_t* devops;
	char* nameCopy;
	RAMDISK_PARTITION** partition;
	char Mountpoint[100];
	char *cptr;

	strlcpy(Mountpoint, mountpoint, sizeof(Mountpoint));
	int len = strlen(Mountpoint);
	cptr = strchr(Mountpoint, ':');
	if(cptr)
	{
		len = cptr-Mountpoint;
		*++cptr = 0;
	}
	else
		strlcat(Mountpoint, ":", sizeof(Mountpoint));
	ramdiskFS_Unmount(Mountpoint);
	if(handle) ramdiskFS_Unmount(((RAMDISK_PARTITION*)handle)->name);
	
	devops = (devoptab_t*)malloc(sizeof(devoptab_t) + sizeof(RAMDISK_PARTITION*) + len + 1);
	if (!devops)
		return false;

	partition = (RAMDISK_PARTITION**)(devops+1);	// Use the space allocated at the end of the devoptab struct
											// for storing the partition
	nameCopy = (char*)( partition+1);				// Use the space allocated at the end of the partition struct
											// for storing the name
	
	memcpy (devops, &ramdiskFS_devoptab, sizeof(ramdiskFS_devoptab)); // Add an entry for this device to the devoptab table

	strlcpy (nameCopy, Mountpoint, len + 1);
	devops->name = nameCopy;
	
	if(handle)
	{
		*partition = (RAMDISK_PARTITION*)handle;
		(*partition)->Rename(Mountpoint);
	}
	else
		*partition = new RAMDISK_PARTITION(Mountpoint, true);
	devops->deviceData			= partition; 

	if(AddDevice(devops)<0)
	{
		free(devops);
		return false;
	}

	return true;

}
示例#18
0
void RegEdit::OnSocItemActivated(QTreeWidgetItem *current, int column)
{
    Q_UNUSED(column);
    if(current == 0)
        return;
    if(current->type() == SocTreeNewDevType)
        AddDevice(current);
    else if(current->type() == SocTreeNewRegType)
        AddRegister(current);
    else if(current->type() == SocTreeNewFieldType)
        AddField(current);
}
示例#19
0
FVisualLogger::FVisualLogger()
{
	BlockAllCategories(false);
	AddDevice(&FVisualLoggerBinaryFileDevice::Get());
	SetIsRecording(GEngine ? !!GEngine->bEnableVisualLogRecordingOnStart : false);
	SetIsRecordingOnServer(false);

	if (FParse::Param(FCommandLine::Get(), TEXT("EnableAILogging")))
	{
		SetIsRecording(true);
		SetIsRecordingToFile(true);
	}
}
void FSDrvInit(FSClient* client, FSCmdBlock* cmdBlock) {
    if(client == NULL || cmdBlock == NULL || (fsClient != NULL && fsCmdBlock != NULL)) {
        return;
    }

    fsClient = client;
    fsCmdBlock = cmdBlock;

    int dev = AddDevice(&fsDrvOpTab);
    if(dev != -1) {
        setDefaultDevice(dev);
    }
}
示例#21
0
OpenNi2Video::OpenNi2Video(const std::string& device_uri, std::vector<OpenNiStreamMode> &stream_modes)
{
    InitialiseOpenNI();

    AddDevice(device_uri);

    for(size_t i=0; i < stream_modes.size(); ++i) {
        OpenNiStreamMode& mode = stream_modes[i];
        AddStream(mode);
    }

    SetupStreamModes();
    Start();
}
示例#22
0
void GWorkBench::AddDeviceInDock( GDevice* pTheDevice, GBenchDockWidget* pDock, bool putOnStack /*= true*/ )
{
    if(!pTheDevice)
        return;
    if(!pDock) {
        qWarning() << "GWorkBench::AddDeviceInDock : The GBenchDockWidget* pointer is 0! 875494";
        return;
    }

    GDeviceWidget* pDevWid = AddDevice(pTheDevice);
    if(!pDevWid)
        return;
    pDock->InsertDeviceWidget(pDevWid);
}
示例#23
0
DeviceWidget::DeviceWidget(QWidget* Parent)
: QWidget(Parent), ui(new Ui::DeviceWidget)
{
	ui->setupUi(this);

	ui->devicesLayout->setAlignment(Qt::AlignTop);

	Dialog = new DeviceDialog(-1, this);

	for (const auto& Data: AppCore::getInstance()->GetDevices()) AddDevice(Data);

	connect(Dialog, &DeviceDialog::onDialogAccept, this, &DeviceWidget::AddDevice);
	connect(ui->addButton, &QPushButton::clicked, Dialog, &DeviceDialog::open);
}
示例#24
0
/*******************************************************************************
 *
 * Function   :  PlxDispatch_Probe
 *
 * Description:  Called by the OS to determine if a device is supported by the driver
 *
 ******************************************************************************/
int
PlxDispatch_Probe(
    struct pci_dev             *pDev,
    const struct pci_device_id *pID
)
{
    int status;


    // Default to supported device
    status = 0;

    DebugPrintf(("   --------------------\n"));
    DebugPrintf((
                    "Probe: %04X %04X [b:%02x s:%02x f:%x]\n",
                    pDev->device, pDev->vendor, pDev->bus->number, PCI_SLOT(pDev->devfn), PCI_FUNC(pDev->devfn)
                ));

    // Verify PLX device
    //if (pDev->vendor != PLX_VENDOR_ID)
    //     status = -ENODEV;

    // Make sure the PCI Header type is 0
    if (pDev->hdr_type != 0) {
        status = -ENODEV;
        DebugPrintf(("PCI Header type is not 0\n"));
    }

    // Must be a function 0 device
    if (PCI_FUNC(pDev->devfn) != 0) {
        status = -ENODEV;
        DebugPrintf(("Not a function 0 device\n"));
    }

    if (status != 0)
    {
        DebugPrintf(("Probe: -- Unsupported Device --\n"));
        return status;
    }

    // Add the device to the device list
    status =
        AddDevice(
            pGbl_DriverObject,
            pDev
        );

    return status;
}
示例#25
0
// this routine reads device notifications from a message queue and updates
// the PM's internal tables appropriately.
BOOL
ProcessPnPMsgQueue(HANDLE hMsgQ)
{
    BOOL fOk = FALSE;
    UCHAR deviceBuf[PNP_QUEUE_SIZE];
    DWORD iBytesInQueue = 0;
    DWORD dwFlags = 0;
    SETFNAME(_T("ProcessPnPMsgQueue"));

    // read a message from the message queue -- it should be a device advertisement
    memset(deviceBuf, 0, PNP_QUEUE_SIZE);
    if ( !ReadMsgQueue(hMsgQ, deviceBuf, PNP_QUEUE_SIZE, &iBytesInQueue, 0, &dwFlags)) {
        // nothing in the queue
        PMLOGMSG(ZONE_WARN, (_T("%s: ReadMsgQueue() failed %d\r\n"), pszFname,
            GetLastError()));
    } else if(iBytesInQueue >= sizeof(DEVDETAIL)) {
        // process the message
        PDEVDETAIL pDevDetail = (PDEVDETAIL) deviceBuf;
        DWORD dwMessageSize = sizeof(DEVDETAIL) + pDevDetail->cbName;
        
        // check for overlarge names
        if(pDevDetail->cbName > ((PNP_MAX_NAMELEN - 1) * sizeof(pDevDetail->szName[0]))) {
            PMLOGMSG(ZONE_WARN, (_T("%s: device name longer than %d characters\r\n"), 
                pszFname, PNP_MAX_NAMELEN - 1));
        } else {
            // convert the device name to lower case
            int i;
            for(i = 0; i < (PNP_MAX_NAMELEN - 1) && pDevDetail->szName[i] != 0; i++) {
                pDevDetail->szName[i] = _totlower(pDevDetail->szName[i]);
            }
            pDevDetail->szName[i] = 0;
            
            // add or remove the device -- note that a particular interface may be
            // advertised more than once, so these routines must handle that possibility.
            if(pDevDetail->fAttached) {
                AddDevice(&pDevDetail->guidDevClass, pDevDetail->szName, NULL, NULL);
            } else {
                RemoveDevice(&pDevDetail->guidDevClass, pDevDetail->szName);
            }
            fOk = TRUE;
        }
    } else {
        // not enough bytes for a message
        PMLOGMSG(ZONE_WARN, (_T("%s: got runt message (%d bytes)\r\n"), pszFname, 
            iBytesInQueue));
    }

    return fOk;
}
示例#26
0
bool USBHost::AddNewDevices(std::set<u64>& new_devices, DeviceChangeHooks& hooks,
                            const bool always_add_hooks)
{
#ifdef __LIBUSB__
  if (SConfig::GetInstance().m_usb_passthrough_devices.empty())
    return true;

  if (m_libusb_context)
  {
    libusb_device** list;
    const ssize_t count = libusb_get_device_list(m_libusb_context, &list);
    if (count < 0)
    {
      WARN_LOG(IOS_USB, "Failed to get device list: %s",
               libusb_error_name(static_cast<int>(count)));
      return false;
    }

    for (ssize_t i = 0; i < count; ++i)
    {
      libusb_device* device = list[i];
      libusb_device_descriptor descriptor;
      libusb_get_device_descriptor(device, &descriptor);
      if (!SConfig::GetInstance().IsUSBDeviceWhitelisted(
              {descriptor.idVendor, descriptor.idProduct}))
      {
        libusb_unref_device(device);
        continue;
      }

      auto usb_device = std::make_unique<USB::LibusbDevice>(m_ios, device, descriptor);
      if (!ShouldAddDevice(*usb_device))
      {
        libusb_unref_device(device);
        continue;
      }
      const u64 id = usb_device->GetId();
      new_devices.insert(id);
      if (AddDevice(std::move(usb_device)) || always_add_hooks)
        hooks.emplace(GetDeviceById(id), ChangeEvent::Inserted);
      else
        libusb_unref_device(device);
    }
    libusb_free_device_list(list, 0);
  }
#endif
  return true;
}
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	// DeviceArrived()
	//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
	void PlugIn::DeviceArrived(UInt64 guid, const io_string_t registryPath)
	{
		try
		{	
			// Instantiate a new CMIODevice object in the DAL
			CMIODeviceID deviceID = 0;
			OSStatus err = CMIOObjectCreate(GetInterface(), kCMIOObjectSystemObject, kCMIODeviceClassID, &deviceID);
			ThrowIfError(err, CAException(err), "CMIO::DP::Sample::PlugIn::DeviceArrived: couldn't instantiate the CMIODevice object");

			// Make a device object
			Device* device = new Device(*this, deviceID, mAssistantPort, guid, registryPath);

			try
			{
				// Initialize the device
				device->Initialize();
				
				// Restore its settings if necessary
				if (DALA::System::IsMaster())
				{
					DP::DeviceSettings::RestoreFromPrefs(*device, DP::DeviceSettings::sStandardControlsToSave, DP::DeviceSettings::kStandardNumberControlsToSave);
				}
				
				// Set the object state mutex
				Object::SetObjectStateMutexForID(deviceID, device->GetObjectStateMutex());
				
				// Add it to the device list
				AddDevice(*device);

				// Unlock the mutex since CMIOObjectsPublishedAndDied() can callout to property listeners
				CAMutex::Unlocker unlocker(GetStateMutex());

				// Tell the DAL about the device
				err = CMIOObjectsPublishedAndDied(GetInterface(), kCMIOObjectSystemObject, 1, &deviceID, 0, 0);
				ThrowIfError(err, err, "CMIO::DP::Sample::PlugIn::DeviceArrived: couldn't tell the DAL about a new device");
			}
			catch (...)
			{
				// Remove it from the device list (which is always safe to attempt) and delete it
				RemoveDevice(*device);
				delete device;
			}
		}
		catch (...)
		{
		}
	}
示例#28
0
文件: mtp.c 项目: etix/vlc
/*****************************************************************************
 * Run: main thread
 *****************************************************************************/
static void *Run( void *data )
{
    LIBMTP_raw_device_t *p_rawdevices;
    int i_numrawdevices;
    int i_ret;
    int i_status = 0;
    services_discovery_t *p_sd = data;

    for(;;)
    {
        int canc = vlc_savecancel();
        i_ret = LIBMTP_Detect_Raw_Devices( &p_rawdevices, &i_numrawdevices );
        if ( i_ret == 0 && i_numrawdevices > 0 && p_rawdevices != NULL &&
             i_status == 0 )
        {
            /* Found a new device, add it */
            msg_Dbg( p_sd, "New device found" );
            if( AddDevice( p_sd, &p_rawdevices[0] ) == VLC_SUCCESS )
                i_status = 1;
            else
                i_status = 2;
        }
        else
        {
            if ( ( i_ret != 0 || i_numrawdevices == 0 || p_rawdevices == NULL )
                 && i_status == 1)
            {
                /* The device is not connected anymore, delete it */
                msg_Info( p_sd, "Device disconnected" );
                CloseDevice( p_sd );
                i_status = 0;
            }
        }
        free( p_rawdevices );
        vlc_restorecancel(canc);
        if( i_status == 2 )
        {
            msleep( 5000000 );
            i_status = 0;
        }
        else
            msleep( 500000 );
    }
    return NULL;
}
示例#29
0
/**
 * \class MediaMonitorWindows
 *
 * I am assuming, for now, that everything on Windows uses drive letters
 * (e.g. C:, D:). That is probably wrong, though. (other APIs?)
 */
MediaMonitorWindows::MediaMonitorWindows(QObject* par,
                                         unsigned long interval,
                                         bool allowEject)
                   : MediaMonitor(par, interval, allowEject)
{
    char strDrives[128];
    if (!::GetLogicalDriveStrings(sizeof(strDrives), strDrives))
        return;

    for (char *driveName = strDrives; *driveName;
         driveName += strlen(driveName) + 1)
    {
        uint type = ::GetDriveType(driveName);
        if (type != DRIVE_REMOVABLE && type != DRIVE_CDROM)
            continue;

        MythMediaDevice *media = NULL;

        if (type == DRIVE_CDROM)
            media = MythCDROM::get(this, driveName, false, allowEject);
        else
            media = MythHDD::Get(this, driveName, false, allowEject);

        if (!media)
        {
            VERBOSE(VB_IMPORTANT,
                    "Error. Couldn't create MythMediaDevice.");
            return;
        }

        // We store the volume name to improve
        // user activities like ChooseAndEjectMedia().
        char volumeName[MAX_PATH];
        if (GetVolumeInformation(driveName, volumeName, MAX_PATH,
                                 NULL, NULL, NULL, NULL, NULL))
        {
            media->setVolumeID(volumeName);
        }

        AddDevice(media);
    }

    VERBOSE(VB_MEDIA, "Initial device list: " + listDevices());
}
示例#30
0
bool fatMount (const char* name, const DISC_INTERFACE* interface, sec_t startSector, uint32_t cacheSize, uint32_t SectorsPerPage) {
	PARTITION* partition;
	devoptab_t* devops;
	char* nameCopy;

	if(!name || strlen(name) > 8 || !interface)
		return false;

	if(!interface->startup())
		return false;

	if(!interface->isInserted())
		return false;

	char devname[10];
	strcpy(devname, name);
	strcat(devname, ":");
	if(FindDevice(devname) >= 0)
		return true;

	devops = _FAT_mem_allocate (sizeof(devoptab_t) + strlen(name) + 1);
	if (!devops) {
		return false;
	}
	// Use the space allocated at the end of the devoptab struct for storing the name
	nameCopy = (char*)(devops+1);

	// Initialize the file system
	partition = _FAT_partition_constructor (interface, cacheSize, SectorsPerPage, startSector);
	if (!partition) {
		_FAT_mem_free (devops);
		return false;
	}

	// Add an entry for this device to the devoptab table
	memcpy (devops, &dotab_fat, sizeof(dotab_fat));
	strcpy (nameCopy, name);
	devops->name = nameCopy;
	devops->deviceData = partition;

	AddDevice (devops);

	return true;
}