Skip to content

Commit

Permalink
Release v3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
arobenko committed Nov 11, 2019
2 parents e1cf1ab + 6a5ba85 commit 7b6957b
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 224 deletions.
291 changes: 90 additions & 201 deletions .travis.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ endwhile ()
include(GNUInstallDirs)

if ("${CC_TAG}" STREQUAL "")
set (CC_TAG "v2.2")
set (CC_TAG "v2.2.1")
endif()

add_subdirectory(lib)
Expand Down
20 changes: 18 additions & 2 deletions app/commsdsl2comms/src/AllMessages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ bool AllMessages::writeProtocolDefinition() const
MessagesInfo m_all;
MessagesInfo m_serverInput;
MessagesInfo m_clientInput;
bool m_realPlatform = true;
};

using PlatformsMap = std::map<std::string, PlatformInfo>;
Expand All @@ -57,6 +58,12 @@ bool AllMessages::writeProtocolDefinition() const
platformsMap.insert(std::make_pair(p, PlatformInfo()));
};

auto bundles = m_generator.extraMessagesBundles();
for (auto& b : bundles) {
auto& elem = platformsMap[b];
elem.m_realPlatform = false;
}

auto allMessages = m_generator.getAllDslMessages();

for (auto& p : platformsMap) {
Expand Down Expand Up @@ -120,12 +127,11 @@ bool AllMessages::writeProtocolDefinition() const
auto& msgPlatforms = m.platforms();
if (msgPlatforms.empty()) {
for (auto& p : platformsMap) {
if (p.first.empty()) {
if ((p.first.empty()) || (!p.second.m_realPlatform)) {
continue;
}
addToPlatformInfoFunc(p.second);
}
continue;
}

for (auto& p : msgPlatforms) {
Expand All @@ -137,6 +143,16 @@ bool AllMessages::writeProtocolDefinition() const

addToPlatformInfoFunc(iter->second);
}

auto inBundles = m_generator.bundlesForMessage(extRef);
for (auto& b : inBundles) {
auto iter = platformsMap.find(b);
if (iter == platformsMap.end()) {
assert(!"Should not happen");
continue;
}
addToPlatformInfoFunc(iter->second);
}
}

auto writeFileFunc =
Expand Down
30 changes: 22 additions & 8 deletions app/commsdsl2comms/src/Dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ bool Dispatch::writeProtocolDefinition() const
MessagesInfo m_all;
MessagesInfo m_serverInput;
MessagesInfo m_clientInput;
bool m_realPlatform = true;
};

using PlatformsMap = std::map<std::string, PlatformInfo>;
Expand All @@ -61,6 +62,12 @@ bool Dispatch::writeProtocolDefinition() const
platformsMap.insert(std::make_pair(p, PlatformInfo()));
};

auto bundles = m_generator.extraMessagesBundles();
for (auto& b : bundles) {
auto& elem = platformsMap[b];
elem.m_realPlatform = false;
}

auto allMessages = m_generator.getAllDslMessages();

for (auto& p : platformsMap) {
Expand Down Expand Up @@ -128,12 +135,11 @@ bool Dispatch::writeProtocolDefinition() const
auto& msgPlatforms = m.platforms();
if (msgPlatforms.empty()) {
for (auto& p : platformsMap) {
if (p.first.empty()) {
if (p.first.empty() || (!p.second.m_realPlatform)) {
continue;
}
addToPlatformInfoFunc(p.second);
}
continue;
}

for (auto& p : msgPlatforms) {
Expand All @@ -145,8 +151,17 @@ bool Dispatch::writeProtocolDefinition() const

addToPlatformInfoFunc(iter->second);
}
}

auto inBundles = m_generator.bundlesForMessage(extRef);
for (auto& b : inBundles) {
auto iter = platformsMap.find(b);
if (iter == platformsMap.end()) {
assert(!"Should not happen");
continue;
}
addToPlatformInfoFunc(iter->second);
}
}

