POE-Component-NomadJukebox

 view release on metacpan or  search on metacpan

NomadJukebox/Device.xs  view on Meta::CPAN

	return newSVpv (NJB_Get_TmpDir(njb), 0);
}

/*
 * Set the temp dir
*/

SV*
SetTmpDir( SV* device, SV* dir ) {
	SV*     result;
	STRLEN  len;
	char    dir_string[256];
	njb_t*  njb;

	if (SvROK( device )) {
		device = SvRV( device );
	}

	njb = (njb_t*) SvIV( device );

	if (!njb) {
		return &PL_sv_undef;
	}

	strncpy( dir_string, SvPV( dir, len ), 255 );
	dir_string[len] = 0;

	return newSViv( (IV) NJB_Set_TmpDir( njb, dir_string ));
}

/*
 * Delete Playlist
*/

static SV*
DeletePlayList ( SV* device, int plid ) {
	njb_t*     njb;

	if (SvROK( device )) {
		device = SvRV( device );
	}

	njb = (njb_t*) SvIV( device );

	if (njb) {
		int status;

		status = NJB_Delete_Playlist( njb, plid );
		return newSViv( (IV) status );
	}

	return &PL_sv_undef;
}

/**************** Perl Stubs ****************/

MODULE = POE::Component::NomadJukebox::Device		PACKAGE = POE::Component::NomadJukebox::Device		

AV*
Discover ()
	PPCODE:
	HV*    devlist;
	SV*    devid;
//	SV*    type;
	int    n, i;

	devlist = newHV();

	if (NJB_Discover(njbs, 0, &n) == -1) {
		XSRETURN( 0 );
	}

	for (i=0; i<n; i++) {
		XPUSHs( newRV_noinc( (SV*) devlist ));
		devid = newSViv ( (IV) &(njbs[i]) );
//		type = newSViv ( (IV) njbs[i]->device_type);
		hv_store (devlist, "DEVID", 5, devid, 0);
// doesn't work
//		hv_store (devlist, "TYPE", 4, type, 0);
	}

	XSRETURN( i );

SV*
Open ( device )
	SV * device
	OUTPUT:
		RETVAL

void
TrackList ( device, extended )
	SV * device
	int extended
	PPCODE:
	njb_t*     njb;
	int        n, count=0;
	songid_t*  songtag;

	if (SvROK( device )) {
		device = SvRV( device );
	}

	njb = (njb_t*) SvIV( device );
	if ( !njb ) {
	    XSRETURN(0);
	}

	if ( extended == 1 ) {
		// 20 times slower because it gets more tags
		NJB_Get_Extended_Tags(njb, 1);
	}

	NJB_Reset_Get_Track_Tag(njb);
	while ( songtag = NJB_Get_Track_Tag(njb) ) {
		HV*    HV_track_info;
		SV*    data;
		SV*    tag;
		songid_frame_t*  songinfo;
		int    i, j;

		HV_track_info = newHV();
		XPUSHs( newRV_noinc( (SV*) HV_track_info));
		count++;
		tag = newSViv ( (IV) songtag );
		data = newSViv ( (IV) songtag->trid);
		hv_store (HV_track_info, "ID", 2, data, 0);
		hv_store (HV_track_info, "TAG", 3, tag, 0);
// this is set below
//		hv_store (HV_track_info, "SIZE", 4, newSViv( songid_size( songtag )), 0 );
		songinfo = songtag->first;

		for (i=0; i<songtag->nframes; i++) {
			char newdata[256];

 			switch (songinfo->type) {
				case 1:		snprintf ((char *) newdata, 256, "%lu",
							songid_frame_data32(songinfo));
							break;

				case 0:		memcpy(newdata,
							songinfo->data,
							songinfo->datasz);
							break;

				default:	strcpy (newdata, "UNDEF");
			}

			data = newSVpv ( newdata, strlen (newdata) );
  			for (j=0; j<songinfo->labelsz; j++) {
				if ( ((char*) songinfo->label)[j] < 22)
					break;
			}
			hv_store (HV_track_info,
				  (char*) songinfo->label,
				  j,
				  data,
				  0);
			songinfo = songinfo->next;
		}

	}

	// turn it off
	if ( extended == 1 ) {
		NJB_Get_Extended_Tags(njb, 0);
	}
	XSRETURN(count);

void
PlayList ( device )
	SV * device
	PPCODE:
	njb_t*     njb;
