Example #1
0
UnitTests::TestList UnitTests::selectPackage (
    String const& package, TestList const& tests) const noexcept
{
    TestList list;
    list.ensureStorageAllocated (tests.size ());
    for (int i = 0; i < tests.size(); ++i)
    {
        UnitTest* const test = tests [i];
        if (package.equalsIgnoreCase (test->getPackageName ()) &&
            test->getWhen () != UnitTest::runManual)
            list.add (test);
    }
    return list;
}
Example #2
0
void GM862::deleteMessage(String index){
    char buf[BUF_LENGTH];
    char cmdBuf[BUF_LENGTH];
    char delflag;
    String cmd = "AT+CMGD=";
    if(index.equalsIgnoreCase("0")){
        cmd.concat("1,3");  // delete all read messages from <memr> storage, sent and unsent mobile originated messages, leaving unread messages untouched
    } else {
        index.concat(",0");
        cmd.concat(index);
    }
    cmd.toCharArray(cmdBuf,BUF_LENGTH);
    requestModem(cmdBuf, 2000,true,buf);
}
Example #3
0
bool ProcessorGraph::processorWithSameNameExists(const String& name)
{
    for (int i = 0; i < getNumNodes(); i++)
    {
        Node* node = getNode(i);

        if (name.equalsIgnoreCase(node->getProcessor()->getName()))
            return true;

    }

    return false;

}
int triggerRelay(String command){
	if(command.equalsIgnoreCase("on")){
		Serial.println("Turning on relay");
		relayController.turnOnRelay();
		Serial.println("returning");
		return 1;
	}
	if(command.equalsIgnoreCase("off")){
		relayController.turnOffRelay();
		return 1;
	}
	if(command.equalsIgnoreCase("toggle")){
		relayController.toggleRelay();
		return 1;
	}
	if(command.equalsIgnoreCase("momentary")){
		relayController.turnOnRelay();
		delay(300);
		relayController.turnOffRelay();
		return 1;
	}
	return 0;
}
Example #5
0
JucerDocument* loadDocumentFromFile (const File& f, const bool showErrorMessage)
{
    File file (f);

    if (file == File::nonexistent && showErrorMessage)
    {
        FileChooser fc ("Open a Jucer C++ file...",
                        StoredSettings::getInstance()->recentFiles.getFile (0),
                        "*.cpp");

        if (! fc.browseForFileToOpen())
            return 0;

        file = fc.getResult();
    }

    XmlElement* xml = JucerDocument::pullMetaDataFromCppFile (file.loadFileAsString());

    if (xml == 0 || ! xml->hasTagName (JucerDocument::jucerCompXmlTag))
    {
        if (file != File::nonexistent && showErrorMessage)
            AlertWindow::showMessageBox (AlertWindow::WarningIcon,
                                         TRANS("Failed to open file..."),
                                         TRANS("This wasn't a valid Jucer .cpp file..."));

        delete xml;
        return 0;
    }

    const String docType (xml->getStringAttribute ("documentType"));
    delete xml;

    // (reverse order so ComponentDocument is default last-case)
    for (int i = numDocumentTypes; --i >= 0;)
    {
        if (docType.equalsIgnoreCase (documentTypeNames[i]) || i == 0)
        {
            JucerDocument* doc = createNewDocument (i);

            if (doc->loadFrom (file, showErrorMessage))
                return doc;

            delete doc;
            break;
        }
    }

    return 0;
}
Example #6
0
boolean TMRpcm::wavInfo(SDFile myFile) {
    sdFile = myFile;
    char nom[13];
    if(!myFile.isOpen() ) {
        return 0;
    }
    //Serial.println("MIERDAAAAA");
    myFile.seekSet(8);
    String wavStr = "";
    for(int i=0; i<3; i++) {
        wavStr += char(myFile.read());
    }
    if(!wavStr.equalsIgnoreCase("WAV")) {
        Serial.println("Not a WAV file");
        //Serial.println(wavStr);
        myFile.close();
        return 0;
    }

    //make sure the Sample rate is below 22000
    myFile.seekSet(24);
    unsigned int dVar = myFile.read();
    // Serial.println("dVar ");
    // Serial.println(dVar, BIN);
    dVar = myFile.read() << 8 | dVar; //read 8bit values into 16-bit integer

    // Serial.println("dVar2 ");
    // Serial.println(dVar, BIN);
    if(dVar > 22000) {
        Serial.print(" SampleRate Too High: ");
        SAMPLE_RATE = 22000;
    } else {
        SAMPLE_RATE = dVar; // Set the sample rate according to the file
    }

    //verify that Bits Per Sample is 8 (0-255)
    myFile.seekSet(34);
    dVar = myFile.read();
    // Serial.println("dVar3 ");
    // Serial.println(dVar, BIN);
    dVar = myFile.read() << 8 | dVar;
    // Serial.println("dVar4 ");
    // Serial.println(dVar, BIN);
    if(dVar != 8) {
        Serial.print("Wrong BitRate");
        return 0;
    }
    return 1;
}
Example #7
0
static JucerDocument* createDocument (SourceCodeDocument* cpp)
{
    CodeDocument& codeDoc = cpp->getCodeDocument();

    ScopedPointer<XmlElement> xml (JucerDocument::pullMetaDataFromCppFile (codeDoc.getAllContent()));

    if (xml == nullptr || ! xml->hasTagName (JucerDocument::jucerCompXmlTag))
        return nullptr;

    const String docType (xml->getStringAttribute ("documentType"));

    ScopedPointer<JucerDocument> newDoc;

    if (docType.equalsIgnoreCase ("Button"))
        newDoc = new ButtonDocument (cpp);

    if (docType.equalsIgnoreCase ("Component") || docType.isEmpty())
        newDoc = new ComponentDocument (cpp);

    if (newDoc != nullptr && newDoc->reloadFromDocument())
        return newDoc.release();

    return nullptr;
}
Example #8
0
String XmlDocument::expandEntity (const String& ent)
{
    if (ent.equalsIgnoreCase ("amp"))   return String::charToString ('&');
    if (ent.equalsIgnoreCase ("quot"))  return String::charToString ('"');
    if (ent.equalsIgnoreCase ("apos"))  return String::charToString ('\'');
    if (ent.equalsIgnoreCase ("lt"))    return String::charToString ('<');
    if (ent.equalsIgnoreCase ("gt"))    return String::charToString ('>');

    if (ent[0] == '#')
    {
        const juce_wchar char1 = ent[1];

        if (char1 == 'x' || char1 == 'X')
            return String::charToString (static_cast<juce_wchar> (ent.substring (2).getHexValue32()));

        if (char1 >= '0' && char1 <= '9')
            return String::charToString (static_cast<juce_wchar> (ent.substring (1).getIntValue()));

        setLastError ("illegal escape sequence", false);
        return String::charToString ('&');
    }

    return expandExternalEntity (ent);
}
Example #9
0
UnitTests::TestList UnitTests::selectTest (
    String const& testname, TestList const& tests) const noexcept
{
    TestList list;
    for (int i = 0; i < tests.size(); ++i)
    {
        UnitTest* const test = tests [i];
        if (testname.equalsIgnoreCase (test->getClassName ()))
        {
            list.add (test);
            break;
        }
    }
    return list;
}
Example #10
0
int PhoBot::setMotors(String command) {
    // "M3-F-100" use fixed positioning for first 2 params
    String motorName = command.substring(0, 2);
    String directionStr = command.substring(3, 4);
    String speedStr = command.substring(5);
    int direction = FORWARD;
    if (directionStr.equalsIgnoreCase("B")) {
        direction = BACK;
    }
    float speed = speedStr.toInt() / 100.0;
    if (motorName.equalsIgnoreCase("M3")) {
        setMotor(M3, direction, speed);
    }
    else if (motorName.equalsIgnoreCase("M4")) {
        setMotor(M4, direction, speed);
    }
    else if (motorName.equalsIgnoreCase("M1")) {
        setMotor(M1, FORWARD, speed);
    }
    else if (motorName.equalsIgnoreCase("M2")) {
        setMotor(M2, FORWARD, speed);
    }
    return 1;
}
CWMPPlaylist MediaDatabase::createPlayList(const String &name) { // static
  if(name.equalsIgnoreCase(queueName)) {
    throwException(_T("Cannot use name of queue (=%s) as name for playlist"), queueName);
  }
  CWMPPlayer4           &player       = MediaDatabase::getPlayer();
  CWMPPlaylistCollection plCollection = player.GetPlaylistCollection();
  CWMPPlaylistArray      plArray      = plCollection.getByName(name.cstr());
  CWMPPlaylist           result;
  if(plArray.GetCount() > 0) {
    result = plArray.Item(0);
    result.clear();
  } else {
    result = plCollection.newPlaylist(name.cstr());
  }
  return result;
}
Example #12
0
void ClockController::dispatchSerial(const String& line) {
  bool handled = false;

  if(line == "beep") {
    beep();
    handled = true;
  } else if(line.equalsIgnoreCase("Open the pod bay doors, HAL")){
    Serial.println("Sorry. I can't let you do that, Dave.");
    handled = true;
  } else {
    //Dispatch
    handled = this->handleSerialEvent(line);
  }

  if(!handled)
    Serial.println("I'm not wise enough to understand: " + line);
}
Example #13
0
String XmlDocument::getParameterEntity (const String& entity)
{
    for (int i = 0; i < tokenisedDTD.size(); ++i)
    {
        if (tokenisedDTD[i] == entity
             && tokenisedDTD [i - 1] == "%"
             && tokenisedDTD [i - 2].equalsIgnoreCase ("<!entity"))
        {
            const String ent (tokenisedDTD [i + 1].trimCharactersAtEnd (">"));

            if (ent.equalsIgnoreCase ("system"))
                return getFileContents (tokenisedDTD [i + 2].trimCharactersAtEnd (">"));

            return ent.trim().unquoted();
        }
    }

    return entity;
}
int triggerRelay(String command){
	if(command.equalsIgnoreCase("turnonallrelays")){
		relayController.turnOnAllRelays();
		return 1;
	}
	if(command.equalsIgnoreCase("turnoffallrelays")){
		relayController.turnOffAllRelays();
		return 1;
	}
	if(command.startsWith("setBankStatus:")){
		int status = command.substring(14).toInt();
		if(status < 0 || status > 255){
			return 0;
		}
		Serial.print("Setting bank status to: ");
		Serial.println(status);
		relayController.setBankStatus(status);
		Serial.println("done");
		return 1;
	}
	//Relay Specific Command
	int relayNumber = command.substring(0,1).toInt();
	Serial.print("relayNumber: ");
	Serial.println(relayNumber);
	String relayCommand = command.substring(1);
	Serial.print("relayCommand:");
	Serial.print(relayCommand);
	Serial.println(".");
	if(relayCommand.equalsIgnoreCase("on")){
		Serial.println("Turning on relay");
		relayController.turnOnRelay(relayNumber);
		Serial.println("returning");
		return 1;
	}
	if(relayCommand.equalsIgnoreCase("off")){
		relayController.turnOffRelay(relayNumber);
		return 1;
	}
	if(relayCommand.equalsIgnoreCase("toggle")){
		relayController.toggleRelay(relayNumber);
		return 1;
	}
	if(relayCommand.equalsIgnoreCase("momentary")){
		relayController.turnOnRelay(relayNumber);
		delay(300);
		relayController.turnOffRelay(relayNumber);
		return 1;
	}
	return 0;
}
Typeface::Ptr CustomLookAndFeel::getTypefaceForFont(const Font& font)
{
    String typefaceName = font.getTypefaceName();

    // some of these names might be unnecessary, and there may be good ones
    // missing.  adjust as needed
    if (typefaceName.equalsIgnoreCase("Default Extra Light"))
    {
        return cpmonoExtraLight;
    }
    else if (typefaceName.equalsIgnoreCase("Default Light"))
    {
        return cpmonoLight;
    }
    else if (typefaceName.equalsIgnoreCase("Default"))
    {
        return cpmonoPlain;
    }
    else if (typefaceName.equalsIgnoreCase("Default Bold"))
    {
        return cpmonoBold;
    }
    else if (typefaceName.equalsIgnoreCase("Default Black"))
    {
        return cpmonoBlack;
    }
    else if (typefaceName.equalsIgnoreCase("Paragraph"))
    {
        return misoRegular;
    }
    else if (typefaceName.equalsIgnoreCase("Small Text"))
    {
        return silkscreen;
    }
    else   // default
    {
        return LookAndFeel::getTypefaceForFont(font);
    }

    // UNCOMMENT AFTER UPDATE
    // if (typefaceMap.contains(typefaceName))
    //     return typefaceMap[typefaceName];
    // else
    //     return LookAndFeel::getTypefaceForFont(font);
}
Example #16
0
String rdata(String cstr)
{
  readagain:
  if (dbg>0)
  {
    reply(cstr);
  }else{
    reply("?");
  }
  String cst = "";
  while(Serial.available()>0)
  {
    cst += byte(Serial.read());
  }
  if (cst.equalsIgnoreCase("!"))
  {
    sprintln("cmd = "+cmdlck);
    goto readagain;
  }
  return cst;
}
Example #17
0
void Ambix_binauralAudioProcessorEditor::UpdatePresets()
{
    Ambix_binauralAudioProcessor* ourProcessor = getProcessor();
    
    popup_submenu.clear(); // contains submenus
    
    popup_presets.clear(); // main menu
    
    String lastSubdir;
    StringArray Subdirs; // hold name of subdirs
    
    int j = 1;
    
    for (int i=0; i < ourProcessor->_presetFiles.size(); i++) {
        
        // add separator for new subfolder
        String subdir = ourProcessor->_presetFiles.getUnchecked(i).getParentDirectory().getFileName();
        
        if (!lastSubdir.equalsIgnoreCase(subdir)) {
            
            popup_submenu.add(new PopupMenu());
            Subdirs.add(subdir);
            
            j++;
            lastSubdir = subdir;
        }
        
        // add item to submenu
        popup_submenu.getLast()->addItem(i+1, ourProcessor->_presetFiles.getUnchecked(i).getFileNameWithoutExtension());
        
    }
    
    // add all subdirs to main menu
    for (int i=0; i < popup_submenu.size(); i++) {
        popup_presets.addSubMenu(Subdirs.getReference(i), *popup_submenu.getUnchecked(i));
    }
    
    popup_presets.addItem(-1, String("open from file..."));
    
}
/*
 * This funtion will turn on/off the LED and set it to the appropriate color
 * Usage - "args=ON,1" will turn the LED on and set the color to Red
 * Color settings are:
 * 1 - RED
 * 2 - YELLOW
 * 3 - GREEN
 * 4 - BLUE
 * Errors (invalid color choices) will set the LED to full power for all RGB.
 * @param command The current state (on/off) and speed (1..4), comma-delimited and case-insensitive
 */
