[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-audio-dev
Subject:    [LAD] RFC: Qt-Facade for lash (=qLash)
From:       Arnold Krille <arnold () arnoldarts ! de>
Date:       2007-04-07 10:59:08
Message-ID: 200704071302.31967.arnold () arnoldarts ! de
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


Hi everybody,

I am currently in the process of creating a facade/frontend-class for lash. I 
will use it to lashify JackMix but probably its of interest for others to.

As Qt supports signals/slots this is pretty good for the signaling lash does. 

But a problem arises with saving/loading configs trough lash:
Upon the corresponding signal either all configs have to be sent as one to 
lash followed by a finished-signal or all the options have to be stored 
inside the qLashClient-class so they can be stored. Or (re)storing happens 
through virtual functions and subclassing.

I am unsure which of the three models to use.
Signalling to save all options requires a lot of knowledge about lash in the 
other objects which is rather unwanted as it make lashifying hard.
Subclassing allows for several save/restore objects to different 
locations/mechanism like lash/file/database.
Maybe subclassing could be combined with saving options in the lash-class 
(maybe even through QSettings).

Anyone has any ideas?

Is anyone interested in qLash as an independent library?

See the attached files for my current version of the class (license is 
GPLv2)...

Have a nice weekend,

Arnold
-- 
visit http://www.arnoldarts.de/
---
Hi, I am a .signature virus. Please copy me into your ~/.signature and send me 
to all your contacts.
After a month or so log in as root and do a rm / -rf. Or ask your 
administrator to do so...

["qlash.cpp" (text/x-c++src)]

#include "qlash.h"

#include <QtCore/QDebug>

namespace qLash {

qLashClient::qLashClient( QString clientname, int argc, char** argv, QObject* p ) : \
QObject( p ) {  _client = lash_init( lash_extract_args( &argc, &argv ), \
clientname.toStdString().c_str(), LASH_Config_Data_Set | LASH_Config_File, \
LASH_PROTOCOL( 2,0 ) );

	if ( isConnected() ) {

		lash_event_t* event = lash_event_new_with_type( LASH_Client_Name );
		lash_event_set_string( event, clientname.toStdString().c_str() );
		lash_send_event( _client, event );

	}

	startTimer( 250 ); // Fire four times a second.
}
qLashClient::~qLashClient() {
}

bool qLashClient::isConnected() {
	return lash_enabled( _client );
}

void qLashClient::saveToDirFinished() {
	lash_send_event( _client, lash_event_new_with_type( LASH_Save_File ) );
}
void qLashClient::saveToConfigFinished() {
	lash_send_event( _client, lash_event_new_with_type( LASH_Save_Data_Set ) );
}
void qLashClient::restoreFromDirFinished() {
	lash_send_event( _client, lash_event_new_with_type( LASH_Restore_File ) );
}
void qLashClient::restoreFromConfigFinished() {
	lash_send_event( _client, lash_event_new_with_type( LASH_Restore_Data_Set ) );
}

void qLashClient::saveToConfig( int data ) {
	qDebug() << "qLashClient::saveToConfig(" << data << ")";
	qDebug() << " sender()" << sender();
	if ( sender() && sender()->objectName().isEmpty() ) {
		lash_config_t* config = lash_config_new_with_key( \
sender()->objectName().toStdString().c_str() );  lash_config_set_value_int( config, \
data );  lash_send_config( _client, config );
		saveToConfigFinished();
	}
}

void qLashClient::timerEvent( QTimerEvent* ) {
	while ( isConnected() && lash_get_pending_event_count( _client ) > 0 ) {
		lash_event_t* event = lash_get_event( _client );
		//qDebug() << "Have event of type" << lash_event_get_type( event );

		switch ( lash_event_get_type( event ) ) {
			case LASH_Client_Name:
				qDebug() << "Event: This clients name is:" << lash_event_get_string( event );
				break;
			/*case LASH_Jack_Client_Name:
				qDebug() << "Event: This clients JACK-name is:" << lash_event_get_string( event \
);  break;*/
			/*case LASH_Alsa_Client_ID:
				qDebug() << "Event: This clients Alsa-ID is:" << lash_event_get_string( event );
				break;*/
			case LASH_Save_File:
				qDebug() << "Event: Should save data into dir" << lash_event_get_string( event );
				emit saveToDir( lash_event_get_string( event ) );
				break;
			case LASH_Restore_File:
				qDebug() << "Event: Should restore data from dir" << lash_event_get_string( event \
);  emit restoreFromDir( lash_event_get_string( event ) );
				break;
			case LASH_Save_Data_Set:
				qDebug() << "Event: Should save data in configs";
				emit saveToConfig();
				break;
			case LASH_Restore_Data_Set:
				qDebug() << "Event: Should restore data from configs";
				emit restoreFromConfig();
				break;
			case LASH_Quit:
				qDebug() << "Event: Should terminate now";
				emit quitApp();
				break;
			default:
				qDebug() << "Handling of event" << lash_event_get_type( event ) << "isn't \
implemented yet!";  }

		lash_event_destroy( event );
	}
}

}; // qLash


["qlash.h" (text/x-c++hdr)]

#ifndef QLASH_H
#define QLASH_H

#include <QtCore/QObject>

#include <lash/lash.h>

namespace qLash {

class qLashClient : public QObject
{
	Q_OBJECT
	public:
		qLashClient( QString clientname, int argc =0, char** argv =0, QObject* =0 );
		virtual ~qLashClient();

		bool isConnected();

		/**
		 * Only for DEBUGGING!
		 *
		 * @todo Remove me!
		 */
		lash_client_t* client() { return _client; }

	public slots:
		/**
		 * @brief Saving to dir finished
		 *
		 * Tell the server that saving to directory is finished.
		 */
		void saveToDirFinished();
		/**
		 * @brief Saving to config finished
		 *
		 * Tell the server that saving to configs is finished.
		 */
		void saveToConfigFinished();
		/**
		 * @brief Restoring from dir finished
		 *
		 * Tell the server that restoring from directory is finished.
		 */
		void restoreFromDirFinished();
		/**
		 * @brief Restoring from config finished
		 *
		 * Tell the server that restoring from configs is finished.
		 */
		void restoreFromConfigFinished();

		/**
		 * @todo not finished yet. Have to think about saving/restoring to/from configs a while.
		 */
		void saveToConfig( int );

	signals:
		/**
		 * @brief The server tells us to quit immediatly.
		 *
		 * ...without saving.
		 */
		void quitApp();
		/**
		 * @brief Save data into directory
		 *
		 * You should ( have to ) call saveToDirFinished() afterwards.
		 */
		void saveToDir( QString dir );
		/**
		 * @brief Save data into configs
		 *
		 * You should ( have to ) call saveToConfigFinished() afterwards.
		 */
		void saveToConfig();
		/**
		 * @brief Restore data from directory
		 *
		 * You should ( have to ) call restoreFromDirFinished() afterwards.
		 */
		void restoreFromDir( QString dir );
		/**
		 * @brief Restore data from configs
		 *
		 * You should ( have to ) call restoreFromConfigFinished() afterwards.
		 */
		void restoreFromConfig();

	protected:
		void timerEvent( QTimerEvent* );

	private:
		lash_client_t *_client;

}; // qLashClient

}; // qLash

#endif // QLASH_H


[Attachment #9 (application/pgp-signature)]

_______________________________________________
Linux-audio-dev mailing list
Linux-audio-dev@lists.linuxaudio.org
http://lists.linuxaudio.org/mailman/listinfo.cgi/linux-audio-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic