JNIEXPORT void JNICALL native_onNotificationsRegisterError(JNIEnv* env, jclass clazz, jstring message) 
{
	AutoJniStringBuffer messageBuffer(env, message);
    g_errorMessage = std::string(messageBuffer.buffer);
	
	s3eEdkCallbacksEnqueue(S3E_EXT_PUSHWOOSH_HASH, S3E_PUSHWOOSH_REGISTRATION_ERROR, (char *)g_errorMessage.c_str());
}
void PacketSocket::readBody()
{
    QByteArray messageBuffer(_header.message_len(), 0);
    int res = _socket->read(messageBuffer.data(), _header.message_len());
    if (res != _header.message_len()) {
        qDebug() << "res=" << res;
        qDebug() << "msg len=" << _header.message_len();
        qFatal("unable to read packet");
    }

    //qDebug() << "Received message, type id: " << _header.message_type() << "req id: " << _header.request_id();

    // ok, message readed, try dispatching it
    HandlerKey key = qMakePair(_header.message_type(), _header.request_id());
    auto i = _handlers.find(key);
    if (i != _handlers.end()) {
        BaseDecoder* dec = *i;
        dec->onMessage(messageBuffer);
        if (dec->singleShot) {
            _handlers.erase(i);
        }
    } else {
        qDebug() << "Unhandled message, type id: " << _header.message_type() << "req id: " << _header.request_id();
    }

    _state = stateReadingHeader;
}
Example #3
0
void MyLib::Exception::CMyException::setMessage(const char* szFileName, int nLine, const char* szMessage, ...) {

	std::string message = szMessage;

	va_list args = {0};
    va_start(args, szMessage);
	int messageLength = (_vscprintf(szMessage, args) + 1) * sizeof(char);
	if(messageLength > 0) {
		std::vector<char> messageBuffer(messageLength, 0);
		if(_vsnprintf_s(&messageBuffer[0], messageBuffer.size(), _TRUNCATE, szMessage, args) > 0) {
			message = (char*)&messageBuffer[0];
		}
	}
    va_end(args);

	std::ostringstream oss;
	oss << "[" << (const char*)(strrchr(szFileName, '\\') + 1) << ":" << nLine << "]" << message;
	m_what = oss.str();
}
Example #4
0
PEGASUS_NAMESPACE_BEGIN