int Ohmbrewer_Pump::pumpCtrl(String command) {
    int    speedSuccess  = -1;
    int    toggleSuccess = -1;
    char * params        = new char[command.length() + 1];
    strcpy(params, command.c_str());
    
    // Parse the parameters
    String desiredPumpID  = String(strtok(params, ","));
    String stateUpdate    = String(strtok(NULL, ","));
    String stopTimeUpdate = String(strtok(NULL, ","));
    String speedUpdate    = "";
    
    if(stopTimeUpdate != NULL && stopTimeUpdate.toInt() > 0) {
        // Let's try to avoid null pointer exceptions...
        speedUpdate = "" + String(strtok(NULL, ",")); // Note that the quotes are a workaround for a known issue with the String class
    }

    if((desiredPumpID == NULL) || (!desiredPumpID.equalsIgnoreCase(this->pumpID))) {
        // Not doing anything with it right now, but we'll error out if it isn't provided properly
        return -9000;
    }
    
    this->setStopTime(stateUpdate, stopTimeUpdate);
    
    speedSuccess = this->setSpeed(speedUpdate);
    
    if(state != NULL) {
        // Toggle the LED, if appropriate
        toggleSuccess = this->togglePump(stateUpdate);
    }
    
    this->publishStatus();
    if(speedSuccess > 0 && toggleSuccess != -136) {
        return speedSuccess;
    }
    
    return toggleSuccess;
}
void RGBStrip::color2RGB(String color, int &r, int &g, int &b)
{
  r=0;
  g=0;
  b=0;
  if (color.equalsIgnoreCase("red"))
  {
    r=255;
  }
  else if (color.equalsIgnoreCase("green"))
  {
    g=255;
  }
  else if (color.equalsIgnoreCase("blue"))
  {
    b=255;
  }
  else if (color.equalsIgnoreCase("yellow"))
  {
    r=255;
    g=255;
  }
  else if (color.equalsIgnoreCase("purple"))
  {
    r=255;
    b=255;
  }
  else if (color.equalsIgnoreCase("cyan"))
  {
    b=255;
    g=255;
  }
  else if (color.equalsIgnoreCase("white"))
  {
    r=255;
    g=255;
    b=255;
  }
 setColorVars(r, g, b);
}
Example #20
0
GenericProcessor* ProcessorGraph::createProcessorFromDescription(String& description)
{
    int splitPoint = description.indexOf("/");
    String processorType = description.substring(0,splitPoint);
    String subProcessorType = description.substring(splitPoint+1);

    std::cout << processorType << "::" << subProcessorType << std::endl;

    GenericProcessor* processor = 0;

    if (processorType.equalsIgnoreCase("Sources"))
    {

        if (subProcessorType.equalsIgnoreCase("RHA2000-EVAL") ||
            // subProcessorType.equalsIgnoreCase("File Reader") ||
            subProcessorType.equalsIgnoreCase("Custom FPGA") ||
            subProcessorType.equalsIgnoreCase("eCube") || // Added by Michael Borisov
            subProcessorType.equalsIgnoreCase("Rhythm FPGA"))
        {

            // if (subProcessorType.equalsIgnoreCase("Intan Demo Board") &&
            // 	!processorWithSameNameExists(subProcessorType)) {
            // 	std::cout << "Only one Intan Demo Board is allowed at a time."
            // 			  << std::endl;
            // } else {
            std::cout << "Creating a new data source." << std::endl;
            processor = new SourceNode(subProcessorType);

            //}

        }
        else if (subProcessorType.equalsIgnoreCase("Signal Generator"))
        {
            processor = new SignalGenerator();
            std::cout << "Creating a new signal generator." << std::endl;
        }
        else if (subProcessorType.equalsIgnoreCase("Event Generator"))
        {
            processor = new EventNode();
            std::cout << "Creating a new event node." << std::endl;
        }
        else if (subProcessorType.equalsIgnoreCase("File Reader"))
        {
            processor = new FileReader();
            std::cout << "Creating a new file reader." << std::endl;
        }
        else if (subProcessorType.equalsIgnoreCase("Serial Port"))
        {
            processor = new SerialInput();
            std::cout << "Creating a new serial port input." << std::endl;
		}
		else if (subProcessorType.equalsIgnoreCase("Network Events"))
		{
			processor = new NetworkEvents();
			std::cout << "Creating a new signal generator." << std::endl;
		}



		CoreServices::sendStatusMessage("New source node created.");


    }
    else if (processorType.equalsIgnoreCase("Filters"))
    {

        if (subProcessorType.equalsIgnoreCase("Bandpass Filter"))
        {

            std::cout << "Creating a new filter." << std::endl;
            processor = new FilterNode();

        }
        else if (subProcessorType.equalsIgnoreCase("Rectifier"))
        {
            std::cout << "Creating a new rectifier node." << std::endl;
            processor = new Rectifier();
        }
        else if (subProcessorType.equalsIgnoreCase("Spike Detector"))
        {
            std::cout << "Creating a new spike detector." << std::endl;
            processor = new SpikeDetector();
        }
        else if (subProcessorType.equalsIgnoreCase("Spike Sorter"))
        {
            std::cout << "Creating a new spike sorter." << std::endl;
            processor = new SpikeSorter();
        }
        else if (subProcessorType.equalsIgnoreCase("Event Detector"))
        {
            std::cout << "Creating a new event detector." << std::endl;
            processor = new EventDetector();
        }
        else if (subProcessorType.equalsIgnoreCase("Phase Detector"))
        {
            std::cout << "Creating a new phase detector." << std::endl;
            processor = new PhaseDetector();
        }
        else if (subProcessorType.equalsIgnoreCase("Channel Map"))
        {
            std::cout << "Creating a new channel mapping node." << std::endl;
            processor = new ChannelMappingNode();
        }
        else if (subProcessorType.equalsIgnoreCase("Common Avg Ref"))
        {
            std::cout << "Creating a new common average reference node." << std::endl;
            processor = new CAR();
        }
		CoreServices::sendStatusMessage("New filter node created.");

    }
    else if (processorType.equalsIgnoreCase("Utilities"))
    {

        if (subProcessorType.equalsIgnoreCase("Splitter"))
        {

            std::cout << "Creating a new splitter." << std::endl;
            processor = new Splitter();

			CoreServices::sendStatusMessage("New splitter created.");

        }
        else if (subProcessorType.equalsIgnoreCase("Merger"))
        {

            std::cout << "Creating a new merger." << std::endl;
            processor = new Merger();

			CoreServices::sendStatusMessage("New merger created.");

        }
        else if (subProcessorType.equalsIgnoreCase("Record Control"))
        {

            std::cout << "Creating a new record controller." << std::endl;
            processor = new RecordControl();

			CoreServices::sendStatusMessage("New record controller created.");

        }

    }
    else if (processorType.equalsIgnoreCase("Sinks"))
    {

        if (subProcessorType.equalsIgnoreCase("LFP Viewer"))
        {
            std::cout << "Creating an LfpDisplayNode." << std::endl;
            processor = new LfpDisplayNode();
        }

        else if (subProcessorType.equalsIgnoreCase("Spike Viewer"))
        {
            std::cout << "Creating a SpikeDisplayNode." << std::endl;
            processor = new SpikeDisplayNode();
        }

        else if (subProcessorType.equalsIgnoreCase("Arduino Output"))
        {
            std::cout << "Creating an Arduino node." << std::endl;
            processor = new ArduinoOutput();
        }
        else if (subProcessorType.equalsIgnoreCase("Pulse Pal"))
        {
            std::cout << "Creating a Pulse Pal output node." << std::endl;
            processor = new PulsePalOutput();
		}
		else if (subProcessorType.equalsIgnoreCase("PSTH"))
		{
			std::cout << "Creating a PSTH output node." << std::endl;
			processor = new PeriStimulusTimeHistogramNode();
		}
        else if (subProcessorType.equalsIgnoreCase("Event Broadcaster"))
        {
            std::cout << "Creating an Event Broadcaster output node." << std::endl;
            processor = new EventBroadcaster();
        }

		CoreServices::sendStatusMessage("New sink created.");
    }

    return processor;
}
Example #21
0
GenericProcessor* ProcessorGraph::createProcessorFromDescription(String& description)
{
    int splitPoint = description.indexOf("/");
    String processorType = description.substring(0,splitPoint);
    String subProcessorType = description.substring(splitPoint+1);

    std::cout << processorType << "::" << subProcessorType << std::endl;

    GenericProcessor* processor = 0;

    if (processorType.equalsIgnoreCase("Sources"))
    {

        if (subProcessorType.equalsIgnoreCase("RHA2000-EVAL") ||
            // subProcessorType.equalsIgnoreCase("File Reader") ||
            subProcessorType.equalsIgnoreCase("Custom FPGA") ||
            subProcessorType.equalsIgnoreCase("Rhythm FPGA"))
        {

            // if (subProcessorType.equalsIgnoreCase("Intan Demo Board") &&
            // 	!processorWithSameNameExists(subProcessorType)) {
            // 	std::cout << "Only one Intan Demo Board is allowed at a time."
            // 			  << std::endl;
            // } else {
            std::cout << "Creating a new data source." << std::endl;
            processor = new SourceNode(subProcessorType);

            //}

        }
        else if (subProcessorType.equalsIgnoreCase("Signal Generator"))
        {
            processor = new SignalGenerator();
            std::cout << "Creating a new signal generator." << std::endl;
        }
        else if (subProcessorType.equalsIgnoreCase("Event Generator"))
        {
            processor = new EventNode();
            std::cout << "Creating a new event node." << std::endl;
        }
        else if (subProcessorType.equalsIgnoreCase("File Reader"))
        {
            processor = new FileReader();
            std::cout << "Creating a new file reader." << std::endl;
        }


        sendActionMessage("New source node created.");


    }
    else if (processorType.equalsIgnoreCase("Filters"))
    {

        if (subProcessorType.equalsIgnoreCase("Bandpass Filter"))
        {

            std::cout << "Creating a new filter." << std::endl;
            processor = new FilterNode();

        }
        else if (subProcessorType.equalsIgnoreCase("Resampler"))
        {
            std::cout << "Creating a new resampler." << std::endl;
            processor = new ResamplingNode();

        }
        else if (subProcessorType.equalsIgnoreCase("Spike Detector"))
        {
            std::cout << "Creating a new spike detector." << std::endl;
            processor = new SpikeDetector();
        }
        else if (subProcessorType.equalsIgnoreCase("Event Detector"))
        {
            std::cout << "Creating a new event detector." << std::endl;
            processor = new EventDetector();
        }
        else if (subProcessorType.equalsIgnoreCase("Phase Detector"))
        {
            std::cout << "Creating a new phase detector." << std::endl;
            processor = new PhaseDetector();
        }
        else if (subProcessorType.equalsIgnoreCase("Digital Ref"))
        {
            std::cout << "Creating a new digital reference." << std::endl;
            processor = new ReferenceNode();
        }
        else if (subProcessorType.equalsIgnoreCase("Channel Map"))
        {
            std::cout << "Creating a new channel mapping node." << std::endl;
            processor = new ChannelMappingNode();
        }

        sendActionMessage("New filter node created.");

    }
    else if (processorType.equalsIgnoreCase("Utilities"))
    {

        if (subProcessorType.equalsIgnoreCase("Splitter"))
        {

            std::cout << "Creating a new splitter." << std::endl;
            processor = new Splitter();

            sendActionMessage("New splitter created.");

        }
        else if (subProcessorType.equalsIgnoreCase("Merger"))
        {

            std::cout << "Creating a new merger." << std::endl;
            processor = new Merger();

            sendActionMessage("New merger created.");

        }
        else if (subProcessorType.equalsIgnoreCase("Record Control"))
        {

            std::cout << "Creating a new record controller." << std::endl;
            processor = new RecordControl();

            sendActionMessage("New record controller created.");

        }

    }
    else if (processorType.equalsIgnoreCase("Sinks"))
    {

        if (subProcessorType.equalsIgnoreCase("LFP Viewer"))
        {
            std::cout << "Creating an LfpDisplayNode." << std::endl;
            processor = new LfpDisplayNode();

            // std::cout << "Graph data viewport: " << UI->getDataViewport() << std::endl;
            // processor->setDataViewport(getDataViewport());
            //processor->setUIComponent(UI);
        }
        else if (subProcessorType.equalsIgnoreCase("LFP Trig. Avg."))
        {
            std::cout << "Creating an LfpTrigAvgNode." << std::endl;
            processor = new LfpTriggeredAverageNode();
        }                   
        
        else if (subProcessorType.equalsIgnoreCase("Spike Viewer"))
        {
            std::cout << "Creating a SpikeDisplayNode." << std::endl;
            processor = new SpikeDisplayNode();
        }
        else if (subProcessorType.equalsIgnoreCase("WiFi Output"))
        {
            std::cout << "Creating a WiFi node." << std::endl;
            processor = new WiFiOutput();
        }
        else if (subProcessorType.equalsIgnoreCase("Arduino Output"))
        {
            std::cout << "Creating an Arduino node." << std::endl;
            processor = new ArduinoOutput();
        }
        else if (subProcessorType.equalsIgnoreCase("FPGA Output"))
        {
            std::cout << "Creating an FPGA output node." << std::endl;
            processor = new FPGAOutput();
        }
        else if (subProcessorType.equalsIgnoreCase("Pulse Pal"))
        {
            std::cout << "Creating a Pulse Pal output node." << std::endl;
            processor = new PulsePalOutput();
        }

        sendActionMessage("New sink created.");
    }

    return processor;
}
bool VirtualKeyboardParser::parserCallback_event(ParserNode *node) {
    // if just checking resolutions we're done
    if (_parseMode == kParseCheckResolutions)
        return true;

    String name = node->values["name"];
    if (_mode->events.contains(name))
        return parserError("Event '%s' has already been defined", name.c_str());

    VirtualKeyboard::VKEvent *evt = new VirtualKeyboard::VKEvent();
    evt->name = name;

    String type = node->values["type"];
    if (type.equalsIgnoreCase("key")) {
        if (!node->values.contains("code") || !node->values.contains("ascii")) {
            delete evt;
            return parserError("Key event element must contain code and ascii attributes");
        }
        evt->type = VirtualKeyboard::kVKEventKey;

        KeyState *ks = (KeyState*) malloc(sizeof(KeyState));
        ks->keycode = (KeyCode)atoi(node->values["code"].c_str());
        ks->ascii = atoi(node->values["ascii"].c_str());
        ks->flags = 0;
        if (node->values.contains("modifiers"))
            ks->flags = parseFlags(node->values["modifiers"]);
        evt->data = ks;

    } else if (type.equalsIgnoreCase("modifier")) {
        if (!node->values.contains("modifiers")) {
            delete evt;
            return parserError("Key modifier element must contain modifier attributes");
        }

        evt->type = VirtualKeyboard::kVKEventModifier;
        byte *flags = (byte*) malloc(sizeof(byte));
        *(flags) = parseFlags(node->values["modifiers"]);
        evt->data = flags;

    } else if (type.equalsIgnoreCase("switch_mode")) {
        if (!node->values.contains("mode")) {
            delete evt;
            return parserError("Switch mode event element must contain mode attribute");
        }

        evt->type = VirtualKeyboard::kVKEventSwitchMode;
        String& mode = node->values["mode"];
        char *str = (char*) malloc(sizeof(char) * mode.size() + 1);
        memcpy(str, mode.c_str(), sizeof(char) * mode.size());
        str[mode.size()] = 0;
        evt->data = str;
    } else if (type.equalsIgnoreCase("submit")) {
        evt->type = VirtualKeyboard::kVKEventSubmit;
    } else if (type.equalsIgnoreCase("cancel")) {
        evt->type = VirtualKeyboard::kVKEventCancel;
    } else if (type.equalsIgnoreCase("clear")) {
        evt->type = VirtualKeyboard::kVKEventClear;
    } else if (type.equalsIgnoreCase("delete")) {
        evt->type = VirtualKeyboard::kVKEventDelete;
    } else if (type.equalsIgnoreCase("move_left")) {
        evt->type = VirtualKeyboard::kVKEventMoveLeft;
    } else if (type.equalsIgnoreCase("move_right")) {
        evt->type = VirtualKeyboard::kVKEventMoveRight;
    } else {
        delete evt;
        return parserError("Event type '%s' not known", type.c_str());
    }

    _mode->events[name] = evt;

    return true;
}
bool CommandLineEngine::execute( String cmdLine, Print * printer )
{

	if( cmdLine.length() <= 0 )
		return false;

	Tokens tk;


	if( Tokens::Tokenize(tk,cmdLine).isEmpty() )
		return false;

	// Replace the macros now
	// doMacros uses external iterator so the internal iterator of tk is untouched

	doMacros( tk );

	// Now find the function and call it
	// But first check if it is one of the built in functions


	String func;
	if (!tk.next(func))
		return false;

	// Remove trailing weird space issues
	func.trim();


	if( func.equalsIgnoreCase("set") ) {
		// Built in function
		set( printer, tk, FF_Normal );
	}
	else if ( func.equalsIgnoreCase("help") ) {
		// Built in function
		help( printer, tk, FF_Normal );
	}
	else {
		bool foundfunction = false;
		// Now Search for the function and call the user function if
		//  we can find it

		for( UserFunctions::iterator it = mUserFunctions.begin(); it != mUserFunctions.end(); ++it )
		{

			if( func.equalsIgnoreCase( it->name) ) {
				foundfunction = true;
				it->func( 	printer ? printer : &nullprinter,
							tk,
							FF_Normal);
				break;
			}
		}
		if( !foundfunction ) {
			if(printer) {
				printer->print("Unable to find the specified command: ");
				printer->println( func );
			}
			return false;
		}

	}

	return true;
}
Example #24
0
/**
 * reads the response from the server
 * @return int http code
 */