//	njbid_t    njbid;
	int        n, count=0;
	playlist_t*  pl;

	if (SvROK( device )) {
		device = SvRV( device );
	}

	njb = (njb_t*) SvIV( device );
	if ( !njb ) {
	    XSRETURN(0);
	}

	NJB_Reset_Get_Playlist(njb);
	while ( pl = NJB_Get_Playlist(njb) ) {
		HV*    HV_playlist_info;
		AV*    AV_tracklist;
		playlist_track_t*  trackinfo;
		int    i;

		AV_tracklist = newAV();
		HV_playlist_info = newHV();
		XPUSHs( newRV_noinc( (SV*) HV_playlist_info));
		count++;
		hv_store (HV_playlist_info, "ID", 2, newSViv( (IV) pl->plid ), 0);
		hv_store (HV_playlist_info, "NAME", 4, newSVpv( pl->name, strlen(pl->name) ), 0);
		hv_store (HV_playlist_info, "TAG", 3, newSViv( (IV) pl ), 0);
		hv_store (HV_playlist_info, "STATE", 5, newSViv( (IV) pl->_state), 0);
		trackinfo = pl->first;
		for (i=0; i<pl->ntracks; i++) {
			SV* trackid;
			
			trackid = newSViv ( (IV) trackinfo->trackid );
			av_push(AV_tracklist,trackid);
			trackinfo = trackinfo->next;
		}
		hv_store (HV_playlist_info, "TRACKS", 6, newRV((SV*) AV_tracklist), 0); 
	}
	XSRETURN(count);

void
FileList ( device )
	SV * device
	PPCODE:
	njb_t*     njb;
	int        n, count=0;
	datafile_t*  datatag;

	if (SvROK( device )) {
		device = SvRV( device );
	}

	njb = (njb_t*) SvIV( device );
	if ( !njb ) {
	    XSRETURN(0);
	}

	NJB_Reset_Get_Datafile_Tag(njb);
	while ( datatag = NJB_Get_Datafile_Tag(njb) ) {
		HV*    HV_datafile_info;

		HV_datafile_info = newHV();
		XPUSHs( newRV_noinc( (SV*) HV_datafile_info));
		count++;
		
		hv_store (HV_datafile_info, "ID", 2, newSVnv ( (NV) datatag->dfid ), 0);
		hv_store (HV_datafile_info, "FILE", 4, newSVpv ( datatag->filename, strlen(datatag->filename) ), 0);
		hv_store (HV_datafile_info, "SIZE", 4, newSVnv ( (NV) datafile_size(datatag) ), 0);
		hv_store (HV_datafile_info, "TAG", 3, newSViv ( (IV) datatag ), 0);
// doesn't work
//		hv_store (HV_datafile_info, "TIMESTAMP", 9, newSVnv ( (NV) datatag->timestamp ), 0);
	}
	XSRETURN(count);

SV*
GetTrack ( device, hash, fname )
	SV *   device
	SV *   hash
	char * fname;
	OUTPUT:
		RETVAL


SV*
SendTrack ( device, arglist )
	SV* device
	SV* arglist
	OUTPUT:
		RETVAL

SV*
SendFile ( device, arglist )
	SV* device
	SV* arglist
	OUTPUT:
		RETVAL

SV*
GetFile ( device, hash, fname )
	SV *   device
	SV *   hash
	char * fname;
	OUTPUT:
		RETVAL

NomadJukebox/Device.xs  view on Meta::CPAN

		RETVAL

SV*
SeekTrack ( device, position )
	SV*   device
	int   position
	OUTPUT:
		RETVAL

SV*
StopPlay ( device )
	SV*   device
	OUTPUT:
		RETVAL

SV*
PausePlay ( device )
	SV*   device
	OUTPUT:
		RETVAL

SV*
ResumePlay ( device )
	SV*   device
	OUTPUT:
		RETVAL

SV*
GetOwner ( device )
	SV * device
	OUTPUT:
		RETVAL

SV*
SetOwner ( device, owner )
	SV * device
	SV * owner
	OUTPUT:
		RETVAL

SV*
GetTmpDir ( device )
	SV * device
	OUTPUT:
		RETVAL

SV*
SetTmpDir ( device, dir )
	SV * device
	SV * dir
	OUTPUT:
		RETVAL

void
Close ( device )
	SV * device

AV*
DiskUsage ( device )
	SV*    device
	PPCODE:
	njb_t*     njb;
	HV*    info;
	u_int64_t   total=0, free=0;

	if (SvROK( device )) {
		device = SvRV( device );
	}

	njb = (njb_t*) SvIV( device );
	if ( !njb ) {
	    XSRETURN(0);
	}
	if (NJB_Get_Disk_Usage(njbs, &total, &free) == -1) {
		XSRETURN( 0 );
	}

	info = newHV();
	
	XPUSHs( newRV_noinc( (SV*) info ));
	hv_store (info, "TOTAL", 5, newSVnv( (NV) total ), 0);
	hv_store (info, "FREE", 4, newSVnv( (NV) free ), 0);

	XSRETURN( 1 );



( run in 0.809 second using v1.01-cache-2.11-cpan-5511b514fd6 )