Example #1
0
bool KviXmmsInterface::playMrl(const QString &mrl)
{
	void (*sym)(int,char *) = (void (*)(int,char *))lookupSymbol("xmms_remote_playlist_add_url_string");
	QByteArray tmp = mrl.toLocal8Bit();
	if(!tmp.isEmpty())
	{
		if(sym)
		{
			sym(0,tmp.data());
			int (*sym1)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_length");
			if(sym1)
			{
				int len = sym1(0);
				if(len > 0)
				{
					void (*sym2)(int,int) = (void (*)(int,int))lookupSymbol("xmms_remote_set_playlist_pos");
					if(sym2)
					{
						sym2(0,len - 1);
					} else return false;
				} else return false;
			} else return false;
		} else return false;
	}
	return true;
}
Example #2
0
// test the API for C++ intuitiveness, example of use.
bool testAPI() {
	bool passed = true;
	passed &= symbol::validate("");
	passed &= symbol::validate("0");
	passed &= symbol::validate("testing");
	passed &= !symbol::validate("help!");
	passed &= !symbol::validate("save me");

	uint64_t code = symbol::encode("Test").code();
	// test decode(uint64_t) override
	std::string identifier = symbol::decode(code); 
	passed &= (identifier == "Test");

	// test implicit and explicit construction from unsigned long
	passed &= symbol::Symbol(code) > 0; 
	
	symbol::Symbol sym("Testing");
	std::string name;
	name = sym; // implicit conversion from Symbol to string
	passed &= (name == "Testing");

	// test decode(Symbol) override
	name = symbol::decode(sym); 
	passed &= (name == "Testing");

	// standard output operator
	std::stringstream ss;
	ss << sym; 
	passed &= (ss.str() == "Testing");

	// test copy constructor... and setup for comparison operators.
	symbol::Symbol sym2(sym);

	// comparison operators.
	symbol::Symbol sym3("thisIsARatherLongSymbol");
	passed &= (sym == sym);
	passed &= !(sym != sym);
	passed &= (sym <= sym);
	passed &= (sym >= sym);

	passed &= (sym == sym2);
	passed &= (sym <= sym2);
	passed &= (sym >= sym2);

	passed &=  (sym  != sym3);
	passed &= !(sym  == sym3);
	passed &=  (sym  <  sym3);
	passed &= !(sym  >  sym3);
	passed &=  (sym3 >  sym );
	passed &= !(sym3 <  sym );
	
	// we don't need detailed error reporting here. If this test compiles 
	// it's unlikely to fail at runtime.
	if ( !passed ) {
		std::cout << "failed basic API usage test." << std::endl;
	}

	return passed;
}
Example #3
0
int KviXmmsInterface::length()
{
	int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos");
	if(!sym)return -1;
	int pos = sym(0);
	int (*sym2)(int,int) = (int (*)(int,int))lookupSymbol("xmms_remote_get_playlist_time");
	if(!sym2)return -1;
	return sym2(0,pos);
}
Example #4
0
QString KviXmmsInterface::nowPlaying()
{
	int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos");
	if(!sym)return QString();
	int pos = sym(0);
	char * (*sym2)(int,int) = (char * (*)(int,int))lookupSymbol("xmms_remote_get_playlist_title");
	if(!sym2)return QString();
	return QString::fromLocal8Bit(sym2(0,pos));
}
Example #5
0
QString KviXmmsInterface::mrl()
{
	int (*sym)(int) = (int (*)(int))lookupSymbol("xmms_remote_get_playlist_pos");
	if(!sym)return QString();
	int pos = sym(0);
	char * (*sym2)(int,int) = (char * (*)(int,int))lookupSymbol("xmms_remote_get_playlist_file");
	if(!sym2)return QString();
	QString ret = QString::fromLocal8Bit(sym2(0,pos));
	if(ret.length() > 1)
		if(ret[0] == '/')ret.prepend("file://");
	return ret;
}
Example #6
0
bool KviXmmsInterface::setShuffle(bool &bVal)
{
	bool (*sym1)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_shuffle");
	if(!sym1)return false;
	bool bNow = sym1(0);
	if(bNow != bVal)
	{
		void (*sym2)(int) = (void (*)(int))lookupSymbol("xmms_remote_toggle_shuffle");
		if(!sym2)return false;
		sym2(0);
	}
	return true;
}
Example #7
0
MpInterface::PlayerStatus KviXmmsInterface::status()
{
	bool (*sym1)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_paused");
	if(sym1)
	{
		if(sym1(0))return MpInterface::Paused;
		bool (*sym2)(int) = (bool (*)(int))lookupSymbol("xmms_remote_is_playing");
		if(sym2)
		{
			if(sym2(0))return MpInterface::Playing;
			else return MpInterface::Stopped;
		}
	}

	return MpInterface::Unknown;
}
Example #8
0
bool testLossy(const std::string& identifier) {
	symbol::Symbol sym1(identifier);
	symbol::Symbol sym2(identifier);

	// make sure it's consistent (non-random)
	if ( sym1 != sym2 ) {
		std::cout << "unreliable encoding of " << identifier << std::endl;
		return false;
	}

	// make sure high bit was set
	static const unsigned long HIGH_BIT = (1UL << 63);
	static const unsigned long PENULTIMATE_BIT = (1UL << 62);
	if ( (sym1.code() & HIGH_BIT ) != HIGH_BIT ) {
		std::cout << "high bit of encoded " << identifier << " -> " << sym1.code() << " not set" << std::endl;
		return false;
	}

	if ( sym1.code() & PENULTIMATE_BIT ) {
		std::cout << "second-highest of encoded " << identifier << " -> " << sym1.code() << " is set" << std::endl;
		return false;
	}

	if ( !sym1.is_lossy() ) {
		std::cout << "symbol " << identifier << " does not self-report as lossy." << std::endl;
	}

	if ( verbose ) {
		std::cout << "lossy encoding: " << identifier << " -> " << sym1.code() << " -> " << sym1.decode() << std::endl;
	}

	// passed!
	if ( verbose ) {
		std::cout << "reliably encoded long identifier " << identifier << " as " << sym1.code() << std::endl;
	}
	return true;
}