add .clang-format
Add .clang-format for automatic style.
Change-Id: I91e9acb28ca4218eba58dc13d10773bcb39c338f
Signed-off-by: Patrick Venture <venture@google.com>
diff --git a/sbe_chipOp_handler.cpp b/sbe_chipOp_handler.cpp
index 361e9f4..dbed874 100644
--- a/sbe_chipOp_handler.cpp
+++ b/sbe_chipOp_handler.cpp
@@ -1,11 +1,12 @@
-#include <array>
+#include <endian.h>
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#include <poll.h>
-#include <endian.h>
-#include <sbe_chipOp_handler.hpp>
+#include <unistd.h>
+
+#include <array>
#include <file.hpp>
+#include <sbe_chipOp_handler.hpp>
namespace openpower
{
namespace sbe
@@ -23,17 +24,16 @@
constexpr auto MAGIC_CODE_BITS = 16;
std::vector<sbe_word_t> writeToFifo(const char* devPath,
const sbe_word_t* cmdBuffer,
- size_t cmdBufLen,
- size_t respBufLen)
+ size_t cmdBufLen, size_t respBufLen)
{
ssize_t len = 0;
std::vector<sbe_word_t> response;
std::ostringstream errMsg;
- //Open the device and obtain the file descriptor associated with it.
+ // Open the device and obtain the file descriptor associated with it.
FileDescriptor fileFd(devPath, (O_RDWR | O_NONBLOCK));
- //Wait for FIFO device and perform write operation
+ // Wait for FIFO device and perform write operation
struct pollfd poll_fd = {};
poll_fd.fd = fileFd();
poll_fd.events = POLLOUT | POLLERR;
@@ -41,145 +41,150 @@
int rc = 0;
if ((rc = poll(&poll_fd, 1, -1)) < 0)
{
- //TODO:use elog infrastructure
+ // TODO:use elog infrastructure
errMsg << "Waiting for FIFO device:" << devPath << "to write failed"
<< "rc=" << rc << "errno=" << errno;
throw std::runtime_error(errMsg.str().c_str());
}
if (poll_fd.revents & POLLERR)
{
- //TODO:use elog infrastructure
+ // TODO:use elog infrastructure
errMsg << "POLLERR while waiting for writeable FIFO,errno:" << errno;
throw std::runtime_error(errMsg.str().c_str());
}
auto bytesToWrite = (cmdBufLen * WORD_SIZE);
- //Perform the write operation
+ // Perform the write operation
len = write(fileFd(), cmdBuffer, bytesToWrite);
if (len < 0)
{
- //TODO:use elog infrastructure
- errMsg << "Failed to write to FIFO device:" << devPath << " Length "
- "returned= " << len << " errno=" << errno;
+ // TODO:use elog infrastructure
+ errMsg << "Failed to write to FIFO device:" << devPath
+ << " Length "
+ "returned= "
+ << len << " errno=" << errno;
throw std::runtime_error(errMsg.str().c_str());
}
- //Wait for FIFO device and perform read operation
+ // Wait for FIFO device and perform read operation
poll_fd.fd = fileFd();
poll_fd.events = POLLIN | POLLERR;
if ((rc = poll(&poll_fd, 1, -1) < 0))
{
- //TODO:use elog infrastructure
+ // TODO:use elog infrastructure
errMsg << "Waiting for FIFO device:" << devPath << "to read failed"
<< " rc=" << rc << " and errno=" << errno;
throw std::runtime_error(errMsg.str().c_str());
}
if (poll_fd.revents & POLLERR)
{
- //TODO:use elog infrastructure
+ // TODO:use elog infrastructure
errMsg << "POLLERR while waiting for readable FIFO,errno:" << errno;
throw std::runtime_error(errMsg.str().c_str());
}
- //Derive the total read length which should include the FFDC, which SBE
- //returns in case of failure.
+ // Derive the total read length which should include the FFDC, which SBE
+ // returns in case of failure.
size_t totalReadLen = respBufLen + MAX_FFDC_LEN_IN_WORDS;
- //Create a temporary buffer
+ // Create a temporary buffer
std::vector<sbe_word_t> buffer(totalReadLen);
ssize_t bytesToRead = (totalReadLen * WORD_SIZE);
len = read(fileFd(), buffer.data(), bytesToRead);
if (len < 0)
{
- //TODO:use elog infrastructure
- errMsg << "Failed to read the FIFO device:" << devPath << "bytes read ="
- << len << " errno=" << errno;
+ // TODO:use elog infrastructure
+ errMsg << "Failed to read the FIFO device:" << devPath
+ << "bytes read =" << len << " errno=" << errno;
throw std::runtime_error(errMsg.str().c_str());
}
- //Extract the valid number of words read.
+ // Extract the valid number of words read.
for (auto i = 0; i < (len / WORD_SIZE); ++i)
{
response.push_back(be32toh(buffer[i]));
}
- //Closing of the file descriptor will be handled when the FileDescriptor
- //object will go out of scope.
+ // Closing of the file descriptor will be handled when the FileDescriptor
+ // object will go out of scope.
return response;
}
void parseResponse(std::vector<sbe_word_t>& sbeDataBuf)
{
- //Number of 32-bit words obtained from the SBE
+ // Number of 32-bit words obtained from the SBE
size_t lengthObtained = sbeDataBuf.size();
- //Fetch the SBE header and SBE chiop primary and secondary status
- //Last value in the buffer will have the offset for the SBE header
- size_t distanceToStatusHeader = sbeDataBuf[sbeDataBuf.size() - 1];
+ // Fetch the SBE header and SBE chiop primary and secondary status
+ // Last value in the buffer will have the offset for the SBE header
+ size_t distanceToStatusHeader = sbeDataBuf[sbeDataBuf.size() - 1];
if (lengthObtained < distanceToStatusHeader)
{
- //TODO:use elog infrastructure
+ // TODO:use elog infrastructure
std::ostringstream errMsg;
- errMsg << "Distance to SBE status header value " <<
- distanceToStatusHeader << " is greater then total length of "
- "response buffer " << lengthObtained;
+ errMsg << "Distance to SBE status header value "
+ << distanceToStatusHeader
+ << " is greater then total length of "
+ "response buffer "
+ << lengthObtained;
throw std::runtime_error(errMsg.str().c_str());
}
- //Fetch the response header contents
+ // Fetch the response header contents
auto iter = sbeDataBuf.begin();
std::advance(iter, (lengthObtained - distanceToStatusHeader));
- //First header word will have 2 bytes of MAGIC CODE followed by
- //Command class and command type
+ // First header word will have 2 bytes of MAGIC CODE followed by
+ // Command class and command type
//| MAGIC BYTES:0xCODE | COMMAND-CLASS | COMMAND-TYPE|
sbe_word_t l_magicCode = (*iter >> MAGIC_CODE_BITS);
- //Fetch the primary and secondary response code
+ // Fetch the primary and secondary response code
std::advance(iter, DISTANCE_TO_RESP_CODE);
auto l_priSecResp = *iter;
- //Validate the magic code obtained in the response
+ // Validate the magic code obtained in the response
if (l_magicCode != MAGIC_CODE)
{
- //TODO:use elog infrastructure
+ // TODO:use elog infrastructure
std::ostringstream errMsg;
- errMsg << "Invalid MAGIC keyword in the response header (" <<
- l_magicCode << "),expected keyword " << MAGIC_CODE;
+ errMsg << "Invalid MAGIC keyword in the response header ("
+ << l_magicCode << "),expected keyword " << MAGIC_CODE;
throw std::runtime_error(errMsg.str().c_str());
}
- //Validate the Primary and Secondary response value
+ // Validate the Primary and Secondary response value
if (l_priSecResp != SBE_OPERATION_SUCCESSFUL)
{
- //Extract the SBE FFDC and throw it to the caller
- size_t ffdcLen = (distanceToStatusHeader -
- LENGTH_OF_RESP_HEADER_IN_WORDS -
- LENGTH_OF_DISTANCE_HEADER_IN_WORDS);
+ // Extract the SBE FFDC and throw it to the caller
+ size_t ffdcLen =
+ (distanceToStatusHeader - LENGTH_OF_RESP_HEADER_IN_WORDS -
+ LENGTH_OF_DISTANCE_HEADER_IN_WORDS);
if (ffdcLen)
{
std::vector<sbe_word_t> ffdcData(ffdcLen);
- //Fetch the offset of FFDC data
+ // Fetch the offset of FFDC data
auto ffdcOffset = (lengthObtained - distanceToStatusHeader) +
LENGTH_OF_RESP_HEADER_IN_WORDS;
std::copy_n((sbeDataBuf.begin() + ffdcOffset), ffdcLen,
ffdcData.begin());
}
- //TODO:use elog infrastructure to return the SBE and Hardware procedure
- //FFDC container back to the caller.
+ // TODO:use elog infrastructure to return the SBE and Hardware procedure
+ // FFDC container back to the caller.
std::ostringstream errMsg;
- errMsg << "Chip operation failed with SBE response code:" << l_priSecResp
+ errMsg << "Chip operation failed with SBE response code:"
+ << l_priSecResp
<< ".Length of FFDC data of obtained:" << ffdcLen;
throw std::runtime_error(errMsg.str().c_str());
}
- //In case of success, remove the response header content and send only the
- //data.Response header will be towards the end of the buffer.
+ // In case of success, remove the response header content and send only the
+ // data.Response header will be towards the end of the buffer.
auto respLen = (lengthObtained - distanceToStatusHeader);
iter = sbeDataBuf.begin();
- std::advance(iter,respLen);
+ std::advance(iter, respLen);
sbeDataBuf.erase(iter, sbeDataBuf.end());
}
-}
-}
-}
+} // namespace internal
+} // namespace sbe
+} // namespace openpower