#include "CommandExecutor.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <image.h>
#include "ShortcutsFilterConstants.h"
#include "CommandActuators.h"
CommandExecutor::CommandExecutor()
:
BLooper("Shortcuts commands executor")
{
}
CommandExecutor::~CommandExecutor()
{
}
bool
CommandExecutor::GetNextWord(char** setBegin, char** setEnd) const
{
char* next = *setEnd;
while (next++) {
if (*next == '\0')
return false;
else if (*next <= ' ')
*next = '\0';
else
break;
}
*setBegin = next;
while (next++) {
if (*next <= ' ') {
*next = '\0';
*setEnd = next;
return true;
}
}
return false;
}
void
CommandExecutor::MessageReceived(BMessage* message)
{
switch(message->what) {
case B_UNMAPPED_KEY_DOWN:
case B_KEY_DOWN:
{
BMessage actuatorMessage;
void* asyncData;
if ((message->FindMessage("act", &actuatorMessage) == B_OK)
&& (message->FindPointer("adata", &asyncData) == B_OK)) {
BArchivable* archivedObject
= instantiate_object(&actuatorMessage);
if (archivedObject != NULL) {
CommandActuator* actuator
= dynamic_cast<CommandActuator*>(archivedObject);
if (actuator)
actuator->KeyEventAsync(message, asyncData);
delete archivedObject;
}
}
break;
}
}
}