AnonymousPipe::Status AnonymousPipe::writeMessage (CIMMessage * message)
{
    PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::writeMessage");

    //
    // Serialize the request
    //
    CIMBuffer messageBuffer(4096);

    try
    {
        CIMBinMsgSerializer::serialize(messageBuffer, message);
    }
    catch (Exception & e)
    {
        PEG_TRACE((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
            "Failed to serialize message: %s",
            (const char*)e.getMessage().getCString()));
        PEG_METHOD_EXIT ();
        throw;
    }

    //
    // Write the serialized message to the pipe
    //
    Uint32 messageLength = messageBuffer.size();
    const char * messageData = messageBuffer.getData ();

    Status writeStatus =
        writeBuffer((const char*) &messageLength, sizeof(Uint32));

    if (writeStatus == STATUS_SUCCESS)
    {
        writeStatus = writeBuffer(messageData, messageLength);
    }

    PEG_METHOD_EXIT ();
    return writeStatus;
}
Example #5
0
int DerivedHandler::print()
{
	mexPrintf(messageBuffer());
	mexPrintf("\n");
	return 0;
}
Example #6
0
AnonymousPipe::Status AnonymousPipe::readMessage (CIMMessage * & message)
{
    PEG_METHOD_ENTER (TRC_OS_ABSTRACTION, "AnonymousPipe::readMessage");

    message = 0;

    //
    //  Read the message length
    //
    Uint32 messageLength;
    Status readStatus = readBuffer ((char *) &messageLength, sizeof (Uint32));

    if (readStatus != STATUS_SUCCESS)
    {
        PEG_METHOD_EXIT ();
        return readStatus;
    }

    if (messageLength == 0)
    {
        //
        //  Null message
        //
        PEG_METHOD_EXIT ();
        return STATUS_SUCCESS;
    }

    //
    //  Read the message data
    //
    // CIMBuffer uses realloc() and free() so the buffer must be allocated
    // with malloc().
    AutoPtr<char, FreeCharPtr> messageBuffer((char*)malloc(messageLength + 1));

    //
    //  We know a message is coming
    //  Keep reading even if interrupted
    //
    do
    {
        readStatus = readBuffer (messageBuffer.get (), messageLength);
    } while (readStatus == STATUS_INTERRUPT);

    if (readStatus != STATUS_SUCCESS)
    {
        PEG_METHOD_EXIT ();
        return readStatus;
    }

    try
    {
        //
        //  De-serialize the message
        //
        // CIMBuffer frees messageBuffer upon destruction.
        CIMBuffer buf(messageBuffer.release(), messageLength);
        message = CIMBinMsgDeserializer::deserialize(buf, messageLength);

        if (!message)
        {
            throw CIMException(CIM_ERR_FAILED, "deserialize() failed");
        }
    }
    catch (Exception & e)
    {
        //
        //  De-serialization failed
        //
        PEG_TRACE ((TRC_OS_ABSTRACTION, Tracer::LEVEL2,
            "Failed to de-serialize message: %s",
            (const char*)e.getMessage().getCString()));
        PEG_METHOD_EXIT ();
        throw;
    }

    PEG_METHOD_EXIT ();
    return readStatus;
}
void
CLogSvcServer::ProcessReceivedData( TClientInfo& clientInfo                   ,
                                    COMCORE::CTCPServerConnection* connection )
{GUCEF_TRACE;

    // Cycle as long as we have buffered data and no errors occur
    bool noError = true;
    while ( clientInfo.receiveBuffer.HasBufferedData() )
    {
        // First read the message delimiter if its fully available
        char msgDelimterHeader[ 5 ];
        if ( 5 == clientInfo.receiveBuffer.PeekElement( msgDelimterHeader, 5 ) )
        {
            if ( msgDelimterHeader[ 0 ] == LOGSVCMSGTYPE_DELIMITER )
            {
                // Get the total message length from the delimiter header
                CORE::UInt32 msgLength = 0;
                memcpy( &msgLength, msgDelimterHeader+1, 4 );

                // Perform a sanity check
                // Server side we limit the length of the message we will accept from the client
                if ( msgLength <= MAX_ACCEPTED_MSGLENGTH )
                {
                    // Check to see if the buffer actually has the data available already to form the complete message
                    if ( msgLength+5 <= clientInfo.receiveBuffer.GetBufferedDataSizeInBytes() )
                    {
                        // Since we already got he header data via a Peek() we will skip that data now
                        if ( 5 != clientInfo.receiveBuffer.SkipRead( 5 ) )
                        {
                            // This should not happen
                            GUCEF_ERROR_LOG( CORE::LOGLEVEL_BELOW_NORMAL, "CLogSvcServer: Unable to Skip buffered data" );
                            connection->Close();
                            return;
                        }

                        // Make a buffer for this message and read it from the receive buffer
                        CORE::CDynamicBuffer messageBuffer( msgLength, false );
                        if ( msgLength == clientInfo.receiveBuffer.Read( messageBuffer.GetBufferPtr(), msgLength, 1 ) )
                        {
                            // Set the size of usefull data in the buffer
                            messageBuffer.SetDataSize( msgLength );

                            // Process this single message
                            ProcessReceivedMessage( clientInfo    ,
                                                    connection    ,
                                                    messageBuffer );
                        }
                        else
                        {
                            // This should not happen
                            GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CLogSvcServer: Unable to Read() buffered data" );
                            connection->Close();
                            return;
                        }
                    }
                    else
                    {
                        // We don't have all the data yet to read this message, we will wait for more data to come in
                        return;
                    }
                }
                else
                {
                    // This connection is misbehaving
                    GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CLogSvcServer: A message was received which exceeded the max msg size, disconnecting client" );
                    connection->Close();
                    return;
                }
            }
        }
    }
}