summaryrefslogtreecommitdiff
path: root/resourceqt-client
diff options
context:
space:
mode:
authorWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-18 12:52:29 +0200
committerWolf Bergenheim <ext-wolf.2.bergenheim@nokia.com>2010-02-18 12:52:29 +0200
commita36aef2b7c5128785a60213a6607191a8bfb1ecf (patch)
treeadd37ed9e8b7172dd5df4fab24a4333a0dd7116c /resourceqt-client
parentfdb67c341fcb9ea0ae29a7889227ded6ac66a362 (diff)
downloadlibresourceqt-a36aef2b7c5128785a60213a6607191a8bfb1ecf.tar.gz
astyled the code
Diffstat (limited to 'resourceqt-client')
-rw-r--r--resourceqt-client/client.cpp799
-rw-r--r--resourceqt-client/resourceqt-client.cpp362
2 files changed, 532 insertions, 629 deletions
diff --git a/resourceqt-client/client.cpp b/resourceqt-client/client.cpp
index c926ef0..1ac9519 100644
--- a/resourceqt-client/client.cpp
+++ b/resourceqt-client/client.cpp
@@ -9,39 +9,35 @@
Client::Client(QString appClass) : QObject()
{
- applicationClass = appClass;
- resourceSet = NULL;
+ applicationClass = appClass;
+ resourceSet = NULL;
standardInput = new QTextStream(stdin, QFile::ReadOnly);
- mainTimerID = startTimer(0);
+ mainTimerID = startTimer(0);
}
Client::~Client()
{
- killTimer(mainTimerID);
-
- if( resourceSet != NULL )
- {
- delete resourceSet;
- resourceSet = NULL;
- }
-
- if( standardInput != NULL )
- {
- delete standardInput;
- standardInput = NULL;
- }
+ killTimer(mainTimerID);
+
+ if (resourceSet != NULL) {
+ delete resourceSet;
+ resourceSet = NULL;
+ }
+
+ if (standardInput != NULL) {
+ delete standardInput;
+ standardInput = NULL;
+ }
}
uint32_t Client::parseResourceList(QString resourceListStr)
{
- struct
- {
- uint32_t resourceType;
- const char* resourceName;
+ struct {
+ uint32_t resourceType;
+ const char* resourceName;
}
- resourceDef[] =
- {
+ resourceDef[] = {
{ RES_AUDIO_PLAYBACK , "AudioPlayback" },
{ RES_VIDEO_PLAYBACK , "VideoPlayback" },
{ RES_AUDIO_RECORDING, "AudioRecording" },
@@ -59,33 +55,27 @@ uint32_t Client::parseResourceList(QString resourceListStr)
uint32_t resourceList = 0;
- if( resourceListStr.isEmpty() || resourceListStr.isNull() )
- {
+ if (resourceListStr.isEmpty() || resourceListStr.isNull()) {
return 0;
}
- else
- {
- QStringList resList = resourceListStr.split(",", QString::SkipEmptyParts);
-
- for( int i = 0; i < resList.count(); i++ )
- {
- int pos = 0;
- while( resourceDef[pos].resourceName != NULL )
- {
- if( resList[i] == resourceDef[pos].resourceName )
+ else {
+ QStringList resList = resourceListStr.split(",", QString::SkipEmptyParts);
+
+ for (int i = 0; i < resList.count(); i++) {
+ int pos = 0;
+ while (resourceDef[pos].resourceName != NULL) {
+ if (resList[i] == resourceDef[pos].resourceName)
break;
pos++;
}
- if( !resourceDef[pos].resourceName )
- {
- const char* res = qPrintable(resList[i]);
- printf("Ignoring invalid resource name '%s'\n", res);
+ if (!resourceDef[pos].resourceName) {
+ const char* res = qPrintable(resList[i]);
+ printf("Ignoring invalid resource name '%s'\n", res);
}
- else
- {
- resourceList |= resourceDef[pos].resourceType;
+ else {
+ resourceList |= resourceDef[pos].resourceType;
}
}
}
@@ -95,448 +85,383 @@ uint32_t Client::parseResourceList(QString resourceListStr)
void Client::showPrompt()
{
- printf("res-client> ");
- fflush(stdout);
+ printf("res-client> ");
+ fflush(stdout);
}
void Client::updateSet(uint32_t list, uint32_t optional, bool remove)
{
- uint32_t resources[] =
- {
- RES_AUDIO_PLAYBACK, RES_VIDEO_PLAYBACK, RES_AUDIO_RECORDING, RES_VIDEO_RECORDING,
- RES_VIBRA, RES_LEDS, RES_BACKLIGHT, RES_SYSTEM_BUTTON, RES_LOCK_BUTTON,
- RES_SCALE_BUTTON, RES_SNAP_BUTTON, RES_LENS_COVER, 0
- };
-
- int pos = 0;
- while( resources[pos] )
- {
- if( list & resources[pos] )
- {
- Resource* resource = NULL;
- ResourceType res = getResourceType(resources[pos]);
- bool opt = (optional & resources[pos]) == resources[pos];
-
- if( remove )
- {
- if( !resourceSet->contains(res) )
- {
- continue;
- }
-
- if( optional )
- {
- resource = resourceSet->resource(res);
- resource->setOptional(false);
- }
- else
- {
- resourceSet->deleteResource(res);
- }
- }
- else
- {
- if( resourceSet->contains(res) )
- {
- resource = resourceSet->resource(res);
- if( resource->isOptional() != opt )
- {
- resource->setOptional(opt);
- }
-
- continue;
- }
-
- resource = allocateResource(res, opt);
- if( resource )
- {
- resourceSet->addResource(resource);
- }
- }
- }
-
- pos++;
- }
+ uint32_t resources[] = {
+ RES_AUDIO_PLAYBACK, RES_VIDEO_PLAYBACK, RES_AUDIO_RECORDING, RES_VIDEO_RECORDING,
+ RES_VIBRA, RES_LEDS, RES_BACKLIGHT, RES_SYSTEM_BUTTON, RES_LOCK_BUTTON,
+ RES_SCALE_BUTTON, RES_SNAP_BUTTON, RES_LENS_COVER, 0
+ };
+
+ int pos = 0;
+ while (resources[pos]) {
+ if (list & resources[pos]) {
+ Resource* resource = NULL;
+ ResourceType res = getResourceType(resources[pos]);
+ bool opt = (optional & resources[pos]) == resources[pos];
+
+ if (remove) {
+ if (!resourceSet->contains(res)) {
+ continue;
+ }
+
+ if (optional) {
+ resource = resourceSet->resource(res);
+ resource->setOptional(false);
+ }
+ else {
+ resourceSet->deleteResource(res);
+ }
+ }
+ else {
+ if (resourceSet->contains(res)) {
+ resource = resourceSet->resource(res);
+ if (resource->isOptional() != opt) {
+ resource->setOptional(opt);
+ }
+
+ continue;
+ }
+
+ resource = allocateResource(res, opt);
+ if (resource) {
+ resourceSet->addResource(resource);
+ }
+ }
+ }
+
+ pos++;
+ }
}
bool Client::initialize(uint32_t all, uint32_t optional, bool alwaysReply, bool autoRelease)
{
- resourceSet = new ResourceSet(applicationClass);
- if( resourceSet == NULL )
- {
- return false;
- }
-
- if( alwaysReply )
- {
- qDebug("client: alwaysReply");
- resourceSet->setAlwaysReply();
- }
-
- if( autoRelease )
- {
- qDebug("client: autoRelease");
- resourceSet->setAutoRelease();
- }
-
- updateSet(all, optional, false);
-
- if( !connect(resourceSet, SIGNAL(resourcesGranted(QList<ResourceType>)), this, SLOT(resourceAcquiredHandler(QList<ResourceType>))) )
- {
- return false;
- }
-
- if( !connect(resourceSet, SIGNAL(resourcesDenied()), this, SLOT(resourceDeniedHandler())) )
- {
- return false;
- }
-
- if( !connect(resourceSet, SIGNAL(lostResources()), this, SLOT(resourceLostHandler())) )
- {
- return false;
- }
+ resourceSet = new ResourceSet(applicationClass);
+ if (resourceSet == NULL) {
+ return false;
+ }
+
+ if (alwaysReply) {
+ qDebug("client: alwaysReply");
+ resourceSet->setAlwaysReply();
+ }
+
+ if (autoRelease) {
+ qDebug("client: autoRelease");
+ resourceSet->setAutoRelease();
+ }
+
+ updateSet(all, optional, false);
+
+ if (!connect(resourceSet, SIGNAL(resourcesGranted(QList<ResourceType>)), this, SLOT(resourceAcquiredHandler(QList<ResourceType>)))) {
+ return false;
+ }
+
+ if (!connect(resourceSet, SIGNAL(resourcesDenied()), this, SLOT(resourceDeniedHandler()))) {
+ return false;
+ }
+
+ if (!connect(resourceSet, SIGNAL(lostResources()), this, SLOT(resourceLostHandler()))) {
+ return false;
+ }
connect(resourceSet, SIGNAL(resourcesReleased()), this, SLOT(resourceReleasedHandler()));
- showPrompt();
+ showPrompt();
- return true;
+ return true;
}
Resource* Client::allocateResource(ResourceType resource, bool optional)
{
- Resource* retValue = NULL;
-
- switch( resource )
- {
- case AudioPlaybackType:
- retValue = new AudioResource();
- break;
- case VideoPlaybackType:
- retValue = new VideoResource();
- break;
- case AudioRecorderType:
- retValue = new AudioRecorderResource();
- break;
- case VideoRecorderType:
- retValue = new VideoRecorderResource();
- break;
- case VibraType:
- retValue = new VibraResource();
- break;
- case LedsType:
- retValue = new LedsResource();
- break;
- case BacklightType:
- retValue = new BacklightResource();
- break;
- case SystemButtonType:
- retValue = new SystemButtonResource();
- break;
- case LockButtonType:
- retValue = new LockButtonResource();
- break;
- case ScaleButtonType:
- retValue = new ScaleButtonResource();
- break;
- case SnapButtonType:
- retValue = new SnapButtonResource();
- break;
- case LensCoverType:
- retValue = new LensCoverResource();
- break;
- case NumberOfTypes:
- return NULL;
- }
-
- if( retValue )
- {
- retValue->setOptional(optional);
- }
- else
- {
- printf("Unknown resource type - %d\n", resource);
- }
-
- return retValue;
+ Resource* retValue = NULL;
+
+ switch (resource) {
+ case AudioPlaybackType:
+ retValue = new AudioResource();
+ break;
+ case VideoPlaybackType:
+ retValue = new VideoResource();
+ break;
+ case AudioRecorderType:
+ retValue = new AudioRecorderResource();
+ break;
+ case VideoRecorderType:
+ retValue = new VideoRecorderResource();
+ break;
+ case VibraType:
+ retValue = new VibraResource();
+ break;
+ case LedsType:
+ retValue = new LedsResource();
+ break;
+ case BacklightType:
+ retValue = new BacklightResource();
+ break;
+ case SystemButtonType:
+ retValue = new SystemButtonResource();
+ break;
+ case LockButtonType:
+ retValue = new LockButtonResource();
+ break;
+ case ScaleButtonType:
+ retValue = new ScaleButtonResource();
+ break;
+ case SnapButtonType:
+ retValue = new SnapButtonResource();
+ break;
+ case LensCoverType:
+ retValue = new LensCoverResource();
+ break;
+ case NumberOfTypes:
+ return NULL;
+ }
+
+ if (retValue) {
+ retValue->setOptional(optional);
+ }
+ else {
+ printf("Unknown resource type - %d\n", resource);
+ }
+
+ return retValue;
}
ResourceType Client::getResourceType(uint32_t resource)
{
- switch( resource )
- {
- case RES_AUDIO_PLAYBACK:
- return AudioPlaybackType;
- case RES_VIDEO_PLAYBACK:
- return VideoPlaybackType;
- case RES_AUDIO_RECORDING:
- return AudioRecorderType;
- case RES_VIDEO_RECORDING:
- return VideoRecorderType;
- case RES_VIBRA:
- return VibraType;
- case RES_LEDS:
- return LedsType;
- case RES_BACKLIGHT:
- return BacklightType;
- case RES_SYSTEM_BUTTON:
- return SystemButtonType;
- case RES_LOCK_BUTTON:
- return LockButtonType;
- case RES_SCALE_BUTTON:
- return ScaleButtonType;
- case RES_SNAP_BUTTON:
- return SnapButtonType;
- case RES_LENS_COVER:
- return LensCoverType;
- }
-
- return NumberOfTypes;
+ switch (resource) {
+ case RES_AUDIO_PLAYBACK:
+ return AudioPlaybackType;
+ case RES_VIDEO_PLAYBACK:
+ return VideoPlaybackType;
+ case RES_AUDIO_RECORDING:
+ return AudioRecorderType;
+ case RES_VIDEO_RECORDING:
+ return VideoRecorderType;
+ case RES_VIBRA:
+ return VibraType;
+ case RES_LEDS:
+ return LedsType;
+ case RES_BACKLIGHT:
+ return BacklightType;
+ case RES_SYSTEM_BUTTON:
+ return SystemButtonType;
+ case RES_LOCK_BUTTON:
+ return LockButtonType;
+ case RES_SCALE_BUTTON:
+ return ScaleButtonType;
+ case RES_SNAP_BUTTON:
+ return SnapButtonType;
+ case RES_LENS_COVER:
+ return LensCoverType;
+ }
+
+ return NumberOfTypes;
}
void Client::showResources(const QList<ResourceType> resList)
{
- const char* resTypes[] =
- {
- "AudioPlayback", "VideoPlayback", "AudioRecorder", "VideoRecorder", "Vibra",
- "Leds", "Backlight", "SystemButton", "LockButton", "ScaleButton", "SnapButton",
- "LensCover"
- };
-
- for( int i = 0; i < resList.count(); i++ )
- {
- printf("\t%s\n", resTypes[resList[i]]);
- }
+ const char* resTypes[] = {
+ "AudioPlayback", "VideoPlayback", "AudioRecorder", "VideoRecorder", "Vibra",
+ "Leds", "Backlight", "SystemButton", "LockButton", "ScaleButton", "SnapButton",
+ "LensCover"
+ };
+
+ for (int i = 0; i < resList.count(); i++) {
+ printf("\t%s\n", resTypes[resList[i]]);
+ }
}
void Client::showResources(const QList<Resource*> resList)
{
- const char* resTypes[] =
- {
- "AudioPlayback", "VideoPlayback", "AudioRecorder", "VideoRecorder", "Vibra",
- "Leds", "Backlight", "SystemButton", "LockButton", "ScaleButton", "SnapButton",
- "LensCover"
- };
-
- for( int i = 0; i < resList.count(); i++ )
- {
- Resource* r = resList[i];
- printf("\t%s%s%s\n", resTypes[r->type()],
- r->isOptional() ? " (optional)" : "",
- r->isGranted() ? " (granted)" : "");
- }
+ const char* resTypes[] = {
+ "AudioPlayback", "VideoPlayback", "AudioRecorder", "VideoRecorder", "Vibra",
+ "Leds", "Backlight", "SystemButton", "LockButton", "ScaleButton", "SnapButton",
+ "LensCover"
+ };
+
+ for (int i = 0; i < resList.count(); i++) {
+ Resource* r = resList[i];
+ printf("\t%s%s%s\n", resTypes[r->type()],
+ r->isOptional() ? " (optional)" : "",
+ r->isGranted() ? " (granted)" : "");
+ }
}
void Client::resourceAcquiredHandler(const QList<ResourceType>& /*grantedResList*/)
{
- QList<Resource*> list = resourceSet->resources();
- if( !list.count() )
- {
- printf("\nGranted resource set is empty. Possible bug?\n");
- }
- else
- {
- printf("\nManager grants access to these resources:\n");
- printf("Resource set:\n");
- showResources(list);
- }
- showPrompt();
+ QList<Resource*> list = resourceSet->resources();
+ if (!list.count()) {
+ printf("\nGranted resource set is empty. Possible bug?\n");
+ }
+ else {
+ printf("\nManager grants access to these resources:\n");
+ printf("Resource set:\n");
+ showResources(list);
+ }
+ showPrompt();
}
void Client::resourceDeniedHandler()
{
- printf("\nManager denies access to resources!\n");
- showPrompt();
+ printf("\nManager denies access to resources!\n");
+ showPrompt();
}
void Client::resourceLostHandler()
{
- printf("\nLost resources from manager!\n");
- showPrompt();
+ printf("\nLost resources from manager!\n");
+ showPrompt();
}
void Client::resourceReleasedHandler()
{
- printf("\nAll resources released\n");
- showPrompt();
+ printf("\nAll resources released\n");
+ showPrompt();
}
void Client::timerEvent(QTimerEvent*)
{
- bool quitFlag = false;
-
- fd_set stdinfd;
- FD_ZERO(&stdinfd);
- FD_SET(0, &stdinfd);
- timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
-
- int ready = select(1, &stdinfd, NULL, NULL, &tv);
- if( ready > 0 )
- {
- QString line = standardInput->readLine();
- if( !line.isNull() )
- {
- QStringList params = line.split(" ");
- if( params[0] == "quit" )
- {
- quitFlag = true;
- QMetaObject::invokeMethod(QCoreApplication::instance(), "quit");
- }
- else if( params[0] == "help" )
- {
- printf("Available commands:\n");
- printf("\t help \tprint this help message\n");
- printf("\t quit \texit application\n");
- printf("\t acquire\tacquire required resources\n");
- printf("\t release\trelease resources\n");
- printf("\t update\tupdate modified resource set after add or remove command\n");
- printf("\t add reslist [-o]\tadd reosurce list, if -o provided, set as optional\n");
- printf("\t remove reslist [-o]\tremove reosurce list, if -o provided, removed only optional flag\n");
- printf("\t audio pid <pid>|group <audio group>|tag <name:value>\tset audio properties");
- printf("\t show \tshow resources\n");
- }
- else if( params[0] == "show" )
- {
- if( !resourceSet )
- {
- printf("Show failed!\n");
- }
- else
- {
- QList<Resource*> list = resourceSet->resources();
- if( !list.count() )
- {
- printf("Resource set is empty, use add command to add some ...\n");
- }
- else
- {
- printf("Resource set:\n");
- showResources(list);
- }
- }
- }
- else if( params[0] == "acquire" )
- {
- if( !resourceSet || !resourceSet->acquire() )
- {
- printf("Acquire failed!\n");
- }
- }
- else if( params[0] == "release" )
- {
- if( !resourceSet || !resourceSet->release() )
- {
- printf("Release failed!\n");
- }
- }
- else if( params[0] == "add" )
- {
- if( !resourceSet )
- {
- printf("Update failed!\n");
- }
- else if( params.count() == 1 || params[1].isEmpty() || params[1].isNull() )
- {
- printf("List of desired resources is missing. See help ...\n");
- }
- else
- {
- uint32_t temp = Client::parseResourceList(params[1]);
- if( params.count() > 2 && params[2] == "-o" )
- {
- updateSet(temp, temp, false);
- }
- else
- {
- updateSet(temp, 0, false);
- }
- }
- }
- else if( params[0] == "remove" )
- {
- if( !resourceSet || params.count() == 1 )
- {
- printf("Update failed!\n");
- }
- else if( params.count() == 1 || params[1].isEmpty() || params[1].isNull() )
- {
- printf("List of desired resources is missing. See help ...\n");
- }
- else
- {
- uint32_t temp = Client::parseResourceList(params[1]);
- if( params.count() > 2 && params[2] == "-o" )
- {
- updateSet(temp, temp, true);
- }
- else
- {
- updateSet(temp, 0, true);
- }
- }
- }
- else if( params[0] == "update" )
- {
- if( !resourceSet || !resourceSet->update() )
- {
- printf("Update failed!\n");
- }
- }
- else if( params[0] == "audio" )
- {
- if( params.count() < 3 )
- {
- printf("Not enough parameters! See help!\n");
- }
- else
- {
- Resource *resource = resourceSet->resource(AudioPlaybackType);
- AudioResource *audioResource = static_cast<AudioResource*>(resource);
+ bool quitFlag = false;
+
+ fd_set stdinfd;
+ FD_ZERO(&stdinfd);
+ FD_SET(0, &stdinfd);
+ timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ int ready = select(1, &stdinfd, NULL, NULL, &tv);
+ if (ready > 0) {
+ QString line = standardInput->readLine();
+ if (!line.isNull()) {
+ QStringList params = line.split(" ");
+ if (params[0] == "quit") {
+ quitFlag = true;
+ QMetaObject::invokeMethod(QCoreApplication::instance(), "quit");
+ }
+ else if (params[0] == "help") {
+ printf("Available commands:\n");
+ printf("\t help \tprint this help message\n");
+ printf("\t quit \texit application\n");
+ printf("\t acquire\tacquire required resources\n");
+ printf("\t release\trelease resources\n");
+ printf("\t update\tupdate modified resource set after add or remove command\n");
+ printf("\t add reslist [-o]\tadd reosurce list, if -o provided, set as optional\n");
+ printf("\t remove reslist [-o]\tremove reosurce list, if -o provided, removed only optional flag\n");
+ printf("\t audio pid <pid>|group <audio group>|tag <name:value>\tset audio properties");
+ printf("\t show \tshow resources\n");
+ }
+ else if (params[0] == "show") {
+ if (!resourceSet) {
+ printf("Show failed!\n");
+ }
+ else {
+ QList<Resource*> list = resourceSet->resources();
+ if (!list.count()) {
+ printf("Resource set is empty, use add command to add some ...\n");
+ }
+ else {
+ printf("Resource set:\n");
+ showResources(list);
+ }
+ }
+ }
+ else if (params[0] == "acquire") {
+ if (!resourceSet || !resourceSet->acquire()) {
+ printf("Acquire failed!\n");
+ }
+ }
+ else if (params[0] == "release") {
+ if (!resourceSet || !resourceSet->release()) {
+ printf("Release failed!\n");
+ }
+ }
+ else if (params[0] == "add") {
+ if (!resourceSet) {
+ printf("Update failed!\n");
+ }
+ else if (params.count() == 1 || params[1].isEmpty() || params[1].isNull()) {
+ printf("List of desired resources is missing. See help ...\n");
+ }
+ else {
+ uint32_t temp = Client::parseResourceList(params[1]);
+ if (params.count() > 2 && params[2] == "-o") {
+ updateSet(temp, temp, false);
+ }
+ else {
+ updateSet(temp, 0, false);
+ }
+ }
+ }
+ else if (params[0] == "remove") {
+ if (!resourceSet || params.count() == 1) {
+ printf("Update failed!\n");
+ }
+ else if (params.count() == 1 || params[1].isEmpty() || params[1].isNull()) {
+ printf("List of desired resources is missing. See help ...\n");
+ }
+ else {
+ uint32_t temp = Client::parseResourceList(params[1]);
+ if (params.count() > 2 && params[2] == "-o") {
+ updateSet(temp, temp, true);
+ }
+ else {
+ updateSet(temp, 0, true);
+ }
+ }
+ }
+ else if (params[0] == "update") {
+ if (!resourceSet || !resourceSet->update()) {
+ printf("Update failed!\n");
+ }
+ }
+ else if (params[0] == "audio") {
+ if (params.count() < 3) {
+ printf("Not enough parameters! See help!\n");
+ }
+ else {
+ Resource *resource = resourceSet->resource(AudioPlaybackType);
+ AudioResource *audioResource = static_cast<AudioResource*>(resource);
qDebug("resource = %p audioResource = %p", resource, audioResource);
- if( audioResource == NULL )
- {
- printf("No AudioResource available in set!\n");
- }
- else
- {
- if( params[1] == "group" )
- {
- audioResource->setAudioGroup(params[2]);
- }
- else if( params[1] == "pid" )
- {
- bool ok;
- quint32 pid = (quint32)params[2].toInt(&ok, 10);
- if( ok && pid != 0 )
- {
- audioResource->setProcessID(pid);
- }
- else
- {
- printf("Bad pid parameter!\n");
- }
- }
- else if( params[1] == "tag" ) {
- audioResource->setStreamTag(params[2]);
- }
- else {
- printf("Unknown audio command!\n");
- }
- }
- }
- }
- else if( !params[0].isEmpty() )
- {
- QByteArray ba = line.toLatin1();
- const char *c_line = ba.data();
- printf("unknown command '%s'\n", c_line);
- }
-
- if( !quitFlag )
- {
- showPrompt();
- }
- }
- }
+ if (audioResource == NULL) {
+ printf("No AudioResource available in set!\n");
+ }
+ else {
+ if (params[1] == "group") {
+ audioResource->setAudioGroup(params[2]);
+ }
+ else if (params[1] == "pid") {
+ bool ok;
+ quint32 pid = (quint32)params[2].toInt(&ok, 10);
+ if (ok && pid != 0) {
+ audioResource->setProcessID(pid);
+ }
+ else {
+ printf("Bad pid parameter!\n");
+ }
+ }
+ else if (params[1] == "tag") {
+ audioResource->setStreamTag(params[2]);
+ }
+ else {
+ printf("Unknown audio command!\n");
+ }
+ }
+ }
+ }
+ else if (!params[0].isEmpty()) {
+ QByteArray ba = line.toLatin1();
+ const char *c_line = ba.data();
+ printf("unknown command '%s'\n", c_line);
+ }
+
+ if (!quitFlag) {
+ showPrompt();
+ }
+ }
+ }
}
diff --git a/resourceqt-client/resourceqt-client.cpp b/resourceqt-client/resourceqt-client.cpp
index 89aef76..49fa323 100644
--- a/resourceqt-client/resourceqt-client.cpp
+++ b/resourceqt-client/resourceqt-client.cpp
@@ -10,221 +10,199 @@
class CommandLineParser
{
public:
- CommandLineParser(int argc, char** argv)
- {
- exitCode = 0;
- exitFlag = false;
- exeName = strdup(basename(argv[0]));
-
- resourcesAll = 0;
- resourcesOptional = 0;
- autoRelease = false;
- alwaysReply = false;
-
- parseArguments(argc, argv);
- }
-
- ~CommandLineParser()
- {
- if( exeName != NULL )
- {
- delete exeName;
- exeName = NULL;
- }
- }
+ CommandLineParser(int argc, char** argv) {
+ exitCode = 0;
+ exitFlag = false;
+ exeName = strdup(basename(argv[0]));
+
+ resourcesAll = 0;
+ resourcesOptional = 0;
+ autoRelease = false;
+ alwaysReply = false;
+
+ parseArguments(argc, argv);
+ }
+
+ ~CommandLineParser() {
+ if (exeName != NULL) {
+ delete exeName;
+ exeName = NULL;
+ }
+ }
public:
- bool exitFlag;
- int exitCode;
+ bool exitFlag;
+ int exitCode;
- uint32_t resourcesAll;
- uint32_t resourcesOptional;
- QString applicationClass;
- bool autoRelease;
- bool alwaysReply;
+ uint32_t resourcesAll;
+ uint32_t resourcesOptional;
+ QString applicationClass;
+ bool autoRelease;
+ bool alwaysReply;
- void printMessage(const char *fmt, ...)
- {
- va_list ap;
- char fmtbuf[512];
+ void printMessage(const char *fmt, ...) {
+ va_list ap;
+ char fmtbuf[512];
snprintf(fmtbuf, sizeof(fmtbuf), "%s\n", fmt);
- va_start(ap, fmt);
- vprintf(fmtbuf, ap);
- va_end(ap);
- }
+ va_start(ap, fmt);
+ vprintf(fmtbuf, ap);
+ va_end(ap);
+ }
private:
- char* exeName;
+ char* exeName;
- void printError(const char *fmt, ...)
- {
- va_list ap;
- char fmtbuf[512];
+ void printError(const char *fmt, ...) {
+ va_list ap;
+ char fmtbuf[512];
snprintf(fmtbuf, sizeof(fmtbuf), "%s\n", fmt);
- va_start(ap, fmt);
- vprintf(fmtbuf, ap);
- va_end(ap);
-
- exitCode = errno;
- exitFlag = true;
- }
-
- void parseArguments(int argc, char** argv)
- {
- int option;
-
- while( (option = getopt(argc, argv, "hm:o:")) != -1 )
- {
- switch (option)
- {
- case 'h':
- usage(0);
- return;
- case 'm':
- parseModeValues(optarg);
- break;
- case 'o':
- resourcesOptional = Client::parseResourceList(optarg);
- break;
- default:
- usage(EINVAL);
- return;
- }
- }
-
- if( (optind != argc - 2) && (optind != argc - 1) )
- {
- usage(EINVAL);
- return;
- }
- else
- {
- applicationClass = parseClassString(argv[optind]);
- if( argc > optind + 1 )
- resourcesAll = Client::parseResourceList(argv[optind+1]);
- else
- resourcesAll = 0;
- }
-
- if( !resourcesAll )
- {
- printMessage("No resources found, use add command to add some ...");
- }
-
- if( (resourcesAll | resourcesOptional) != resourcesAll )
- {
- printError("optional resources are not subset of all resources");
- }
- }
-
- char* parseClassString(char *str)
- {
- if( strcmp(str, "call" ) &&
- strcmp(str, "camera" ) &&
- strcmp(str, "ringtone" ) &&
- strcmp(str, "alarm" ) &&
- strcmp(str, "navigator" ) &&
- strcmp(str, "game" ) &&
- strcmp(str, "player" ) &&
- strcmp(str, "event" ) &&
- strcmp(str, "background") )
- {
- printError("invalid class '%s'", str);
- return NULL;
- }
-
- return str;
- }
-
- void parseModeValues(QString modeListStr)
- {
- if( !modeListStr.isEmpty() && !modeListStr.isNull() )
- {
- QStringList modeList = modeListStr.split(",", QString::SkipEmptyParts);
-
- for( int i = 0; i < modeList.count(); i++ )
- {
- if( modeList[i] == "AutoRelease" )
- {
- autoRelease = true;
+ va_start(ap, fmt);
+ vprintf(fmtbuf, ap);
+ va_end(ap);
+
+ exitCode = errno;
+ exitFlag = true;
+ }
+
+ void parseArguments(int argc, char** argv) {
+ int option;
+
+ while ((option = getopt(argc, argv, "hm:o:")) != -1) {
+ switch (option) {
+ case 'h':
+ usage(0);
+ return;
+ case 'm':
+ parseModeValues(optarg);
+ break;
+ case 'o':
+ resourcesOptional = Client::parseResourceList(optarg);
+ break;
+ default:
+ usage(EINVAL);
+ return;
+ }
+ }
+
+ if ((optind != argc - 2) && (optind != argc - 1)) {
+ usage(EINVAL);
+ return;
+ }
+ else {
+ applicationClass = parseClassString(argv[optind]);
+ if (argc > optind + 1)
+ resourcesAll = Client::parseResourceList(argv[optind+1]);
+ else
+ resourcesAll = 0;
+ }
+
+ if (!resourcesAll) {
+ printMessage("No resources found, use add command to add some ...");
+ }
+
+ if ((resourcesAll | resourcesOptional) != resourcesAll) {
+ printError("optional resources are not subset of all resources");
+ }
+ }
+
+ char* parseClassString(char *str) {
+ if (strcmp(str, "call") &&
+ strcmp(str, "camera") &&
+ strcmp(str, "ringtone") &&
+ strcmp(str, "alarm") &&
+ strcmp(str, "navigator") &&
+ strcmp(str, "game") &&
+ strcmp(str, "player") &&
+ strcmp(str, "event") &&
+ strcmp(str, "background")) {
+ printError("invalid class '%s'", str);
+ return NULL;
+ }
+
+ return str;
+ }
+
+ void parseModeValues(QString modeListStr) {
+ if (!modeListStr.isEmpty() && !modeListStr.isNull()) {
+ QStringList modeList = modeListStr.split(",", QString::SkipEmptyParts);
+
+ for (int i = 0; i < modeList.count(); i++) {
+ if (modeList[i] == "AutoRelease") {
+ autoRelease = true;
}
- else if( modeList[i] == "AlwaysReply" )
- {
- alwaysReply = true;
+ else if (modeList[i] == "AlwaysReply") {
+ alwaysReply = true;
}
- else
- {
- const char* mode = qPrintable(modeList[i]);
- printMessage("Ignoring unknown mode '%s'!", mode);
+ else {
+ const char* mode = qPrintable(modeList[i]);
+ printMessage("Ignoring unknown mode '%s'!", mode);
}
- }
- }
- }
-
- void usage(int theExitCode)
- {
- printf("usage: %s [-h] [-t] [-v] [-m mode-values]"
- "[-o optional-resources] [-s shared-resources -m shared-mask] "
- "class all-resources\n",
- exeName);
- printf("\toptions:\n");
- printf("\t h\tprint this help message and exit\n");
- printf("\t m\tmode values. See 'modes' below for the "
- "\n\t\tsyntax of <mode-values>\n");
- printf("\t o\toptional resources. See 'resources' below for the "
- "syntax of\n\t\t<optional-resources>\n");
- printf("\tclass:\n");
- printf("\t\tcall\t - for native or 3rd party telephony\n");
- printf("\t\tcamera\t - for photo applications\n");
- printf("\t\tringtone - for ringtones\n");
- printf("\t\talarm\t - for alarm clock\n");
- printf("\t\tnavigator - for mapping applications\n");
- printf("\t\tgame\t - for gaming\n");
- printf("\t\tplayer\t - for media playback/recording\n");
- printf("\t\tevent\t - for messaging and other event notifications\n");
- printf("\t\tbackground - for thumbnailing etc\n");
- printf("\tresources:\n");
- printf("\t comma separated list of the following resources\n");
- printf("\t\tAudioPlayback\n");
- printf("\t\tVideoPlayback\n");
- printf("\t\tAudioRecording\n");
- printf("\t\tVideoRecording\n");
- printf("\t\tVibra\n");
- printf("\t\tLeds\n");
- printf("\t\tBackLight\n");
- printf("\t\tSystemButton\n");
- printf("\t\tLockButton\n");
- printf("\t\tScaleButton\n");
- printf("\t\tSnapButton\n");
- printf("\t\tLensCover\n");
- printf("\t no whitespace allowed in the resource list.\n");
- printf("\tmodes:\n");
- printf("\t comma separated list of the following modes\n");
- printf("\t\tAutoRelease\n");
- printf("\t\tAlwaysReply\n");
- fflush(stdout);
-
- exitCode = theExitCode;
- exitFlag = true;
- }
+ }
+ }
+ }
+
+ void usage(int theExitCode) {
+ printf("usage: %s [-h] [-t] [-v] [-m mode-values]"
+ "[-o optional-resources] [-s shared-resources -m shared-mask] "
+ "class all-resources\n",
+ exeName);
+ printf("\toptions:\n");
+ printf("\t h\tprint this help message and exit\n");
+ printf("\t m\tmode values. See 'modes' below for the "
+ "\n\t\tsyntax of <mode-values>\n");
+ printf("\t o\toptional resources. See 'resources' below for the "
+ "syntax of\n\t\t<optional-resources>\n");
+ printf("\tclass:\n");
+ printf("\t\tcall\t - for native or 3rd party telephony\n");
+ printf("\t\tcamera\t - for photo applications\n");
+ printf("\t\tringtone - for ringtones\n");
+ printf("\t\talarm\t - for alarm clock\n");
+ printf("\t\tnavigator - for mapping applications\n");
+ printf("\t\tgame\t - for gaming\n");
+ printf("\t\tplayer\t - for media playback/recording\n");
+ printf("\t\tevent\t - for messaging and other event notifications\n");
+ printf("\t\tbackground - for thumbnailing etc\n");
+ printf("\tresources:\n");
+ printf("\t comma separated list of the following resources\n");
+ printf("\t\tAudioPlayback\n");
+ printf("\t\tVideoPlayback\n");
+ printf("\t\tAudioRecording\n");
+ printf("\t\tVideoRecording\n");
+ printf("\t\tVibra\n");
+ printf("\t\tLeds\n");
+ printf("\t\tBackLight\n");
+ printf("\t\tSystemButton\n");
+ printf("\t\tLockButton\n");
+ printf("\t\tScaleButton\n");
+ printf("\t\tSnapButton\n");
+ printf("\t\tLensCover\n");
+ printf("\t no whitespace allowed in the resource list.\n");
+ printf("\tmodes:\n");
+ printf("\t comma separated list of the following modes\n");
+ printf("\t\tAutoRelease\n");
+ printf("\t\tAlwaysReply\n");
+ fflush(stdout);
+
+ exitCode = theExitCode;
+ exitFlag = true;
+ }
};
int main(int argc, char *argv[])
{
- CommandLineParser parser(argc, argv);
+ CommandLineParser parser(argc, argv);
- if( parser.exitFlag )
- return parser.exitCode;
+ if (parser.exitFlag)
+ return parser.exitCode;
QCoreApplication app(argc, argv);
Client client(parser.applicationClass);
- if( !client.initialize(parser.resourcesAll, parser.resourcesOptional, parser.alwaysReply, parser.autoRelease) )
- {
- parser.printMessage("initialization failed!");
- return EINVAL;
+ if (!client.initialize(parser.resourcesAll, parser.resourcesOptional, parser.alwaysReply, parser.autoRelease)) {
+ parser.printMessage("initialization failed!");
+ return EINVAL;
}
return app.exec();