Example #1
0
	void UtlXMLStream::writeAttribute(const std::string& sName, bool bValue) {
		std::string sNormalizedName = normalizeAttributeName(sName);
		getOutputStream() << " " << sNormalizedName.c_str() << "=\"";
		if (bValue) getOutputStream() << "True";
		else getOutputStream() << "False";
		getOutputStream() << "\"";
	}
Example #2
0
	void UtlXMLStream::writeHashtableEntry(const std::string& sKey, const std::vector<std::string>& listOfValues) {
		getOutputStream() << _sIndentation.c_str() << "<pair key=\"" << sKey.c_str() << "\" >" << std::endl;
		_sIndentation += "\t";
		for (std::vector<std::string>::const_iterator i = listOfValues.begin(); i != listOfValues.end(); i++) {
			getOutputStream() << _sIndentation.c_str() << "<string value=\"" << i->c_str() << "\" >" << std::endl;
		}
		_sIndentation = _sIndentation.substr(1);
		getOutputStream() << _sIndentation.c_str() << "</pair>" << std::endl;
	}
Example #3
0
 void JConnection::sendOk(){
     getOutputStream();
     out->writeByte((jint)JTransportConfiguration::MSG_TYPE_OK);
     if (isReusable()){
         out->flush();
     }
 }
Example #4
0
void IppURLConnection::setContent()
{
	if (connected && __ippRequest) {
		ostream &os = getOutputStream();
		os << *__ippRequest;
	}
}
Example #5
0
void VoteProcessorUsingHash::printOut(const CandidateList& maxCandidates) {
	std::ostream& out = getOutputStream();

	for (auto& name : maxCandidates) {
		out << name << std::endl;
	}
}
Example #6
0
	void UtlXMLStream::writeAttribute(const std::string& sName, const UtlDate& myValue) {
		std::string sNormalizedName = normalizeAttributeName(sName);
		std::string sDate = myValue.getString();
		if (!myValue.isNull()) {
			getOutputStream() << " " << sNormalizedName.c_str() << "=\"" << sDate.c_str() << "\"";
		}
	}