int HTTPClient::handleHeaderResponse() {

    if(!connected()) {
        return HTTPC_ERROR_NOT_CONNECTED;
    }
    String transferEncoding;
    _returnCode = -1;
    _size = -1;
    _transferEncoding = HTTPC_TE_IDENTITY;

    while(connected()) {
        size_t len = _tcp->available();
        if(len > 0) {
            String headerLine = _tcp->readStringUntil('\n');
            headerLine.trim(); // remove \r

            DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] RX: '%s'\n", headerLine.c_str());

            if(headerLine.startsWith("HTTP/1.")) {
                _returnCode = headerLine.substring(9, headerLine.indexOf(' ', 9)).toInt();
            } else if(headerLine.indexOf(':')) {
                String headerName = headerLine.substring(0, headerLine.indexOf(':'));
                String headerValue = headerLine.substring(headerLine.indexOf(':') + 2);

                if(headerName.equalsIgnoreCase("Content-Length")) {
                    _size = headerValue.toInt();
                }

                if(headerName.equalsIgnoreCase("Connection")) {
                    _canReuse = headerValue.equalsIgnoreCase("keep-alive");
                }

                if(headerName.equalsIgnoreCase("Transfer-Encoding")) {
                    transferEncoding = headerValue;
                }

                for(size_t i = 0; i < _headerKeysCount; i++) {
                    if(_currentHeaders[i].key.equalsIgnoreCase(headerName)) {
                        _currentHeaders[i].value = headerValue;
                        break;
                    }
                }
            }

            if(headerLine == "") {
                DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] code: %d\n", _returnCode);

                if(_size > 0) {
                    DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] size: %d\n", _size);
                }

                if(transferEncoding.length() > 0) {
                    DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] Transfer-Encoding: %s\n", transferEncoding.c_str());
                    if(transferEncoding.equalsIgnoreCase("chunked")) {
                        _transferEncoding = HTTPC_TE_CHUNKED;
                    } else {
                        return HTTPC_ERROR_ENCODING;
                    }
                } else {
                    _transferEncoding = HTTPC_TE_IDENTITY;
                }

                if(_returnCode) {
                    return _returnCode;
                } else {
                    DEBUG_HTTPCLIENT("[HTTP-Client][handleHeaderResponse] Remote host is not an HTTP Server!");
                    return HTTPC_ERROR_NO_HTTP_SERVER;
                }
            }

        } else {
            delay(0);
        }
    }

    return HTTPC_ERROR_CONNECTION_LOST;
}
Example #25
0
/**
 * phasing the url for all needed informations
 * @param url String
 * @param httpsFingerprint String
 */
