Frozen Document
[ 新規 | 差分 ] [ 検索 | 一覧 | FrontPage ] [ 履歴 (RSS) | 差分履歴 (RSS) ] [ ログイン ]
【PR】Amazon | SL-C3000 | SL-C1000(3/18発売!) | SL-C860 | SL-6000W | SL-6000L | SL-6000N

qcop2

qcopの機能拡張版

標準のqcopではパラメータのタイプとしてQStringとintしか受け付けてくれないので
とりあえずboolも受け付けられるようにしてみました。

変更履歴

qcop2 QPE/KeyHelper 'event(QString,int)' a 2 b 2 c 2 d 2

上記のような事ができるようになりました。

qcop QPE/KeyHelper 'event(QString,int)' a 2
qcop QPE/KeyHelper 'event(QString,int)' b 2
qcop QPE/KeyHelper 'event(QString,int)' c 2
qcop QPE/KeyHelper 'event(QString,int)' d 2

実行される内容は上記と同じですが毎回コマンド実行になってしまうため、非常に遅くなってしまうので拡張しました。

ダウンロード

パッケージングしました。
qcop2_0.1.0-1_arm.ipk

ほぼノーテストの人柱バージョンです。
とりあえず時間がなかったのでバイナリのみ。
qcop2_0.0.1.tar.gz


ご意見があればどうぞ。

あなたの名前:


ソース

main.cpp

#include <qpe/qcopenvelope_qws.h>

#include <qapplication.h>
#include <qstringlist.h>
#include <qdatastream.h>
#include <qtimer.h>

#include <stdlib.h>
#include <stdio.h>

static void usage()
{
    fprintf( stderr, "Usage: qcop channel command [parameters]\n" );
}

static void syntax( const QString &where, const QString &what )
{
    fprintf( stderr, "Syntax error in %s: %s\n", where.latin1(), what.latin1() );
    exit(1);
}

int main( int argc, char *argv[] )
{
    QApplication app( argc, argv );

    if ( argc < 3 ) {
    usage();
    exit(1);
    }

    QString channel = argv[1];
    QString command = argv[2];
    command.stripWhiteSpace();

    int paren = command.find( "(" );
    if ( paren <= 0 )
    syntax( "command", command );

    QString params = command.mid( paren + 1 );
    if ( params[params.length()-1] != ')' )
    syntax( "command", command );

    params.truncate( params.length()-1 );
    QStringList paramList = QStringList::split( ",", params );
    if(paramList.count() == 0){
        QCopEnvelope(channel.latin1(), command.latin1());
    } else {
        QCopEnvelope* env = NULL;
        QStringList::Iterator it = paramList.end();
        for(int argIdx=3; argIdx<argc; argIdx++){
            if(it == paramList.end()){
                if(argc - argIdx < paramList.count()){
                    break;
                }
                /* initialize */
                it = paramList.begin();
                env = new QCopEnvelope(channel.latin1(), command.latin1());
            }
            QString arg = argv[argIdx];
            if ( *it == "QString" ) {
                *env << arg;
            } else if ( *it == "int" ) {
                *env << arg.toInt();
            } else if ( *it == "bool") {
                *env << arg.toInt();
            } else {
                syntax( "paramter type", *it );
            }
            ++it;
            if(it == paramList.end()){
                /* send qcop message */
                delete env;
            }
        }
    }

    QTimer::singleShot( 0, &app, SLOT(quit()) );
    return app.exec();
}

06416