void
CClientProxy1_1::keyRepeat(KeyID key, KeyModifierMask mask,
				SInt32 count, KeyButton button)
{
	LOG((CLOG_DEBUG1 "send key repeat to \"%s\" id=%d, mask=0x%04x, count=%d, button=0x%04x", getName().c_str(), key, mask, count, button));
	CProtocolUtil::writef(getOutputStream(), kMsgDKeyRepeat, key, mask, count, button);
}
Example #8
0
void Logger::startLog( LogLevel loglevel, const char * file, int line,
                       const char * pretty)
{
  getOutputStream() << getFormattedDate() << ' ' <<
                       logLevelToStr(loglevel) << " (" <<
                       file << ':' << line << ") [" <<
                       pretty << "] ";
}
Example #9
0
void eepromMemoryReadBlock(Eeprom* eeprom_, unsigned long index, unsigned int length, Buffer* buffer) {
    // Find a better implementation
    unsigned long i;
    for (i = index; i < index + length; i++) {
        char value = eeprom_->eepromReadChar(eeprom_, i);
        append(getOutputStream(buffer), value);
    }
}
void notifyInfraredDetectorDetection(int type) {
    Buffer* buffer = getMechanicalBoard2I2CSlaveOutputBuffer();
    OutputStream* outputStream = getOutputStream(buffer);
    append(outputStream, NOTIFY_INFRARED_DETECTOR_DETECTION);
	appendHex2(outputStream, type);

	// Debug
	OutputStream* debugOutputStream = getDebugOutputStreamLogger();
	append(debugOutputStream, NOTIFY_INFRARED_DETECTOR_DETECTION);
	appendHex2(debugOutputStream, type);
}
Example #11
0
void Logger::startLog(LogLevel loglevel, const char * file, int line,
                      const char * pretty)
{
  std::string fileStr(file);
  auto lastSlash = fileStr.find_last_of('/');

  getOutputStream() << getFormattedDate() << ' ' <<
                       logLevelToStr(loglevel) << " " <<
                       fileStr.substr(lastSlash+1) << ':' << line << " [" <<
                       pretty << "] ";
}
Example #12
0
bool HttpServletResponse::sendHeader(void)
{
    acl_assert(header_->is_request() == false);
    string buf;
    if (charset_[0] != 0)
        buf.format("%s; charset=%s", content_type_, charset_);
    else
        buf.format("%s", content_type_);
    header_->set_content_type(buf.c_str());

    buf.clear();
    header_->build_response(buf);
    return getOutputStream().write(buf) == -1 ? false : true;
}
Example #13
0
void initDriverToI2CSlaveAndDebugCompositeOutputStream(bool includeI2C) {
    initCompositeOutputStream(&driverToI2CSlaveAndDebugCompositeOutputStream);

    // UART / DEBUG
    addOutputStream(&driverToI2CSlaveAndDebugCompositeOutputStream, getInfoOutputStreamLogger());

    // I2C
    if (includeI2C) {
        StreamLink* i2cStreamLink = getI2cStreamLink();
        Buffer* i2cOutputBuffer = i2cStreamLink->outputBuffer;
        OutputStream* i2cOutputStream = getOutputStream(i2cOutputBuffer);
    
        addOutputStream(&driverToI2CSlaveAndDebugCompositeOutputStream, i2cOutputStream);
    } 
}
Example #14
0
	UtlXMLStream::UtlXMLStream(const std::string& sFileName, const bool bModeRead) : _bOwnerOfFileStream(true), _pInputStream(NULL), _pOutputStream(NULL) {
		if (!bModeRead) {
			_pOutputStream = CodeWorker::openOutputFile(sFileName.c_str());
			if (_pOutputStream == NULL) throw UtlException("unable to open file \"" + sFileName + "\" for writing");
				getOutputStream() << "<?xml version=\"1.0\" ?>" << std::endl;
		}
		else {
			_pInputStream = ScpStream::openSTLInputFile(sFileName.c_str());
			if (_pInputStream == NULL) throw UtlException("unable to open file \"" + sFileName + "\" for reading");
			

			std::string sLineVersion;
			if ( ! readLine(getInputStream() , sLineVersion) ) {
				throw UtlException("No version line in XML file: " + sFileName );
			}
		}
		
		_sFileName=sFileName;

	}
Example #15
0
                    jbool JConnection::openConnection(){
                        if (!opened){
                            opened=true;
                            getOutputStream();
                            out->writeInt(JTransportConfiguration::MAGIC_NUMBER);
                            connections->getTransport()->getLocalEndPoint()->write(out);
                            out->flush();

                            if (isReusable()){
                                jint oldTimeout=socket->getSoTimeout();
                                if (connections==NULL){
                                    socket->setSoTimeout(transport->getTransportConfiguration()->getPingTimeout()->get());
                                }else{
                                    socket->setSoTimeout(connections->getTransport()->getTransportConfiguration()->getPingTimeout()->get());
                                }
                                jbool b=readOk();
                                socket->setSoTimeout(oldTimeout);
                                return b;
                            }
                        }
                        return true;
                    }
Example #16
0
	void UtlXMLStream::writeEndOfAssociation(const std::string& sOwnerClass, const std::string& sName) {
		_sIndentation = _sIndentation.substr(1);
		getOutputStream() << _sIndentation.c_str() << "</" << sOwnerClass.c_str() << "_" << sName.c_str() << ">" << std::endl;
	}
Example #17
0
	void UtlXMLStream::writeObjectReference(const std::string& sTypeName, const std::string& /*sIDAttrName*/, const std::string& sIdentifier) {
		getOutputStream() << _sIndentation.c_str() << "<reference type=\"" << sTypeName.c_str() << "\" ID=\"" << sIdentifier.c_str() << "\" />" << std::endl;
	}
Example #18
0
 void JConnection::finishCall(){
     getOutputStream();
     out->flush();
 }
Example #19
0
 void JConnection::startCall(){
     getOutputStream();
     out->writeByte((jint)JTransportConfiguration::MSG_TYPE_CALL);
 }
Example #20
0
	void UtlXMLStream::writeTag(const std::string& sTag) {
		getOutputStream() << _sIndentation.c_str() << "<" << sTag.c_str() << "/>" << std::endl;
	}