void HTTPClient::begin(String url, String httpsFingerprint) {

    DEBUG_HTTPCLIENT("[HTTP-Client][begin] url: %s\n", url.c_str());

    _httpsFingerprint = httpsFingerprint;
    _returnCode = 0;
    _size = -1;

    _Headers = "";

    String protocol;
    // check for : (http: or https:
    int index = url.indexOf(':');
    //int index2;
    bool hasPort = false;
    if(index) {
        protocol = url.substring(0, index);
        url.remove(0, (index + 3)); // remove http:// or https://

        index = url.indexOf('/');
        String host = url.substring(0, index);
        url.remove(0, index); // remove host part

        // get Authorization
        index = host.indexOf('@');
        if(index >= 0) {
            // auth info
            String auth = host.substring(0, index);
            host.remove(0, index + 1); // remove auth part including @
            _base64Authorization = base64::encode(auth);
        }

        // get port
        index = host.indexOf(':');
        if(index >= 0) {
            _host = host.substring(0, index); // hostname
            host.remove(0, (index + 1)); // remove hostname + :
            _port = host.toInt(); // get port
            hasPort = true;
        } else {
            _host = host;
        }

        _url = url;

        if(protocol.equalsIgnoreCase("http")) {
            _https = false;
            if(!hasPort) {
                _port = 80;
            }
        } else if(protocol.equalsIgnoreCase("https")) {
            _https = true;
            if(!hasPort) {
                _port = 443;
            }
        } else {
            DEBUG_HTTPCLIENT("[HTTP-Client][begin] protocol: %s unknown?!\n", protocol.c_str());
            return;
        }

    }

    DEBUG_HTTPCLIENT("[HTTP-Client][begin] host: %s port: %d url: %s https: %d httpsFingerprint: %s\n", _host.c_str(), _port, _url.c_str(), _https, _httpsFingerprint.c_str());

}
Example #26
0
bool HttpRequest::isWebSocket()
{
	String req = getHeader("Upgrade");
	return req.equalsIgnoreCase("websocket");
}
Example #27
0
bool HttpRequest::isAjax()
{
	String req = getHeader("HTTP_X_REQUESTED_WITH");
	return req.equalsIgnoreCase("xmlhttprequest");
}
/**
 * handle the WebSocket header reading
 * @param client WSclient_t *  ptr to the client struct
 */
