Exemplo n.º 1
0
/*
 *	Initializer
 */
void
InitArchiveFmt_Files(ArchiveHandle *AH)
{
	lclContext *ctx;

	/* Assuming static functions, this can be copied for each format. */
	AH->ArchiveEntryPtr = _ArchiveEntry;
	AH->StartDataPtr = _StartData;
	AH->WriteDataPtr = _WriteData;
	AH->EndDataPtr = _EndData;
	AH->WriteBytePtr = _WriteByte;
	AH->ReadBytePtr = _ReadByte;
	AH->WriteBufPtr = _WriteBuf;
	AH->ReadBufPtr = _ReadBuf;
	AH->ClosePtr = _CloseArchive;
	AH->PrintTocDataPtr = _PrintTocData;
	AH->ReadExtraTocPtr = _ReadExtraToc;
	AH->WriteExtraTocPtr = _WriteExtraToc;
	AH->PrintExtraTocPtr = _PrintExtraToc;

	AH->StartBlobsPtr = _StartBlobs;
	AH->StartBlobPtr = _StartBlob;
	AH->EndBlobPtr = _EndBlob;
	AH->EndBlobsPtr = _EndBlobs;

	/*
	 * Set up some special context used in compressing data.
	 */
	ctx = (lclContext *) calloc(1, sizeof(lclContext));
	AH->formatData = (void *) ctx;
	ctx->filePos = 0;

	/* Initialize LO buffering */
	AH->lo_buf_size = LOBBUFSIZE;
	AH->lo_buf = (void *) malloc(LOBBUFSIZE);
	if (AH->lo_buf == NULL)
		die_horribly(AH, modulename, "out of memory\n");

	/*
	 * Now open the TOC file
	 */
	if (AH->mode == archModeWrite)
	{

		write_msg(modulename, "WARNING:\n"
				  "  This format is for demonstration purposes; it is not intended for\n"
				  "  normal use. Files will be written in the current working directory.\n");

		if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
			AH->FH = fopen(AH->fSpec, PG_BINARY_W);
		else
			AH->FH = stdout;

		if (AH->FH == NULL)
			die_horribly(NULL, modulename, "could not open output file: %s\n", strerror(errno));

		ctx->hasSeek = checkSeek(AH->FH);

		if (AH->compression < 0 || AH->compression > 9)
			AH->compression = Z_DEFAULT_COMPRESSION;


	}
	else
	{							/* Read Mode */

		if (AH->fSpec && strcmp(AH->fSpec, "") != 0)
			AH->FH = fopen(AH->fSpec, PG_BINARY_R);
		else
			AH->FH = stdin;

		if (AH->FH == NULL)
			die_horribly(NULL, modulename, "could not open input file: %s\n", strerror(errno));

		ctx->hasSeek = checkSeek(AH->FH);

		ReadHead(AH);
		ReadToc(AH);
		/* Nothing else in the file... */
		if (fclose(AH->FH) != 0)
			die_horribly(AH, modulename, "could not close TOC file: %s\n", strerror(errno));
	}
}
Exemplo n.º 2
0
void RDCdPlayer::clockData()
{
  bool new_state;
  struct cdrom_subchnl subchnl;

  //
  // Media Status
  //
  if(ioctl(cdrom_fd,CDROM_MEDIA_CHANGED,NULL)==0) {
    new_state=true;
    if(cdrom_old_state==false) {
      Profile("ReadToc() started");
      ReadToc();
      Profile("ReadToc() finished");
      Profile("emitting mediaChanged()");
      emit mediaChanged();
      Profile("mediaChanged() emitted");
    }
  }
  else {
    new_state=false;
    if(cdrom_old_state==true) {
      Profile("emitting ejected()");
      emit ejected();
      Profile("ejected() emitted");
    }
  }
  cdrom_old_state=new_state;

  //
  // Audio State
  //
  memset(&subchnl,0,sizeof(struct cdrom_subchnl));
  subchnl.cdsc_format=CDROM_MSF;
  Profile("calling ioctl(CDROMSUBCHNL)");
  if(ioctl(cdrom_fd,CDROMSUBCHNL,&subchnl)>=0) {
    Profile("ioctl(CDROMSUBCHNL) success");
    if(cdrom_audiostatus!=subchnl.cdsc_audiostatus) {
      cdrom_audiostatus=subchnl.cdsc_audiostatus;
      cdrom_track=subchnl.cdsc_trk;
      switch(cdrom_audiostatus) {
	  case CDROM_AUDIO_INVALID:
	    cdrom_state=NoStateInfo;
	    break;
	  case CDROM_AUDIO_PLAY:
	    cdrom_state=RDCdPlayer::Playing;
	    emit played(cdrom_track);
	    break;
	  case CDROM_AUDIO_PAUSED:
	    cdrom_state=RDCdPlayer::Paused;
	    emit paused();
	    break;
	  case CDROM_AUDIO_COMPLETED:
	    cdrom_state=RDCdPlayer::Stopped;
	    emit stopped();
	    break;
	  case CDROM_AUDIO_ERROR:
	    cdrom_state=RDCdPlayer::Stopped;
	    emit stopped();
	    break;
	  case CDROM_AUDIO_NO_STATUS:
	    cdrom_state=RDCdPlayer::Stopped;
	    emit stopped();
	    break;
      }
    }
  }
  else {
    Profile("ioctl(CDROMSUBCHNL) failure");
    if(cdrom_audiostatus!=CDROM_AUDIO_NO_STATUS) {
      cdrom_audiostatus=CDROM_AUDIO_NO_STATUS;
      cdrom_state=RDCdPlayer::Stopped;
      emit stopped();
    }
  }
  cdrom_clock->start(RDCDPLAYER_CLOCK_INTERVAL,true);
}