auto writeFileFunc =
[this](const MessagesInfo& info,
Expand All @@ -156,8 +171,6 @@ bool Dispatch::writeProtocolDefinition() const
{
auto startInfo = m_generator.startDispatchProtocolWrite(fileName);
auto& filePath = startInfo.first;
auto& funcName = startInfo.second;
static_cast<void>(funcName); // TODO: remove

if (filePath.empty()) {
return true;
Expand Down Expand Up @@ -240,7 +253,9 @@ std::string Dispatch::getDispatchFunc(
using MsgMap = std::map<std::uintmax_t, DslMessagesList>;
MsgMap msgMap;
for (auto& m : messages) {
msgMap[m.id()].push_back(m);
auto& msgList = msgMap[m.id()];
assert((msgList.empty()) || (msgList.back().name() != m.name())); // Make sure message is not inserted twice
msgList.push_back(m);
}

bool hasMultipleMessagesWithSameId =
Expand All @@ -261,8 +276,7 @@ std::string Dispatch::getDispatchFunc(
"case #^#MSG_ID#$#:\n"
"{\n"
" using MsgType = #^#MSG_TYPE#$#<InterfaceType, TProtOptions>;\n"
" auto& castedMsg = static_cast<MsgType&>(msg);\n"
" return handler.handle(castedMsg);\n"
" return handler.handle(static_cast<MsgType&>(msg));\n"
"}";

if (msgList.size() == 1) {
Expand Down
172 changes: 170 additions & 2 deletions app/commsdsl2comms/src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#include <fstream>
#include <iterator>
#include <algorithm>
#include <cctype>

#include <boost/algorithm/string.hpp>

Expand Down Expand Up @@ -45,7 +47,7 @@ namespace
{

const unsigned MaxDslVersion = 3U;
const std::string MinCommsVersionStr("2, 2, 0");
const std::string MinCommsVersionStr("2, 2, 1");
const std::string ScopeSep("::");
const std::string ReplaceSuffix(".replace");
const std::string ExtendSuffix(".extend");
Expand Down Expand Up @@ -176,6 +178,40 @@ bool Generator::isElementOptional(
return false;
}

std::vector<std::string> Generator::extraMessagesBundles() const
{
std::vector<std::string> result;
result.reserve(m_extraMessages.size());
std::transform(
m_extraMessages.begin(), m_extraMessages.end(), std::back_inserter(result),
[](const auto& elem) -> const std::string&
{
return elem.m_name;
});
return result;
}

std::vector<std::string> Generator::bundlesForMessage(const std::string& externalRef)
{
std::vector<std::string> result;
for (auto& info : m_extraMessages) {
auto iter =
std::lower_bound(
info.m_dslNames.begin(), info.m_dslNames.end(), externalRef,
[](const std::string& n, const std::string& ref)
{
return n < ref;
});

if ((iter == info.m_dslNames.end()) || (*iter != externalRef)) {
continue;
}

result.push_back(info.m_name);
}
return result;
}

std::string Generator::protocolDefRootDir()
{
auto dir = getProtocolDefRootDir();
Expand Down Expand Up @@ -1010,6 +1046,7 @@ bool Generator::parseSchemaFiles(const FilesList& files)
if (m_mainNamespace.empty()) {
assert(!schema.name().empty());
m_mainNamespace = common::adjustName(schema.name());
m_schemaNamespace = m_mainNamespace;
}

m_schemaEndian = schema.endian();
Expand Down Expand Up @@ -1078,6 +1115,10 @@ bool Generator::prepare()
return false;
}

if (!prepareExternalMessages()) {
return false;
}

m_messageIdField = findMessageIdField();
return true;
}
Expand Down Expand Up @@ -1985,7 +2026,7 @@ std::string Generator::getCustomOpForElement(
rootDir = common::pluginNsStr();
}
else {
rootDir = bf::path(common::includeStr()) / m_mainNamespace;
rootDir = bf::path(common::includeStr()) / m_schemaNamespace;
}

auto relDirPath = rootDir / refToPath(ns);
Expand Down Expand Up @@ -2072,6 +2113,133 @@ bool Generator::preparePlugins()

}

bool Generator::prepareExternalMessages()
{
auto extraBundles = m_options.getExtraInputBundles();
if (extraBundles.empty()) {
return true;
}

auto dslMessages = getAllDslMessages();
std::sort(
dslMessages.begin(), dslMessages.end(),
[](auto m1, auto m2)
{
return m1.externalRef() < m2.externalRef();
});

auto dslPlatforms = platforms();
for (auto& p : dslPlatforms) {
common::nameToClass(p);
}

std::sort(
dslPlatforms.begin(), dslPlatforms.end(),
[](const std::string& p1, const std::string& p2)
{
return p1 < p2;
});

for (auto& b : extraBundles) {
auto reportErrorFunc =
[this, &b]()
{
m_logger.error("Invalid value of \"" + m_options.extraMessagesBundlesParamStr() + "\" parameter (" + b + ").");
};

auto colonPos = b.find(':');
if ((colonPos == std::string::npos) ||
(colonPos == 0) ||
(b.size() <= (colonPos + 1))) {
reportErrorFunc();
return false;
}

ExtraMessagesInfo info;
info.m_name = b.substr(0, colonPos);
assert(!info.m_name.empty());
auto allAlphaNum =
std::all_of(info.m_name.begin(), info.m_name.end(),
[](char ch)
{
return std::isalnum(ch) != 0;
});

if (!allAlphaNum) {
m_logger.error("Invalid bundle name specified with \"" + m_options.extraMessagesBundlesParamStr() + "\" parameter (" + b + ").");
return false;
}


common::nameToClass(info.m_name);

auto platIter =
std::lower_bound(
dslPlatforms.begin(), dslPlatforms.end(), info.m_name,
[](const std::string& pName, const std::string& bName)
{
return pName < bName;
});

if ((platIter != dslPlatforms.end()) ||
(info.m_name == "All")) {
m_logger.error("Bundle name specified with \"" + m_options.extraMessagesBundlesParamStr() + "\" parameter (" + b + ") reuses name of one of the platforms.");
return false;
}

auto filePath = b.substr(colonPos + 1);
std::ifstream stream(filePath);
if (!stream) {
m_logger.error("Invalid file name specified with \"" + m_options.extraMessagesBundlesParamStr() + "\" parameter (" + b + ").");
return false;
}

std::string content((std::istreambuf_iterator<char>(stream)), std::istreambuf_iterator<char>());
ba::split(info.m_dslNames, content, ba::is_any_of(" \r\n"), ba::token_compress_on);

// trim spaces and check the validity of names
for (auto& m : info.m_dslNames) {
ba::trim(m);
if (m.empty()) {
continue;
}

auto iter =
std::lower_bound(
dslMessages.begin(), dslMessages.end(), m,
[](commsdsl::Message msg, const std::string& mParam)
{
return msg.externalRef() < mParam;
});

if ((iter == dslMessages.end()) ||
(iter->externalRef() != m)) {
m_logger.error("Invalid message name (" + m + ") specified inside \"" + filePath + "\" file.");
return false;
}
}

info.m_dslNames.erase(
std::remove_if(
info.m_dslNames.begin(), info.m_dslNames.end(),
[](const std::string& n)
{
return n.empty();
}),
info.m_dslNames.end());

if (info.m_dslNames.empty()) {
m_logger.error("The file bundle \"" + info.m_name + "\" doesn't contain any messages.");
return false;
}

std::sort(info.m_dslNames.begin(), info.m_dslNames.end());
m_extraMessages.push_back(std::move(info));
}

return true;
}

std::string Generator::getOptionsBody(GetOptionsFunc func) const
{
std::string result;
Expand Down
Loading

0 comments on commit 7b6957b

Please sign in to comment.