void WebSocketsClient::handleHeader(WSclient_t * client, String * headerLine) {

    headerLine->trim(); // remove \r

    if(headerLine->length() > 0) {
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader] RX: %s\n", headerLine->c_str());

        if(headerLine->startsWith("HTTP/1.")) {
            // "HTTP/1.1 101 Switching Protocols"
            client->cCode = headerLine->substring(9, headerLine->indexOf(' ', 9)).toInt();
        } else if(headerLine->indexOf(':')) {
            String headerName = headerLine->substring(0, headerLine->indexOf(':'));
            String headerValue = headerLine->substring(headerLine->indexOf(':') + 2);

            if(headerName.equalsIgnoreCase("Connection")) {
                if(headerValue.equalsIgnoreCase("upgrade")) {
                    client->cIsUpgrade = true;
                }
            } else if(headerName.equalsIgnoreCase("Upgrade")) {
                if(headerValue.equalsIgnoreCase("websocket")) {
                    client->cIsWebsocket = true;
                }
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Accept")) {
                client->cAccept = headerValue;
                client->cAccept.trim(); // see rfc6455
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Protocol")) {
                client->cProtocol = headerValue;
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Extensions")) {
                client->cExtensions = headerValue;
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Version")) {
                client->cVersion = headerValue.toInt();
            }
        } else {
            DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header error (%s)\n", headerLine->c_str());
        }

        (*headerLine) = "";
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
        client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsClient::handleHeader, this, client, &(client->cHttpLine)));
