aboutsummaryrefslogtreecommitdiffstats
path: root/remote-processor
diff options
context:
space:
mode:
Diffstat (limited to 'remote-processor')
-rw-r--r--remote-processor/Android.mk39
-rw-r--r--remote-processor/AnswerMessage.cpp85
-rw-r--r--remote-processor/AnswerMessage.h59
-rw-r--r--remote-processor/ConnectionSocket.cpp73
-rw-r--r--remote-processor/ConnectionSocket.h47
-rw-r--r--remote-processor/ListeningSocket.cpp92
-rw-r--r--remote-processor/ListeningSocket.h46
-rw-r--r--remote-processor/Message.cpp267
-rw-r--r--remote-processor/Message.h81
-rw-r--r--remote-processor/RemoteCommand.h46
-rw-r--r--remote-processor/RemoteCommandHandler.h41
-rw-r--r--remote-processor/RemoteProcessorProtocol.h40
-rw-r--r--remote-processor/RemoteProcessorServer.cpp203
-rw-r--r--remote-processor/RemoteProcessorServer.h72
-rw-r--r--remote-processor/RemoteProcessorServerBuilder.cpp41
-rw-r--r--remote-processor/RemoteProcessorServerInterface.h43
-rw-r--r--remote-processor/RequestMessage.cpp137
-rw-r--r--remote-processor/RequestMessage.h68
-rw-r--r--remote-processor/Socket.cpp139
-rw-r--r--remote-processor/Socket.h66
20 files changed, 1685 insertions, 0 deletions
diff --git a/remote-processor/Android.mk b/remote-processor/Android.mk
new file mode 100644
index 0000000..e55b158
--- /dev/null
+++ b/remote-processor/Android.mk
@@ -0,0 +1,39 @@
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)
+
+LOCAL_SRC_FILES:= \
+ Socket.cpp \
+ ListeningSocket.cpp \
+ ConnectionSocket.cpp \
+ Message.cpp \
+ RequestMessage.cpp \
+ AnswerMessage.cpp \
+ RemoteProcessorServer.cpp \
+ RemoteProcessorServerBuilder.cpp
+
+LOCAL_MODULE:= libremote-processor
+
+LOCAL_MODULE_TAGS := optional
+
+TARGET_ERROR_FLAGS += -Wno-non-virtual-dtor
+
+LOCAL_C_INCLUDES +=
+
+LOCAL_C_INCLUDES += \
+ external/stlport/stlport/ \
+ bionic/libstdc++ \
+ bionic/
+
+LOCAL_C_INCLUDES +=
+
+LOCAL_SHARED_LIBRARIES := libstlport libicuuc
+LOCAL_STATIC_LIBRARIES :=
+
+LOCAL_LDLIBS +=
+
+
+include $(BUILD_SHARED_LIBRARY)
+
diff --git a/remote-processor/AnswerMessage.cpp b/remote-processor/AnswerMessage.cpp
new file mode 100644
index 0000000..60bf750
--- /dev/null
+++ b/remote-processor/AnswerMessage.cpp
@@ -0,0 +1,85 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "AnswerMessage.h"
+#include "RemoteProcessorProtocol.h"
+#include <assert.h>
+
+#define base CMessage
+
+CAnswerMessage::CAnswerMessage(const string& strAnswer, bool bSuccess) : base(bSuccess ? ESuccessAnswer : EFailureAnswer), _strAnswer(strAnswer)
+{
+}
+
+CAnswerMessage::CAnswerMessage()
+{
+}
+
+// Answer
+void CAnswerMessage::setAnswer(const string& strAnswer)
+{
+ _strAnswer = strAnswer;
+}
+
+const string& CAnswerMessage::getAnswer() const
+{
+ return _strAnswer;
+}
+
+// Status
+bool CAnswerMessage::success() const
+{
+ return getMsgId() == ESuccessAnswer;
+}
+
+// Size
+uint32_t CAnswerMessage::getDataSize() const
+{
+ // Answer
+ return getStringSize(getAnswer());
+}
+
+// Fill data to send
+void CAnswerMessage::fillDataToSend()
+{
+ // Send answer
+ writeString(getAnswer());
+}
+
+// Collect received data
+void CAnswerMessage::collectReceivedData()
+{
+ // Receive answer
+ string strAnswer;
+
+ readString(strAnswer);
+
+ setAnswer(strAnswer);
+}
diff --git a/remote-processor/AnswerMessage.h b/remote-processor/AnswerMessage.h
new file mode 100644
index 0000000..16259a6
--- /dev/null
+++ b/remote-processor/AnswerMessage.h
@@ -0,0 +1,59 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include "Message.h"
+
+class CAnswerMessage : public CMessage
+{
+public:
+ CAnswerMessage(const string& strAnswer, bool bSuccess);
+ CAnswerMessage();
+
+ // Answer
+ const string& getAnswer() const;
+
+ // Status
+ bool success() const;
+private:
+ // Fill data to send
+ virtual void fillDataToSend();
+ // Collect received data
+ virtual void collectReceivedData();
+ // Size
+ virtual uint32_t getDataSize() const;
+ // Answer
+ void setAnswer(const string& strAnswer);
+
+ // Answer
+ string _strAnswer;
+};
+
diff --git a/remote-processor/ConnectionSocket.cpp b/remote-processor/ConnectionSocket.cpp
new file mode 100644
index 0000000..4a0357e
--- /dev/null
+++ b/remote-processor/ConnectionSocket.cpp
@@ -0,0 +1,73 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "ConnectionSocket.h"
+#include <unistd.h>
+#include <netdb.h>
+#include <netinet/in.h>
+#include <stdio.h>
+#include <errno.h>
+
+#define base CSocket
+
+CConnectionSocket::CConnectionSocket()
+{
+}
+
+// Connection
+bool CConnectionSocket::connect(const string& strRemote, uint16_t uiPort, string& strError)
+{
+ struct sockaddr_in server_addr;
+
+ // Host entry
+ struct hostent* host = gethostbyname(strRemote.c_str());
+
+ // Check host
+ if (!host) {
+
+ strError = "Target not found :-(";
+
+ return false;
+ }
+
+ // Fill server address
+ initSockAddrIn(&server_addr, *((uint32_t*)host->h_addr), uiPort);
+
+ // Connect
+ if (::connect(getFd(), (struct sockaddr *)&server_addr, sizeof(struct sockaddr))) {
+
+ perror("CConnectionSocket::connect::connect");
+
+ strError = "Unable to connnect to target :-(";
+
+ return false;
+ }
+ return true;
+}
diff --git a/remote-processor/ConnectionSocket.h b/remote-processor/ConnectionSocket.h
new file mode 100644
index 0000000..e0d6064
--- /dev/null
+++ b/remote-processor/ConnectionSocket.h
@@ -0,0 +1,47 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include "Socket.h"
+
+#include <string>
+
+using namespace std;
+
+class CConnectionSocket : public CSocket
+{
+public:
+ CConnectionSocket();
+
+ // Connection
+ bool connect(const string& strRemote, uint16_t uiPort, string& strError);
+};
+
diff --git a/remote-processor/ListeningSocket.cpp b/remote-processor/ListeningSocket.cpp
new file mode 100644
index 0000000..df5d369
--- /dev/null
+++ b/remote-processor/ListeningSocket.cpp
@@ -0,0 +1,92 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "ListeningSocket.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <assert.h>
+#include <netdb.h>
+#include <strings.h>
+
+#include <stdio.h>
+#include <errno.h>
+
+#define base CSocket
+
+CListeningSocket::CListeningSocket()
+{
+ int iOption = true;
+ // Reuse option
+ setsockopt(getFd(), SOL_SOCKET, SO_REUSEADDR, &iOption, sizeof(iOption));
+}
+
+// Listen
+bool CListeningSocket::listen(uint16_t uiPort)
+{
+ struct sockaddr_in server_addr;
+
+ // Fill server address
+ initSockAddrIn(&server_addr, INADDR_ANY, uiPort);
+
+ // Bind
+ if (bind(getFd(), (struct sockaddr*)&server_addr, sizeof(struct sockaddr)) == -1) {
+
+ perror("CListeningSocket::listen::bind");
+
+ return false;
+ }
+
+ if (::listen(getFd(), 5) == -1) {
+
+ perror("CListeningSocket::listen::bind");
+
+ return false;
+ }
+ return true;
+}
+
+// Accept
+CSocket* CListeningSocket::accept()
+{
+ struct sockaddr_in client_addr;
+ socklen_t ulClientAddrLen = sizeof(client_addr);
+
+ int iSockId = ::accept(getFd(), (struct sockaddr*)&client_addr, &ulClientAddrLen);
+
+ if (iSockId == -1) {
+
+ perror("CListeningSocket::accept::accept");
+
+ return NULL;
+ }
+ return new CSocket(iSockId);
+}
diff --git a/remote-processor/ListeningSocket.h b/remote-processor/ListeningSocket.h
new file mode 100644
index 0000000..a242a73
--- /dev/null
+++ b/remote-processor/ListeningSocket.h
@@ -0,0 +1,46 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include "Socket.h"
+
+class CListeningSocket : public CSocket
+{
+public:
+ CListeningSocket();
+
+ // Listen
+ bool listen(uint16_t uiPort);
+
+ // Accept
+ CSocket* accept();
+};
+
diff --git a/remote-processor/Message.cpp b/remote-processor/Message.cpp
new file mode 100644
index 0000000..5679501
--- /dev/null
+++ b/remote-processor/Message.cpp
@@ -0,0 +1,267 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "Message.h"
+#include <assert.h>
+#include "Socket.h"
+#include "RemoteProcessorProtocol.h"
+#include <string.h>
+#include <assert.h>
+
+CMessage::CMessage(uint8_t ucMsgId) : _ucMsgId(ucMsgId), _pucData(NULL), _uiDataSize(0), _uiIndex(0)
+{
+}
+
+CMessage::CMessage() : _ucMsgId(-1), _pucData(NULL), _uiDataSize(0), _uiIndex(0)
+{
+}
+
+CMessage::~CMessage()
+{
+ delete [] _pucData;
+}
+
+// Msg Id
+uint8_t CMessage::getMsgId() const
+{
+ return _ucMsgId;
+}
+
+// Data
+void CMessage::writeData(const void* pvData, uint32_t uiSize)
+{
+ assert(_uiIndex + uiSize <= _uiDataSize);
+
+ // Copy
+ memcpy(&_pucData[_uiIndex], pvData, uiSize);
+
+ // Index
+ _uiIndex += uiSize;
+}
+
+void CMessage::readData(void* pvData, uint32_t uiSize)
+{
+ assert(_uiIndex + uiSize <= _uiDataSize);
+
+ // Copy
+ memcpy(pvData, &_pucData[_uiIndex], uiSize);
+
+ // Index
+ _uiIndex += uiSize;
+}
+
+void CMessage::writeString(const string& strData)
+{
+ // Size
+ uint32_t uiSize = strData.length();
+
+ writeData(&uiSize, sizeof(uiSize));
+
+ // Content
+ writeData(strData.c_str(), uiSize);
+}
+
+void CMessage::readString(string& strData)
+{
+ // Size
+ uint32_t uiSize;
+
+ readData(&uiSize, sizeof(uiSize));
+
+ // Data
+ char* pcData = new char[uiSize + 1];
+
+ // Content
+ readData(pcData, uiSize);
+
+ // NULL-terminate string
+ pcData[uiSize] = '\0';
+
+ // Output
+ strData = pcData;
+
+ // Delete
+ delete [] pcData;
+}
+
+uint32_t CMessage::getStringSize(const string& strData) const
+{
+ // Return string length plus room to store its length
+ return strData.length() + sizeof(uint32_t);
+}
+
+// Remaining data size
+uint32_t CMessage::getRemainingDataSize() const
+{
+ return _uiDataSize - _uiIndex;
+}
+
+// Send/Receive
+bool CMessage::serialize(CSocket* pSocket, bool bOut)
+{
+ if (bOut) {
+
+ // Make room for data to send
+ allocateData(getDataSize());
+
+ // Get data from derived
+ fillDataToSend();
+
+ // Finished providing data?
+ assert(_uiIndex == _uiDataSize);
+
+ // First send sync word
+ uint16_t uiSyncWord = SYNC_WORD;
+
+ if (!pSocket->write(&uiSyncWord, sizeof(uiSyncWord))) {
+
+ return false;
+ }
+
+ // Size
+ uint32_t uiSize = sizeof(_ucMsgId) + _uiDataSize;
+
+ if (!pSocket->write(&uiSize, sizeof(uiSize))) {
+
+ return false;
+ }
+
+ // Msg Id
+ if (!pSocket->write(&_ucMsgId, sizeof(_ucMsgId))) {
+
+ return false;
+ }
+
+ // Data
+ if (!pSocket->write(_pucData, _uiDataSize)) {
+
+ return false;
+ }
+
+ // Checksum
+ uint8_t ucChecksum = computeChecksum();
+
+ if (!pSocket->write(&ucChecksum, sizeof(ucChecksum))) {
+
+ return false;
+ }
+
+ } else {
+ // First read sync word
+ uint16_t uiSyncWord;
+
+ if (!pSocket->read(&uiSyncWord, sizeof(uiSyncWord))) {
+
+ return false;
+ }
+
+ // Check Sync word
+ if (uiSyncWord != SYNC_WORD) {
+
+ return false;
+ }
+
+ // Size
+ uint32_t uiSize;
+
+ if (!pSocket->read(&uiSize, sizeof(uiSize))) {
+
+ return false;
+ }
+
+ // Msg Id
+ if (!pSocket->read(&_ucMsgId, sizeof(_ucMsgId))) {
+
+ return false;
+ }
+
+ // Data
+
+ // Allocate
+ allocateData(uiSize - sizeof(_ucMsgId));
+
+ // Data receive
+ if (!pSocket->read(_pucData, _uiDataSize)) {
+
+ return false;
+ }
+
+ // Checksum
+ uint8_t ucChecksum;
+
+ if (!pSocket->read(&ucChecksum, sizeof(ucChecksum))) {
+
+ return false;
+ }
+ // Compare
+ if (ucChecksum != computeChecksum()) {
+
+ return false;
+ }
+
+ // Collect data in derived
+ collectReceivedData();
+ }
+
+ return true;
+}
+
+// Checksum
+uint8_t CMessage::computeChecksum() const
+{
+ uint8_t uiChecksum = (_ucMsgId & 0xFF) + (_ucMsgId >> 8);
+
+ uint32_t uiIndex;
+
+ for (uiIndex = 0; uiIndex < _uiDataSize; uiIndex++) {
+
+ uiChecksum += _pucData[uiIndex];
+ }
+
+ return uiChecksum;
+}
+
+// Data allocation
+void CMessage::allocateData(uint32_t uiSize)
+{
+ // Remove previous one
+ if (_pucData) {
+
+ delete [] _pucData;
+ }
+ // Do allocate
+ _pucData = new uint8_t[uiSize];
+
+ // Record size
+ _uiDataSize = uiSize;
+
+ // Reset Index
+ _uiIndex = 0;
+}
diff --git a/remote-processor/Message.h b/remote-processor/Message.h
new file mode 100644
index 0000000..4ab6a2b
--- /dev/null
+++ b/remote-processor/Message.h
@@ -0,0 +1,81 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include <stdint.h>
+#include <string>
+
+using namespace std;
+
+class CSocket;
+
+class CMessage
+{
+public:
+ CMessage(uint8_t ucMsgId);
+ CMessage();
+ virtual ~CMessage();
+
+ // Send/Receive
+ bool serialize(CSocket* pSocket, bool bOut);
+
+protected:
+ // Msg Id
+ uint8_t getMsgId() const;
+ // Data
+ void writeData(const void* pvData, uint32_t uiSize);
+ void readData(void* pvData, uint32_t uiSize);
+ void writeString(const string& strData);
+ void readString(string& strData);
+ uint32_t getStringSize(const string& strData) const;
+ // Remaining data size
+ uint32_t getRemainingDataSize() const;
+private:
+ // Data allocation
+ void allocateData(uint32_t uiDataSize);
+ // Fill data to send
+ virtual void fillDataToSend() = 0;
+ // Collect received data
+ virtual void collectReceivedData() = 0;
+ // Size
+ virtual uint32_t getDataSize() const = 0;
+ // Checksum
+ uint8_t computeChecksum() const;
+
+ // MsgId
+ uint8_t _ucMsgId;
+ // Data
+ uint8_t* _pucData;
+ // Data size
+ uint32_t _uiDataSize;
+ // Read/Write Index
+ uint32_t _uiIndex;
+};
diff --git a/remote-processor/RemoteCommand.h b/remote-processor/RemoteCommand.h
new file mode 100644
index 0000000..8409468
--- /dev/null
+++ b/remote-processor/RemoteCommand.h
@@ -0,0 +1,46 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include <stdint.h>
+#include <string>
+
+class IRemoteCommand
+{
+public:
+ // Command Name
+ virtual const std::string& getCommand() const = 0;
+
+ // Arguments
+ virtual void addArgument(const std::string& strArgument) = 0;
+ virtual uint32_t getArgumentCount() const = 0;
+ virtual const std::string& getArgument(uint32_t uiArgument) const = 0;
+};
diff --git a/remote-processor/RemoteCommandHandler.h b/remote-processor/RemoteCommandHandler.h
new file mode 100644
index 0000000..4f1ab3d
--- /dev/null
+++ b/remote-processor/RemoteCommandHandler.h
@@ -0,0 +1,41 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include "RemoteCommand.h"
+#include <string>
+
+class IRemoteCommandHandler
+{
+public:
+ // Return true on success, fill result in any cases
+ virtual bool remoteCommandProcess(const IRemoteCommand& remoteCommand, std::string& strResult) = 0;
+};
diff --git a/remote-processor/RemoteProcessorProtocol.h b/remote-processor/RemoteProcessorProtocol.h
new file mode 100644
index 0000000..28f9bfb
--- /dev/null
+++ b/remote-processor/RemoteProcessorProtocol.h
@@ -0,0 +1,40 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#define SYNC_WORD 0xBABE
+
+enum RemoteProtocolMsgType
+{
+ ECommandRequest,
+ ESuccessAnswer,
+ EFailureAnswer
+};
diff --git a/remote-processor/RemoteProcessorServer.cpp b/remote-processor/RemoteProcessorServer.cpp
new file mode 100644
index 0000000..efe4342
--- /dev/null
+++ b/remote-processor/RemoteProcessorServer.cpp
@@ -0,0 +1,203 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "RemoteProcessorServer.h"
+#include "ListeningSocket.h"
+#include <assert.h>
+#include <poll.h>
+#include <unistd.h>
+#include <strings.h>
+#include "RequestMessage.h"
+#include "AnswerMessage.h"
+#include "RemoteCommandHandler.h"
+
+CRemoteProcessorServer::CRemoteProcessorServer(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler) :
+ _uiPort(uiPort), _pCommandHandler(pCommandHandler), _bIsStarted(false), _pListeningSocket(NULL), _ulThreadId(0)
+{
+ // Create inband pipe
+ pipe(_aiInbandPipe);
+}
+
+CRemoteProcessorServer::~CRemoteProcessorServer()
+{
+ stop();
+}
+
+// State
+bool CRemoteProcessorServer::start()
+{
+ assert(!_bIsStarted);
+
+ // Create server socket
+ _pListeningSocket = new CListeningSocket;
+
+ if (!_pListeningSocket->listen(_uiPort)) {
+
+ // Remove listening socket
+ delete _pListeningSocket;
+ _pListeningSocket = NULL;
+
+ return false;
+ }
+
+ // Create thread
+ pthread_create(&_ulThreadId, NULL, thread_func, this);
+
+ // State
+ _bIsStarted = true;
+
+ return true;
+}
+
+void CRemoteProcessorServer::stop()
+{
+ // Check state
+ if (!_bIsStarted) {
+
+ return;
+ }
+
+ // Cause exiting of the thread
+ uint8_t ucData = 0;
+ write(_aiInbandPipe[1], &ucData, sizeof(ucData));
+
+ // Join thread
+ pthread_join(_ulThreadId, NULL);
+
+ _bIsStarted = false;
+
+ // Remove listening socket
+ delete _pListeningSocket;
+ _pListeningSocket = NULL;
+}
+
+bool CRemoteProcessorServer::isStarted() const
+{
+ return _bIsStarted;
+}
+
+// Thread
+void* CRemoteProcessorServer::thread_func(void* pData)
+{
+ reinterpret_cast<CRemoteProcessorServer*>(pData)->run();
+
+ return NULL;
+}
+
+void CRemoteProcessorServer::run()
+{
+ struct pollfd _aPollFds[2];
+
+ bzero(_aPollFds, sizeof(_aPollFds));
+
+ // Build poll elements
+ _aPollFds[0].fd = _pListeningSocket->getFd();
+ _aPollFds[1].fd = _aiInbandPipe[0];
+ _aPollFds[0].events = POLLIN;
+ _aPollFds[1].events = POLLIN;
+
+ while (true) {
+
+ poll(_aPollFds, 2, -1);
+
+ if (_aPollFds[0].revents & POLLIN) {
+
+ // New incoming connection
+ handleNewConnection();
+ }
+ if (_aPollFds[1].revents & POLLIN) {
+
+ // Consume exit request
+ uint8_t ucData;
+ read(_aiInbandPipe[0], &ucData, sizeof(ucData));
+
+ // Exit
+ return;
+ }
+ }
+}
+
+// New connection
+void CRemoteProcessorServer::handleNewConnection()
+{
+ CSocket* pClientSocket = _pListeningSocket->accept();
+
+ if (!pClientSocket) {
+
+ return;
+ }
+
+ // Set timeout
+ pClientSocket->setTimeout(5000);
+
+ // Process all incoming requests from the client
+ while (true) {
+
+ // Process requests
+ // Create command message
+ CRequestMessage requestMessage;
+
+ ///// Receive command
+ if (!requestMessage.serialize(pClientSocket, false)) {
+
+ // Bail out
+ break;
+ }
+
+ // Actually process the request
+ bool bSuccess;
+
+ string strResult;
+
+ if (_pCommandHandler) {
+
+ bSuccess = _pCommandHandler->remoteCommandProcess(requestMessage, strResult);
+
+ } else {
+
+ strResult = "No handler!";
+
+ bSuccess = false;
+ }
+
+ // Send back answer
+ // Create answer message
+ CAnswerMessage answerMessage(strResult, bSuccess);
+
+ ///// Send answer
+ if (!answerMessage.serialize(pClientSocket, true)) {
+
+ // Bail out
+ break;
+ }
+ }
+ // Remove client socket
+ delete pClientSocket;
+}
diff --git a/remote-processor/RemoteProcessorServer.h b/remote-processor/RemoteProcessorServer.h
new file mode 100644
index 0000000..0abb5c8
--- /dev/null
+++ b/remote-processor/RemoteProcessorServer.h
@@ -0,0 +1,72 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include <stdint.h>
+#include <pthread.h>
+#include "RemoteProcessorServerInterface.h"
+
+class CListeningSocket;
+class IRemoteCommandHandler;
+
+class CRemoteProcessorServer : public IRemoteProcessorServerInterface
+{
+public:
+ CRemoteProcessorServer(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler);
+ virtual ~CRemoteProcessorServer();
+
+ // State
+ virtual bool start();
+ virtual void stop();
+ virtual bool isStarted() const;
+
+private:
+ // Thread
+ static void* thread_func(void* pData);
+ void run();
+
+ // New connection
+ void handleNewConnection();
+
+ // Port number
+ uint16_t _uiPort;
+ // Command handler
+ IRemoteCommandHandler* _pCommandHandler;
+ // State
+ bool _bIsStarted;
+ // Listening socket
+ CListeningSocket* _pListeningSocket;
+ // Inband pipe
+ int _aiInbandPipe[2];
+ // Thread
+ pthread_t _ulThreadId;
+};
+
diff --git a/remote-processor/RemoteProcessorServerBuilder.cpp b/remote-processor/RemoteProcessorServerBuilder.cpp
new file mode 100644
index 0000000..ed6b2c2
--- /dev/null
+++ b/remote-processor/RemoteProcessorServerBuilder.cpp
@@ -0,0 +1,41 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "RemoteProcessorServer.h"
+
+
+extern "C"
+{
+IRemoteProcessorServerInterface* createRemoteProcessorServer(uint16_t uiPort, IRemoteCommandHandler* pCommandHandler)
+{
+ return new CRemoteProcessorServer(uiPort, pCommandHandler);
+}
+}
+
diff --git a/remote-processor/RemoteProcessorServerInterface.h b/remote-processor/RemoteProcessorServerInterface.h
new file mode 100644
index 0000000..991d3db
--- /dev/null
+++ b/remote-processor/RemoteProcessorServerInterface.h
@@ -0,0 +1,43 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include "RequestMessage.h"
+
+using namespace std;
+
+class IRemoteProcessorServerInterface
+{
+public:
+ virtual bool start() = 0;
+ virtual void stop() = 0;
+ virtual bool isStarted() const = 0;
+};
diff --git a/remote-processor/RequestMessage.cpp b/remote-processor/RequestMessage.cpp
new file mode 100644
index 0000000..6f71b8a
--- /dev/null
+++ b/remote-processor/RequestMessage.cpp
@@ -0,0 +1,137 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "RequestMessage.h"
+#include "RemoteProcessorProtocol.h"
+#include <assert.h>
+#include <algorithm>
+#include <ctype.h>
+
+#define base CMessage
+
+CRequestMessage::CRequestMessage(const string& strCommand) : base(ECommandRequest), _strCommand(strCommand)
+{
+}
+
+CRequestMessage::CRequestMessage()
+{
+}
+
+// Command Name
+void CRequestMessage::setCommand(const string& strCommand)
+{
+ _strCommand = trim(strCommand);
+}
+
+const string& CRequestMessage::getCommand() const
+{
+ return _strCommand;
+}
+
+// Arguments
+void CRequestMessage::addArgument(const string& strArgument)
+{
+ _argumentVector.push_back(trim(strArgument));
+}
+
+uint32_t CRequestMessage::getArgumentCount() const
+{
+ return _argumentVector.size();
+}
+
+const string& CRequestMessage::getArgument(uint32_t uiArgument) const
+{
+ assert(uiArgument < _argumentVector.size());
+
+ return _argumentVector[uiArgument];
+}
+
+// Fill data to send
+void CRequestMessage::fillDataToSend()
+{
+ // Send command
+ writeString(getCommand());
+
+ // Arguments
+ uint32_t uiArgument;
+
+ for (uiArgument = 0; uiArgument < getArgumentCount(); uiArgument++) {
+
+ writeString(getArgument(uiArgument));
+ }
+}
+
+// Collect received data
+void CRequestMessage::collectReceivedData()
+{
+ // Receive command
+ string strCommand;
+
+ readString(strCommand);
+
+ setCommand(strCommand);
+
+ // Arguments
+ while (getRemainingDataSize()) {
+
+ string strArgument;
+
+ readString(strArgument);
+
+ addArgument(strArgument);
+ }
+}
+
+// Size
+uint32_t CRequestMessage::getDataSize() const
+{
+ // Command
+ uint32_t uiSize = getStringSize(getCommand());
+
+ // Arguments
+ uint32_t uiArgument;
+
+ for (uiArgument = 0; uiArgument < getArgumentCount(); uiArgument++) {
+
+ uiSize += getStringSize(getArgument(uiArgument));
+ }
+ return uiSize;
+}
+
+// Trim input string
+string CRequestMessage::trim(const string& strToTrim)
+{
+ // Trim string
+ string strTrimmed = strToTrim;
+
+ strTrimmed.erase(remove_if(strTrimmed.begin(), strTrimmed.end(), ::isspace), strTrimmed.end());
+
+ return strTrimmed;
+}
diff --git a/remote-processor/RequestMessage.h b/remote-processor/RequestMessage.h
new file mode 100644
index 0000000..c0b2183
--- /dev/null
+++ b/remote-processor/RequestMessage.h
@@ -0,0 +1,68 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include "Message.h"
+#include "RemoteCommand.h"
+#include <vector>
+
+class CRequestMessage : public CMessage, public IRemoteCommand
+{
+public:
+ CRequestMessage(const string& strCommand);
+ CRequestMessage();
+
+ // Command Name
+ virtual const string& getCommand() const;
+
+ // Arguments
+ virtual void addArgument(const string& strArgument);
+ virtual uint32_t getArgumentCount() const;
+ virtual const string& getArgument(uint32_t uiArgument) const;
+
+private:
+ // Fill data to send
+ virtual void fillDataToSend();
+ // Collect received data
+ virtual void collectReceivedData();
+ // Size
+ virtual uint32_t getDataSize() const;
+ // Command
+ void setCommand(const string& strCommand);
+ // Trim input string
+ static string trim(const string& strToTrim);
+
+ // Command
+ string _strCommand;
+ // Arguments
+ vector<string> _argumentVector;
+};
+
diff --git a/remote-processor/Socket.cpp b/remote-processor/Socket.cpp
new file mode 100644
index 0000000..f77cd45
--- /dev/null
+++ b/remote-processor/Socket.cpp
@@ -0,0 +1,139 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#include "Socket.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <assert.h>
+#include <netdb.h>
+#include <strings.h>
+#include <fcntl.h>
+#include <netinet/in.h>
+#include <sys/time.h>
+
+CSocket::CSocket() : _iSockFd(socket(AF_INET, SOCK_STREAM, 0))
+{
+ assert(_iSockFd != -1);
+}
+
+CSocket::CSocket(int iSockId) : _iSockFd(iSockId)
+{
+ assert(_iSockFd != -1);
+}
+
+CSocket::~CSocket()
+{
+ close(_iSockFd);
+}
+
+// Socket address init
+void CSocket::initSockAddrIn(struct sockaddr_in* pSockAddrIn, uint32_t uiInAddr, uint16_t uiPort) const
+{
+ // Fill server address
+ pSockAddrIn->sin_family = AF_INET;
+ pSockAddrIn->sin_port = htons(uiPort);
+ pSockAddrIn->sin_addr.s_addr = uiInAddr;
+ bzero(&pSockAddrIn->sin_zero, sizeof(pSockAddrIn->sin_zero));
+}
+
+// Non blocking state
+void CSocket::setNonBlocking(bool bNonBlocking)
+{
+ int iFlags = fcntl(_iSockFd, F_GETFL, 0);
+
+ assert(iFlags != -1);
+
+ if (bNonBlocking) {
+
+ iFlags |= O_NONBLOCK;
+ } else {
+
+ iFlags &= ~O_NONBLOCK;
+ }
+ fcntl(_iSockFd, F_SETFL, iFlags);
+}
+
+// Communication timeout
+void CSocket::setTimeout(uint32_t uiMilliseconds)
+{
+ struct timeval tv;
+ tv.tv_sec = uiMilliseconds / 1000;
+ tv.tv_usec = (uiMilliseconds % 1000) * 1000;
+
+ setsockopt(_iSockFd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+ setsockopt(_iSockFd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+}
+
+// Read
+bool CSocket::read(void* pvData, uint32_t uiSize)
+{
+ uint32_t uiOffset = 0;
+ uint8_t* pucData = (uint8_t*)pvData;
+
+ while (uiSize) {
+
+ int32_t iAccessedSize = ::recv(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
+
+ if (!iAccessedSize || iAccessedSize == -1) {
+
+ return false;
+ }
+ uiSize -= iAccessedSize;
+ uiOffset += iAccessedSize;
+ }
+ return true;
+}
+
+// Write
+bool CSocket::write(const void* pvData, uint32_t uiSize)
+{
+ uint32_t uiOffset = 0;
+ const uint8_t* pucData = (const uint8_t*)pvData;
+
+ while (uiSize) {
+
+ int32_t iAccessedSize = ::send(_iSockFd, &pucData[uiOffset], uiSize, MSG_NOSIGNAL);
+
+ if (!iAccessedSize || iAccessedSize == -1) {
+
+ return false;
+ }
+ uiSize -= iAccessedSize;
+ uiOffset += iAccessedSize;
+ }
+ return true;
+}
+
+// Fd
+int CSocket::getFd() const
+{
+ return _iSockFd;
+}
diff --git a/remote-processor/Socket.h b/remote-processor/Socket.h
new file mode 100644
index 0000000..4552dc5
--- /dev/null
+++ b/remote-processor/Socket.h
@@ -0,0 +1,66 @@
+/* <auto_header>
+ * <FILENAME>
+ *
+ * INTEL CONFIDENTIAL
+ * Copyright © 2011 Intel
+ * Corporation All Rights Reserved.
+ *
+ * The source code contained or described herein and all documents related to
+ * the source code ("Material") are owned by Intel Corporation or its suppliers
+ * or licensors. Title to the Material remains with Intel Corporation or its
+ * suppliers and licensors. The Material contains trade secrets and proprietary
+ * and confidential information of Intel or its suppliers and licensors. The
+ * Material is protected by worldwide copyright and trade secret laws and
+ * treaty provisions. No part of the Material may be used, copied, reproduced,
+ * modified, published, uploaded, posted, transmitted, distributed, or
+ * disclosed in any way without Intel’s prior express written permission.
+ *
+ * No license under any patent, copyright, trade secret or other intellectual
+ * property right is granted to or conferred upon you by disclosure or delivery
+ * of the Materials, either expressly, by implication, inducement, estoppel or
+ * otherwise. Any license under such intellectual property rights must be
+ * express and approved by Intel in writing.
+ *
+ * AUTHOR: Patrick Benavoli (patrickx.benavoli@intel.com)
+ * CREATED: 2011-06-01
+ * UPDATED: 2011-07-27
+ *
+ *
+ * </auto_header>
+ */
+#pragma once
+
+#include <string>
+#include <stdint.h>
+
+using namespace std;
+
+struct sockaddr_in;
+struct in_addr;
+
+class CSocket
+{
+public:
+ CSocket();
+ CSocket(int iSockId);
+ virtual ~CSocket();
+
+ // Non blocking state
+ void setNonBlocking(bool bNonBlocking);
+
+ // Communication timeout
+ void setTimeout(uint32_t uiMilliseconds);
+
+ // Read
+ bool read(void* pvData, uint32_t uiSize);
+ // Write
+ bool write(const void* pvData, uint32_t uiSize);
+
+ // Fd
+ int getFd() const;
+protected:
+ // Socket address init
+ void initSockAddrIn(struct sockaddr_in* pSockAddrIn, uint32_t uiInAddr, uint16_t uiPort) const;
+private:
+ int _iSockFd;
+};