Example #21
0
 void print(First first, Args...args)
 {
   getOutputStream() << first;
   print(args...);
 }
Example #22
0
	void UtlXMLStream::writeStartTag(const std::string& sTag) {
		getOutputStream() << _sIndentation.c_str() << "<" << sTag.c_str() << ">" << std::endl;
		_sIndentation += "\t";
	}
bool handleStreamInstruction(Buffer* inputBuffer,
                            Buffer* outputBuffer,
                            OutputStream* outputStream,
                            filterCharFunction* inputFilterChar,
                            filterCharFunction* outputFilterChar) {

    if (inputBuffer == NULL) {
        writeError(DRIVER_STREAM_LISTENER_INPUT_BUFFER_NULL);
        return false;
    }
    if (outputBuffer == NULL) {
        writeError(DRIVER_STREAM_LISTENER_OUTPUT_BUFFER_NULL);
        return false;
    }

    // Try to clear the buffer if needed ('z' char)
    if (clearBufferIfNeeded(inputBuffer)) {
        return false;
    }

    // We received data
    int inputBufferCount = getBufferElementsCount(inputBuffer);

    if (inputBufferCount > 0) {

        if (filterFirstNextChar(inputBuffer, inputFilterChar)) {
            return false;
        }

        // As there is clear of char filtering, we must reload the size of the buffer
        int bufferSize = getBufferElementsCount(inputBuffer);

        if (bufferSize < DEVICE_HEADER_LENGTH) {
            return false;
        }

        // Get the header
        unsigned char deviceHeader = bufferGetCharAtIndex(inputBuffer, DEVICE_HEADER_INDEX);

        // Manage the dispatcher specifier (3 chars : Ex j01 before real command ...)
        unsigned char specifyDispatcherLength = 0;
        if (deviceHeader == DATA_DISPATCHER_DEVICE_HEADER) {
            specifyDispatcherLength += DISPATCHER_COMMAND_AND_INDEX_HEADER_LENGTH;
        }

        // Check if enough data
        if (bufferSize < specifyDispatcherLength + DEVICE_AND_COMMAND_HEADER_LENGTH) {
            return false;
        }

        // Reload the deviceHeader to take the dispatcher specifier if any
        deviceHeader = bufferGetCharAtIndex(inputBuffer, specifyDispatcherLength + DEVICE_HEADER_INDEX);
        unsigned char commandHeader = bufferGetCharAtIndex(inputBuffer, specifyDispatcherLength + COMMAND_HEADER_INDEX);

        // find the device corresponding to this header. It must at least be declared in local or in remote !
        unsigned char dataSize = bufferSize - specifyDispatcherLength;
        const Device* device = deviceDataDispatcherFindDevice(deviceHeader, commandHeader, dataSize, DEVICE_MODE_INPUT);

        // if the device was not found
        if (device == NULL) {
            return false;
        }

        // At this moment, device Interface is found
        DeviceInterface* deviceInterface = device->deviceInterface;

        // We must send device specifyDispatcherLength + Header + commandHeader + data => + 2
        int dataToTransferCount = deviceInterface->deviceGetInterface(commandHeader, DEVICE_MODE_INPUT, false) + specifyDispatcherLength + DEVICE_AND_COMMAND_HEADER_LENGTH;

        if (bufferSize < dataToTransferCount) {
            return false;
        }

        // We must receive ack + device header + command header + data => + 3
        int dataToReceiveCount = deviceInterface->deviceGetInterface(commandHeader, DEVICE_MODE_OUTPUT, false) + ACK_LENGTH + DEVICE_AND_COMMAND_HEADER_LENGTH;

        InputStream* bufferedInputStream = getInputStream(inputBuffer);
        OutputStream* bufferedOutputStream = getOutputStream(outputBuffer);

        TransmitMode transmitMode = device->transmitMode;

        // we handle locally the request
        if (specifyDispatcherLength == 0 && transmitMode == TRANSMIT_LOCAL) {

            // We need the implementation for local mode
            DeviceDescriptor* deviceDescriptor = device->descriptor;
            if (deviceDescriptor == NULL) {
                writeError(NO_DEVICE_DESC_FOUND_FOR);
                append(getErrorOutputStreamLogger(), deviceHeader);
                append(getErrorOutputStreamLogger(), commandHeader);
                return false;
            }

            // remove the first chars corresponding to the device header and command Header
            bufferClearLastChars(inputBuffer, DEVICE_AND_COMMAND_HEADER_LENGTH);

            // Call to the device
            deviceDescriptor->deviceHandleRawData(commandHeader, bufferedInputStream, bufferedOutputStream);

        } // we forward the request through Remote Operation with Dispatcher
        else if (specifyDispatcherLength > 0 || transmitMode == TRANSMIT_I2C || transmitMode == TRANSMIT_UART || transmitMode == TRANSMIT_ZIGBEE) {

            // Find dispatcher
            DriverDataDispatcher* dispatcher = NULL;

            if (specifyDispatcherLength > 0) {
                bufferClearLastChars(inputBuffer, DEVICE_HEADER_LENGTH);
                unsigned char dispatcherIndex = readHex2(bufferedInputStream);

                dispatcher = getDriverDataDispatcherByIndex(dispatcherIndex);
                if (dispatcher == NULL) {
                    writeError(NO_DISPATCHER_FOUND);
                    OutputStream* errorOutputStream = getErrorOutputStreamLogger();
                    appendStringAndDec(errorOutputStream, ", dispatcherIndex=", dispatcherIndex);
                    return false;
                }
            }
            else {
                TransmitMode transmitMode = device->transmitMode;
                int address = device->address;

                dispatcher = getDriverDataDispatcherByTransmitMode(transmitMode, address);
                
                if (dispatcher == NULL) {
                    writeError(NO_DISPATCHER_FOUND);
                    OutputStream* errorOutputStream = getErrorOutputStreamLogger();
                    appendStringAndDec(errorOutputStream, ", transmitMode=", transmitMode);
                    append(errorOutputStream, '(');
                    appendString(errorOutputStream, getTransmitModeAsString(transmitMode));
                    append(errorOutputStream, ')');
                    appendStringAndDec(errorOutputStream, ", addr=", address);
                    return false;
                }
            }

            // copy Driver buffer with remote Call
            dispatcher->driverDataDispatcherTransmitData(dispatcher,
                    inputBuffer,
                    outputBuffer,
                    dataToTransferCount,
                    dataToReceiveCount
                    );
        }
        
        // In All Cases (Local / I2C / UART / Zigbee ...)

        // Copy the data from bufferOutputStream to the outputStream
        if (outputStream != NULL) {
            copyInputToOutputStream(&(outputBuffer->inputStream), outputStream, outputFilterChar, dataToReceiveCount);
        }
        return true;
    }
    return false;
}
Example #24
0
	void UtlXMLStream::writeBeginningOfObject(const std::string& sTypeName) {
		getOutputStream() << _sIndentation.c_str() << "<" << sTypeName.c_str();
		_sIndentation += "\t";
	}