#endif

    } else {
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header read fin.\n");
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Client settings:\n");

        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cURL: %s\n", client->cUrl.c_str());
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cKey: %s\n", client->cKey.c_str());

        DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Server header:\n");
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cCode: %d\n", client->cCode);
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cIsUpgrade: %d\n", client->cIsUpgrade);
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cIsWebsocket: %d\n", client->cIsWebsocket);
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cAccept: %s\n", client->cAccept.c_str());
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cProtocol: %s\n", client->cProtocol.c_str());
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cExtensions: %s\n", client->cExtensions.c_str());
        DEBUG_WEBSOCKETS("[WS-Client][handleHeader]  - cVersion: %d\n", client->cVersion);

        bool ok = (client->cIsUpgrade && client->cIsWebsocket);

        if(ok) {
            switch(client->cCode) {
                case 101:  ///< Switching Protocols

                    break;
                case 403: ///< Forbidden
                    // todo handle login
                default:   ///< Server dont unterstand requrst
                    ok = false;
                    DEBUG_WEBSOCKETS("[WS-Client][handleHeader] serverCode is not 101 (%d)\n", client->cCode);
                    clientDisconnect(client);
                    break;
            }
        }

        if(ok) {

            if(client->cAccept.length() == 0) {
                ok = false;
            } else {
                // generate Sec-WebSocket-Accept key for check
                String sKey = acceptKey(client->cKey);
                if(sKey != client->cAccept) {
                    DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Sec-WebSocket-Accept is wrong\n");
                    ok = false;
                }
            }
        }

        if(ok) {

            DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Websocket connection init done.\n");
            headerDone(client);


            runCbEvent(WStype_CONNECTED, (uint8_t *) client->cUrl.c_str(), client->cUrl.length());

        } else {
            DEBUG_WEBSOCKETS("[WS-Client][handleHeader] no Websocket connection close.\n");
            client->tcp->write("This is a webSocket client!");
            clientDisconnect(client);
        }
    }
}
/**
 * handles http header reading for WebSocket upgrade
 * @param client WSclient_t * ///< pointer to the client struct
 * @param headerLine String ///< the header being read / processed
 */
void WebSocketsServer::handleHeader(WSclient_t * client, String * headerLine) {

    headerLine->trim(); // remove \r

    if(headerLine->length() > 0) {
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] RX: %s\n", client->num, headerLine->c_str());

        // websocket requests always start with GET see rfc6455
        if(headerLine->startsWith("GET ")) {

            // cut URL out
            client->cUrl = headerLine->substring(4, headerLine->indexOf(' ', 4));

            //reset non-websocket http header validation state for this client
			client->cHttpHeadersValid = true;
			client->cMandatoryHeadersCount = 0;

        } else if(headerLine->indexOf(':')) {
            String headerName = headerLine->substring(0, headerLine->indexOf(':'));
            String headerValue = headerLine->substring(headerLine->indexOf(':') + 2);

            if(headerName.equalsIgnoreCase("Connection")) {
                headerValue.toLowerCase();
            	if(headerValue.indexOf("upgrade") >= 0) {
                    client->cIsUpgrade = true;
                }
            } else if(headerName.equalsIgnoreCase("Upgrade")) {
                if(headerValue.equalsIgnoreCase("websocket")) {
                    client->cIsWebsocket = true;
                }
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Version")) {
                client->cVersion = headerValue.toInt();
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Key")) {
                client->cKey = headerValue;
                client->cKey.trim(); // see rfc6455
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Protocol")) {
                client->cProtocol = headerValue;
            } else if(headerName.equalsIgnoreCase("Sec-WebSocket-Extensions")) {
                client->cExtensions = headerValue;
            } else if(headerName.equalsIgnoreCase("Authorization")) {
                client->base64Authorization = headerValue;
            } else {
            	client->cHttpHeadersValid &= execHttpHeaderValidation(headerName, headerValue);
            	if (_mandatoryHttpHeaderCount > 0 && hasMandatoryHeader(headerName)) {
            		client->cMandatoryHeadersCount++;
            	}
            }

        } else {
            DEBUG_WEBSOCKETS("[WS-Client][handleHeader] Header error (%s)\n", headerLine->c_str());
        }

        (*headerLine) = "";
#if (WEBSOCKETS_NETWORK_TYPE == NETWORK_ESP8266_ASYNC)
        client->tcp->readStringUntil('\n', &(client->cHttpLine), std::bind(&WebSocketsServer::handleHeader, this, client, &(client->cHttpLine)));
#endif
    } else {

        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] Header read fin.\n", client->num);
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cURL: %s\n", client->num, client->cUrl.c_str());
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cIsUpgrade: %d\n", client->num, client->cIsUpgrade);
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cIsWebsocket: %d\n", client->num, client->cIsWebsocket);
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cKey: %s\n", client->num, client->cKey.c_str());
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cProtocol: %s\n", client->num, client->cProtocol.c_str());
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cExtensions: %s\n", client->num, client->cExtensions.c_str());
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cVersion: %d\n", client->num, client->cVersion);
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - base64Authorization: %s\n", client->num, client->base64Authorization.c_str());
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cHttpHeadersValid: %d\n", client->num, client->cHttpHeadersValid);
        DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - cMandatoryHeadersCount: %d\n", client->num, client->cMandatoryHeadersCount);

        bool ok = (client->cIsUpgrade && client->cIsWebsocket);

        if(ok) {
            if(client->cUrl.length() == 0) {
                ok = false;
            }
            if(client->cKey.length() == 0) {
                ok = false;
            }
            if(client->cVersion != 13) {
                ok = false;
            }
            if(!client->cHttpHeadersValid) {
            	ok = false;
            }
            if (client->cMandatoryHeadersCount != _mandatoryHttpHeaderCount) {
            	ok = false;
            }
        }

        if(_base64Authorization.length() > 0) {
            if(client->base64Authorization.length() > 0) {
                String auth = "Basic ";
                auth += _base64Authorization;
                if(auth != client->base64Authorization) {
                    DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] HTTP Authorization failed!\n", client->num);
                    handleAuthorizationFailed(client);
                    return;
                }
            } else {
                ok = false;
            }
        }

        if(ok) {

            DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader] Websocket connection incoming.\n", client->num);

            // generate Sec-WebSocket-Accept key
            String sKey = acceptKey(client->cKey);

            DEBUG_WEBSOCKETS("[WS-Server][%d][handleHeader]  - sKey: %s\n", client->num, sKey.c_str());

            client->status = WSC_CONNECTED;

            client->tcp->write("HTTP/1.1 101 Switching Protocols\r\n"
                    "Server: arduino-WebSocketsServer\r\n"
                    "Upgrade: websocket\r\n"
                    "Connection: Upgrade\r\n"
                    "Sec-WebSocket-Version: 13\r\n"
                    "Sec-WebSocket-Accept: ");
            client->tcp->write(sKey.c_str(), sKey.length());

            if(_origin.length() > 0) {
                String origin = "\r\nAccess-Control-Allow-Origin: ";
                origin += _origin;
                origin += "\r\n";
                client->tcp->write(origin.c_str(), origin.length());
            }

            if(client->cProtocol.length() > 0) {
                String protocol = "\r\nSec-WebSocket-Protocol: ";
                protocol += _protocol;
                protocol += "\r\n";
                client->tcp->write(protocol.c_str(), protocol.length());
            } else {
                client->tcp->write("\r\n");
            }

            // header end
            client->tcp->write("\r\n");

            headerDone(client);

            // send ping
            WebSockets::sendFrame(client, WSop_ping);

            runCbEvent(client->num, WStype_CONNECTED, (uint8_t *) client->cUrl.c_str(), client->cUrl.length());

        } else {
            handleNonWebsocketConnection(client);
        }
    }
}
BOOL CAlfrescoApp::InitInstance()
{
	// InitCommonControls() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.

	InitCommonControls();
	CWinApp::InitInstance();
	AfxEnableControlContainer();

	// Check if debug logging is enabled

	char dbgLogName[MAX_PATH];
	size_t dbgLogSize;

	if ( getenv_s( &dbgLogSize, dbgLogName, sizeof( dbgLogName), "ALFDEBUG") == 0) {

		// Enable debug output

		Debug::openLog( dbgLogName);

		// Log the application startup

		DBGOUT_TS << "---------- Desktop client app started ----------" << endl; 
	}

	// Get the application path

	String appPath = __wargv[0];

	int pos = appPath.lastIndexOf(PathSeperator);

	if ( pos < 0) {
		AfxMessageBox( L"Invalid application path", MB_OK | MB_ICONSTOP);
		DBGOUT_TS << "Error, bad application path, " << appPath << endl;
		return 1;
	}

	// Get the path to the folder containing the application

	String folderPath = appPath.substring(0, pos);
	String exeName    = appPath.substring(pos + 1);

	// Create a list of the command line arguments

	StringList argList;
	bool argSetWorkDir = false;

	for ( int i = 1; i < __argc; i++) {

		// Check if the argument is a path or switch

		String arg = __wargv[i];

		if ( arg.startsWith( "/")) {

			// Check for the set working directory switch

			if ( arg.equalsIgnoreCase( "/D")) {
				argSetWorkDir = true;

				// DEBUG

				DBGOUT_TS << "/D switch specified" << endl;
			}
			else {
				String msg = L"Invalid command line switch - ";
				msg.append( arg);
				AfxMessageBox( msg.data(), MB_OK | MB_ICONSTOP);
				DBGOUT_TS << "Error, " << msg << endl;
				return 2;
			}
		}
		else {

			// Add the path to the argument list

			argList.addString( arg);
		}
	}

	// Check if the working directory should be set to the path of the first document

	if ( argSetWorkDir == true) {

		// Check if there are any document paths

		if ( argList.numberOfStrings() == 0) {
			AfxMessageBox( L"Cannot set working directory, no document paths", MB_OK | MB_ICONSTOP);
			DBGOUT_TS << "Error, cannot set working directory, no document paths" << endl;
			return 3;
		}

		// Get the first document path and remove the file name

		String docPath = argList[0];
		pos = docPath.lastIndexOf( PathSeperator);

		if ( pos < 0) {
			AfxMessageBox( L"Invalid document path", MB_OK | MB_ICONSTOP);
			DBGOUT_TS << "Error, invalid document path, " << docPath << endl;
			return 4;
		}

		// Set the document path as the working directory folder

		folderPath = docPath.substring(0, pos);

		// DEBUG

		DBGOUT_TS << "Using document path as working directory, " << folderPath << endl;
	}

	// DEBUG

	if ( HAS_DEBUG)
		DBGOUT_TS << "Using folder path " << folderPath << " for Alfresco base dir" << endl;

	// Create the Alfresco interface

	AlfrescoInterface alfresco(folderPath);

	if ( alfresco.isAlfrescoFolder()) {

		try {

			// DEBUG

			DBGOUT_TS << "Using folder " << folderPath << endl;

			// Get the action information

			AlfrescoActionInfo actionInfo = alfresco.getActionInformation(exeName);

			// DEBUG

			if ( HAS_DEBUG) {
				DBGOUT_TS << "Action " << actionInfo.getName() << endl;
				DBGOUT_TS << "  PreProcess: ";

				if ( actionInfo.hasPreProcessAction( PreConfirmAction))
					DBGOUT << "Confirm ";
				if ( actionInfo.hasPreProcessAction( PreCopyToTarget))
					DBGOUT << "CopyToTarget ";
				if ( actionInfo.hasPreProcessAction( PreLocalToWorkingCopy))
					DBGOUT << "LocalToWorkingCopy";
				DBGOUT << endl;
			}

			// Check if the action should be confirmed

			if ( actionInfo.hasPreProcessAction(PreConfirmAction)) {

				// Get the confirmation message

				String confirmMsg = actionInfo.getConfirmationMessage();
				if ( confirmMsg.length() == 0)
					confirmMsg = L"Run action ?";

				// DEBUG

				DBGOUT_TS << "Confirm action, message = " << confirmMsg << endl;

				// Display a confirmation dialog

				if ( AfxMessageBox( confirmMsg, MB_OKCANCEL | MB_ICONQUESTION) == IDCANCEL) {
					DBGOUT_TS << "User cancelled action" << endl;
					return FALSE;
				}
			}

			// Check if the action supports multiple paths, if not then call the action once for each supplied path

			if ( actionInfo.hasAttribute(AttrMultiplePaths)) {

				// Run the action

				runAction( alfresco, argList, actionInfo);
			}

			// Check if the action supports file/folder targets

			else if ( actionInfo.hasAttribute( AttrAnyFilesFolders) == true) {

				// Pass one path at a time to the action

				for ( size_t i = 0; i < argList.numberOfStrings(); i++) {

					// Create a path list with a single path

					StringList pathList;
					pathList.addString( argList[i]);

					// Run the action

					runAction( alfresco, pathList, actionInfo);
				}
			}

			// Action does not use targets, just run the action

			else if ( actionInfo.allowsNoParameters()) {

				// Run the action

				StringList emptyList;
				runAction( alfresco, emptyList, actionInfo);
			}
		}
		catch (Exception ex) {
			CString msg;
			msg.FormatMessage( L"Exception occurred\n\n%1", ex.getMessage().data());
			AfxMessageBox( msg, MB_OK | MB_ICONSTOP);
		}
	}
	else {
		AfxMessageBox( L"Not a valid Alfresco CIFS folder", MB_OK | MB_ICONSTOP);
		DBGOUT_TS << "Error, not a valid Alfresco CIFS folder, " << folderPath << endl;
		return 1;
	}

	//	Exit the application

	return FALSE;
}