Example #25
0
	void UtlXMLStream::writeBeginningOfAssociation(const std::string& sOwnerClass, const std::string& sName) {
		getOutputStream() << _sIndentation.c_str() << "<" << sOwnerClass.c_str() << "_" << sName.c_str() << ">" << std::endl;
		_sIndentation += "\t";
	}
Example #26
0
void Logger::endLog()
{
  getOutputStream() << std::endl;
}
Example #27
0
 void print(First&& first, Args&&...args)
 {
     getOutputStream() << first;
     print(std::forward<Args>(args)...);
 }
Example #28
0
	void UtlXMLStream::writeEndTag(const std::string& sTag) {
		_sIndentation = _sIndentation.substr(1);
		getOutputStream() << _sIndentation.c_str() << "</" << sTag.c_str() << ">" << std::endl;
	}
void
CClientProxy1_1::keyUp(KeyID key, KeyModifierMask mask, KeyButton button)
{
	LOG((CLOG_DEBUG1 "send key up to \"%s\" id=%d, mask=0x%04x, button=0x%04x", getName().c_str(), key, mask, button));
	CProtocolUtil::writef(getOutputStream(), kMsgDKeyUp, key, mask, button);
}
/**
 * Function Name: SI2C1Interrupt
 * Description : This is the ISR for I2C1 Slave interrupt.
 */
void __ISR(_I2C_1_VECTOR, ipl3) _SlaveI2CHandler(void)
{
    // TODO : Find the right i2cBusConnection
    I2cBusConnection* i2cBusConnection = NULL;

    // last byte received is address and not data
    char isData = I2C1STATbits.D_A;
    char read = I2C1STATbits.R_W;
    char isStart = I2C1STATbits.S;
    char isSclRelease = I2C1CONbits.SCLREL;
    char readBufferFull = I2C1STATbits.RBF;

    // check for MASTER and Bus events and respond accordingly
    if (IFS0bits.I2C1MIF == 1) {
        mI2C1MClearIntFlag();
        return;
    }
    if (IFS0bits.I2C1BIF == 1) {
        mI2C1BClearIntFlag();
        return;
    }
    StreamLink* i2cStreamLink = getI2cStreamLink();

    // handle the incoming message

    // Master want to write and send the address
    if (isStart && !read && !isData && readBufferFull) {
        // R/W bit = 0 --> indicates data transfer is input to slave
        // D/A bit = 0 --> indicates last byte was address

        // reset any state variables needed by a message sequence
        // perform a dummy read of the address
        portableSlaveReadI2C(i2cBusConnection);
        
        // release the clock to restart I2C
        portableSlaveClockRelease(i2cBusConnection);
    }
    // Master WRITE (InputStream)
    else if (isStart && !read && isData && readBufferFull) {
        // R/W bit = 0 --> indicates data transfer is input to slave
        // D/A bit = 1 --> indicates last byte was data
        int data = portableSlaveReadI2C(i2cBusConnection);
        Buffer* i2cSlaveInputBuffer = i2cStreamLink->inputBuffer;
        OutputStream* outputStream = getOutputStream(i2cSlaveInputBuffer);
        // Read data from the Master
        append(outputStream, data);
        // for debug support
        appendI2cDebugInputChar(data);
  
        // release the clock to restart I2C
        portableSlaveClockRelease(i2cBusConnection);
    }
    // Master send the address and want to read
    else if (isStart && read && !isData) {
        // R/W bit = 1 --> indicates data transfer is output from slave
        // D/A bit = 0 --> indicates last byte was address
        portableSlaveReadI2C(i2cBusConnection);
        
        Buffer* i2cSlaveOutputBuffer = i2cStreamLink->outputBuffer;
        // Get an inputStream to read the buffer to send to the master
        InputStream* i2cInputStream = getInputStream(i2cSlaveOutputBuffer);

        // There is available data
        if (i2cInputStream->availableData(i2cInputStream)) {
            char c = i2cInputStream->readChar(i2cInputStream);
            // for debug support
            appendI2cDebugOutputChar(c);
            portableSlaveWriteI2C(i2cBusConnection, c);
        } else {
            portableSlaveWriteI2C(i2cBusConnection, I2C_SLAVE_NO_DATA_IN_READ_BUFFER);
        } 
    }
    // Master want to read
    else if (isStart && read && isData && !isSclRelease) {

        // R/W bit = 1 --> indicates data transfer is output from slave
        // D/A bit = 1 --> indicates last byte was data
        Buffer* i2cSlaveOutputBuffer = i2cStreamLink->outputBuffer;
        // Get an inputStream to read the buffer to send to the master
        InputStream* i2cInputStream = getInputStream(i2cSlaveOutputBuffer);

        // There is available data
        if (i2cInputStream->availableData(i2cInputStream)) {
            char c = i2cInputStream->readChar(i2cInputStream);
            // for debug support
            appendI2cDebugInputChar(c);
            // we send it to the master
            portableSlaveWriteI2C(i2cBusConnection, c);
        } else {
            // There is no data, we send it to the master
            portableSlaveWriteI2C(i2cBusConnection, I2C_SLAVE_NO_DATA_IN_READ_BUFFER);
        }
    }
    // finally clear the slave interrupt flag
    mI2C1SClearIntFlag();
}