Skip to content

Commit 9ce305d

Browse files
committed
Release v2.1
2 parents 4797ead + 02a9400 commit 9ce305d

File tree

130 files changed

+2911
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+2911
-329
lines changed

CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (NOT CMAKE_CXX_STANDARD)
2121
set (CMAKE_CXX_STANDARD 11)
2222
endif()
2323

24-
set (EXTERNALS_DIR "${CMAKE_SOURCE_DIR}/externals")
24+
set (EXTERNALS_DIR "${PROJECT_SOURCE_DIR}/externals")
2525
while (TRUE)
2626
if (CC_NO_UNIT_TESTS)
2727
message (STATUS "Unittests are disabled")
@@ -166,7 +166,7 @@ set (ICON_INSTALL_DIR ${DATA_INSTALL_DIR}/icon)
166166
set (CONFIG_INSTALL_REL_DIR ${CMAKE_INSTALL_DATADIR}/${INSTALL_NAME})
167167
set (CONFIG_INSTALL_DIR ${CONFIG_INSTALL_REL_DIR})
168168

169-
file (READ "${CMAKE_SOURCE_DIR}/comms/include/comms/version.h" version_file)
169+
file (READ "${PROJECT_SOURCE_DIR}/comms/include/comms/version.h" version_file)
170170
string (REGEX MATCH "COMMS_MAJOR_VERSION ([0-9]*)U*" _ ${version_file})
171171
set (major_ver ${CMAKE_MATCH_1})
172172
string (REGEX MATCH "COMMS_MINOR_VERSION ([0-9]*)U*" _ ${version_file})
@@ -188,18 +188,18 @@ write_basic_package_version_file(
188188
COMPATIBILITY AnyNewerVersion)
189189

190190
set (LIB_COMMS_CMAKE_FILES
191-
${CMAKE_SOURCE_DIR}/cmake/LibCommsConfig.cmake
192-
${CMAKE_SOURCE_DIR}/cmake/DocCleanupScript.cmake
191+
${PROJECT_SOURCE_DIR}/cmake/LibCommsConfig.cmake
192+
${PROJECT_SOURCE_DIR}/cmake/DocCleanupScript.cmake
193193
${CMAKE_BINARY_DIR}/LibCommsConfigVersion.cmake
194194
)
195195

196196
set (COMMS_CHAMPION_CMAKE_FILES
197-
${CMAKE_SOURCE_DIR}/cmake/CC_DefineExternalProjectTargets.cmake
198-
${CMAKE_SOURCE_DIR}/cmake/CommsChampionConfig.cmake
199-
${CMAKE_SOURCE_DIR}/cmake/DefineExternalProjectTargets.cmake
200-
${CMAKE_SOURCE_DIR}/cmake/DeployQt5.cmake
201-
${CMAKE_SOURCE_DIR}/cmake/DocCleanupScript.cmake
202-
${CMAKE_SOURCE_DIR}/cmake/GenWinAppStartBat.cmake
197+
${PROJECT_SOURCE_DIR}/cmake/CC_DefineExternalProjectTargets.cmake
198+
${PROJECT_SOURCE_DIR}/cmake/CommsChampionConfig.cmake
199+
${PROJECT_SOURCE_DIR}/cmake/DefineExternalProjectTargets.cmake
200+
${PROJECT_SOURCE_DIR}/cmake/DeployQt5.cmake
201+
${PROJECT_SOURCE_DIR}/cmake/DocCleanupScript.cmake
202+
${PROJECT_SOURCE_DIR}/cmake/GenWinAppStartBat.cmake
203203
${CMAKE_BINARY_DIR}/LibCommsConfigVersion.cmake
204204
)
205205

@@ -232,6 +232,6 @@ if (WIN32 AND CC_QT_DIR)
232232
add_custom_target ("deploy_qt"
233233
COMMAND ${CMAKE_COMMAND} -DCC_QT_DIR=${CC_QT_DIR}
234234
-DCC_BIN_DIR=${BIN_INSTALL_DIR} -DCC_PLUGIN_DIR=${PLUGIN_INSTALL_DIR}
235-
-P ${CMAKE_SOURCE_DIR}/cmake/DeployQt5.cmake
235+
-P ${PROJECT_SOURCE_DIR}/cmake/DeployQt5.cmake
236236
)
237237
endif ()

comms/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (DOXYGEN_FOUND)
1515
COMMAND ${CMAKE_COMMAND} -E make_directory ${doc_output_dir}
1616
COMMAND ${DOXYGEN_EXECUTABLE} ${output_file}
1717
COMMAND ${CMAKE_COMMAND} -DDOC_OUTPUT_DIR="${doc_output_dir}" -P
18-
${CMAKE_SOURCE_DIR}/cmake/DocCleanupScript.cmake
18+
${PROJECT_SOURCE_DIR}/cmake/DocCleanupScript.cmake
1919
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
2020
endif ()
2121

comms/doc/page_define_prot.dox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,7 @@
11901190
/// @li @ref comms::option::app::NoWriteImpl
11911191
/// @li @ref comms::option::app::NoValidImpl
11921192
/// @li @ref comms::option::app::NoLengthImpl
1193+
/// @li @ref comms::option::app::NoDispatchImpl
11931194
///
11941195
/// These options should not be used in the definition of protocol messages, but
11951196
/// it would be wise to allow the client application use them when necessary. It

comms/doc/page_field.dox

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,6 +2387,30 @@
23872387
/// defined field's base classes, which is implementation dependent. Just use
23882388
/// the provided @b value() member function to access the value.
23892389
///
2390+
/// @subsection sec_field_tutorial_common_options_write Custom Write Functionality
2391+
/// On some very rare occasions there may be a need to write custom @b write
2392+
/// functionality. It can be achieved by writing custom @b write() member function
2393+
/// @code
2394+
/// using MyFieldBase = comms::Field<comms::option::def::BigEndian>;
2395+
/// struct MyBundle : public
2396+
/// comms::field::Bundle<
2397+
/// MyFieldBase,
2398+
/// std::tuple<...>,
2399+
/// comms::option::def::HasCustomWrite
2400+
/// >
2401+
/// {
2402+
/// template <typename TIter>
2403+
/// comms::ErrorStatus write(TIter& iter, std::size_t len) const
2404+
/// {
2405+
/// ...
2406+
/// }
2407+
/// };
2408+
/// @endcode
2409+
/// @b NOTE usage of @ref comms::option::def::HasCustomWrite option. It is
2410+
/// required to let prevent field holding @ref comms::MessageBase
2411+
/// class from attempting to optimize write operation due to possible incorrect
2412+
/// behavior.
2413+
///
23902414
/// @subsection sec_field_tutorial_common_options_version Custom Version Update Functionality
23912415
/// Some protocols may include version information either in the transport framing
23922416
/// of every message or in one of the messages used to establish connection. Such

comms/doc/page_use_prot.dox

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// @li @b "comms/" - replace with "comms2/"
2626
///
2727
/// @section page_use_prot_error_handling Error Handling
28-
/// The COMMS library is intended to be used in embedded systems (including
28+
/// The @b COMMS library is intended to be used in embedded systems (including
2929
/// bare metal), which means the library does not use exceptions to report errors.
3030
/// The runtime errors are reported via @ref comms::ErrorStatus return values. All
3131
/// pre- and post-conditions are checked using COMMS_ASSERT() macro.
@@ -220,7 +220,7 @@
220220
/// std::size_t readMessage(MyMessage& msg, const std::uint8_t* buf, std::size_t len)
221221
/// {
222222
/// MyMessage::ReadIterator readIter = buf;
223-
/// auto es = msg->read(readIter, len); // readIter is advanced in the read operation
223+
/// auto es = msg.read(readIter, len); // readIter is advanced in the read operation
224224
/// if (es != comms::ErrorStatus::Success) {
225225
/// ... // Report and handle error
226226
/// return 0U;
@@ -279,9 +279,13 @@
279279
/// iterator for write operation. In the example above the output buffer
280280
/// is chosen to be @b std::vector<std::uint8_t> and the write operation will
281281
/// be performed using @b push_back() calls on this vector (due to @b std::back_insert_iterator
282-
/// being chosen as @b WriteIterator). @n
282+
/// being chosen as @b WriteIterator).
283+
///
283284
/// Also @b note, that iterator is passed by reference, which allows advancing
284-
/// operator when write operation is performed.
285+
/// operator when write operation is performed. In case the iterator is
286+
/// random-access one, the difference between the initial and its value
287+
/// after the write has been performed can be used to determine amount of
288+
/// bytes that have been written to the buffer.
285289
///
286290
/// The @ref comms::Message interface class defines @ref comms::Message::hasWrite()
287291
/// static constexpr member function, which may be used at compile time to
@@ -292,7 +296,7 @@
292296
/// @subsection page_use_prot_interface_length Polymorphic Serialisation Length Retrieval
293297
/// Sometimes it may be needed to polymorphically retrieve the serialisation length of the message
294298
/// in order to be able to reserve or allocate enough space for output buffer.
295-
/// The COMMS library provides @ref comms::option::app::LengthInfoInterface option that
299+
/// The @b COMMS library provides @ref comms::option::app::LengthInfoInterface option that
296300
/// adds @b length() member function to the interface.
297301
/// @code
298302
/// using MyMessage =
@@ -314,7 +318,7 @@
314318
/// }
315319
///
316320
/// protected:
317-
/// virtual std::size_t lengthImpl() const = 0; // Implemented in the derived class
321+
/// virtual std::size_t lengthImpl() const {...}; // Must be overridden in the derived class
318322
/// };
319323
/// @endcode
320324
/// The @ref comms::Message interface class defines @ref comms::Message::hasLength()
@@ -325,7 +329,7 @@
325329
///
326330
/// @subsection page_use_prot_interface_valid Polymorphic Validity Check
327331
/// Sometimes it may be needed to be able to check whether the message contents
328-
/// (fields) have valid values. The COMMS library provides comms::option::app::ValidCheckInterface
332+
/// (fields) have valid values. The @b COMMS library provides comms::option::app::ValidCheckInterface
329333
/// option that adds @b valid() member function to the interface:
330334
/// @code
331335
/// using MyMessage =
@@ -405,7 +409,7 @@
405409
/// }
406410
///
407411
/// protected:
408-
/// virtual DispatchRetType dispatchImpl(Handler& handler) = 0; // Must be implemented in the derived class
412+
/// virtual DispatchRetType dispatchImpl(Handler& handler) {...} // Must be overridden in the derived class
409413
/// };
410414
/// @endcode
411415
/// More details about polymorphic dispatching and handling will be provided
@@ -425,7 +429,7 @@
425429
/// After updating such fields directly, using the interface of the message object,
426430
/// the message contents may end up being in an inconsistent (or invalid) state.
427431
/// There may be a need to polymorphically normalise the state of the message object. The
428-
/// COMMS library provides @ref comms::option::app::RefreshInterface option, that adds
432+
/// @b COMMS library provides @ref comms::option::app::RefreshInterface option, that adds
429433
/// @b refresh() member function to the message interface.
430434
/// @code
431435
/// using MyMessage =
@@ -453,7 +457,7 @@
453457
/// }
454458
/// };
455459
/// @endcode
456-
/// Note, that the @b refresh() member function returns boolean value, which
460+
/// Note, that the @ref comms::Message::refresh() "refresh()" member function returns boolean value, which
457461
/// is expected to be @b true in case at least one of the internal fields has
458462
/// been updated, and @b false if message state remains unchanged. @n
459463
/// Also note, that interface provide default implementation of @b refreshImpl()
@@ -491,7 +495,7 @@
491495
/// }
492496
///
493497
/// protected:
494-
/// virtual const char* nameImpl() const = 0;
498+
/// virtual const char* nameImpl() const = 0; // Must be overridden in the derived class
495499
/// };
496500
/// @endcode
497501
/// The @ref comms::Message interface class defines @ref comms::Message::hasName()
@@ -562,6 +566,11 @@
562566
/// comms::option::app::NameInterface // Add an ability to retrieve message name
563567
/// >;
564568
/// @endcode
569+
/// In case no polymorphic interface extension option has been chosen, every
570+
/// message object becomes a simple "data structure" without any v-table "penalty".
571+
/// @code
572+
/// using MyInterface = my_protocol::Message<>;
573+
/// @endcode
565574
///
566575
/// @section page_use_prot_messages Protocol Messages
567576
/// The protocol messages are expected to be defined as template classes, receiving
@@ -591,7 +600,7 @@
591600
/// The interface class that was defined for the application (@b MyMessage) needs
592601
/// to be passed as @b TBase template parameter. The defined message class
593602
/// extends @ref comms::MessageBase, which in turn extends provided interface
594-
/// class @b TBase, which in turn extends @ref comms::Message. The inheritence
603+
/// class @b TBase, which in turn extends (or typedef-s) @ref comms::Message. The inheritance
595604
/// hierarchy may look like this:
596605
/// @diafile message_class_hierarchy.dia
597606
///
@@ -1233,7 +1242,7 @@
12331242
/// calculating length, checking field's contents validity, and bringing field's
12341243
/// value into a consistent state. It may be required
12351244
/// when a message contains sequence (see @ref page_use_prot_fields_array_list)
1236-
/// of such bundles/structs. The COMMS library provides @ref comms::field::Bundle
1245+
/// of such bundles/structs. The @b COMMS library provides @ref comms::field::Bundle
12371246
/// field for this purpose. It is quite similar to @ref comms::field::Bitfield described
12381247
/// earlier. The difference is that every member field
12391248
/// doesn't specify any length in bits, just bytes. For example:
@@ -1307,7 +1316,7 @@
13071316
/// @subsection page_use_prot_fields_array_list Array List Fields
13081317
/// Some communication protocols may define messages that transmit sequence
13091318
/// of similar fields and/or raw data buffers. To make it easier to handle, the
1310-
/// COMMS library provides comms::field::ArrayList field which provide a required
1319+
/// @b COMMS library provides comms::field::ArrayList field which provide a required
13111320
/// interface to properly handle such sequences of data. It supports a
13121321
/// sequence of raw bytes
13131322
/// @code
@@ -1356,7 +1365,7 @@
13561365
/// >;
13571366
/// @endcode
13581367
/// Usage of this option just ensures right amount of elements "on the wire" after
1359-
/// the field is serialised, but it doesn't automatically resize inner
1368+
/// the field is serialised, but it does @b NOT automatically resize inner
13601369
/// storage vector.
13611370
/// @code
13621371
/// MyList field;
@@ -1384,7 +1393,7 @@
13841393
///
13851394
/// Also similar to @ref page_use_prot_fields_array_list, fixed length strings
13861395
/// are defined using @ref comms::option::def::SequenceFixedSize option, and just
1387-
/// like with lists it doesn't automatically resize inner string, just ensures
1396+
/// like with lists it does @b NOT automatically resize inner string, just ensures
13881397
/// right amount of characters "on the wire" when field is serialised.
13891398
/// @code
13901399
/// using MyFixedString =
@@ -1411,7 +1420,7 @@
14111420
/// based on information recorded in other fields. For example there is a
14121421
/// "flags" bitmask field which specifies whether the following field exists or
14131422
/// missing. The optional field may also be tentative, i.e. if there is enough
1414-
/// data in the input buffer it exists, and missing otherwise. The COMMS
1423+
/// data in the input buffer it exists, and missing otherwise. The @b COMMS
14151424
/// library provides @ref comms::field::Optional which is a mere wrapper around
14161425
/// other fields and provides an ability to set the optional state of the field.
14171426
/// @code
@@ -1420,7 +1429,9 @@
14201429
/// comms::field::IntValue<MyFieldBase, std::int32_t>
14211430
/// >;
14221431
/// @endcode
1423-
/// The default mode of such field is "tentative".
1432+
/// The default mode of such field is "tentative", which means read if there
1433+
/// is data available in the input buffer, and write if there is enough space
1434+
/// in the output buffer.
14241435
/// @code
14251436
/// OptField field;
14261437
/// assert(field.isTentative());
@@ -2121,6 +2132,55 @@
21212132
/// please open reference page of a required @b field class for the list of
21222133
/// supported options and read their documentation for more details.
21232134
///
2135+
/// @subsection page_use_prot_fields_value_assign Field Value Assignment
2136+
/// As was mentioned earlier, every field class has @b value() member function,
2137+
/// which provides an access to internal value storage. Quite often there
2138+
/// may be case when explicit cast is required.
2139+
/// @code
2140+
/// using MyField = comms::field::IntValue<FieldBase, std::uint8_t>; // One byte int
2141+
/// int someValue = ...;
2142+
/// MyField field;
2143+
/// field.value() = static_cast<std::uint8_t>(someValue);
2144+
/// @endcode
2145+
/// The code above is boilerplate one, which in general should be avoided, because in
2146+
/// case of the field definition being changed, the cast below must also be changed.
2147+
/// Such boilerplate code can be avoided by using extra compile time type manipulations:
2148+
/// @code
2149+
/// field.value() = static_cast<typename std::decay<decltype(field.value())>::type>(someValue);
2150+
/// @endcode
2151+
/// However, it's too much typing to do and quite inconvenient for the developer.
2152+
/// The @b COMMS library provides @ref comms::cast_assign() stand alone
2153+
/// function which can be used for easy assignments with implicit @b static_cast to
2154+
/// appropriate type. It should be used for any arithmetic and/or enum storage
2155+
/// values.
2156+
/// @code
2157+
/// comms::cast_assign(field.value()) = someValue; // static_cast is automatic
2158+
/// @endcode
2159+
///
2160+
/// @subsection page_use_prot_fields_cast Cast Between Fields
2161+
/// There may also be cases when value of one field needs to be assigned to
2162+
/// value of another type. If @b static_cast between the values works, then
2163+
/// it is possible to use @ref comms::cast_assign() function described in
2164+
/// @ref page_use_prot_fields_value_assign section above.
2165+
/// @code
2166+
/// comms::assign(field1.value()) = field2.value();
2167+
/// @endcode
2168+
/// However, there may be cases when such cast is not possible. For example
2169+
/// value of 1 byte @ref comms::field::IntValue needs to be assigned to
2170+
/// a @ref comms::field::Bitfield length of which is also 1 byte, but it
2171+
/// splits the value into a couple of inner members. In this case
2172+
/// the @ref comms::field_cast() function should be used.
2173+
/// @code
2174+
/// using MyInt = comms::field::IntValue<FieldBase, std::uint8_t>;
2175+
/// using MyBitfield = comms::field::Bitfield<...>;
2176+
/// MyInt field1;
2177+
/// MyBitfield field2;
2178+
/// ... // Set values of field1 and field2
2179+
/// field2 = comms::field_cast<MyBitfield>(field1);
2180+
/// @endcode
2181+
/// @b NOTE, that casting and assignment is performed on the field objects
2182+
/// themselves, not their stored values.
2183+
///
21242184
/// @section page_use_prot_transport Transport Framing
21252185
/// In addition to definition of the messages and their contents, every
21262186
/// communication protocol must ensure that the message is successfully delivered
@@ -2708,7 +2768,7 @@
27082768
/// @endcode
27092769
///
27102770
/// @subsection page_use_prot_handling_generic Generic Handler
2711-
/// The COMMS library provides some help in defining custom message handlers.
2771+
/// The @b COMMS library provides some help in defining custom message handlers.
27122772
/// There is @ref comms::GenericHandler class that receives at least two template
27132773
/// parameters. The first one is a common interface class for all the handled messages
27142774
/// (@b MyMessage). The second template parameter is
@@ -2972,8 +3032,8 @@
29723032
/// using VersionType = ...; // Equals to ValueType of the relevant field.
29733033
///
29743034
/// // Accessors for the version info
2975-
/// VersionType version();
2976-
/// const VersionType& version();
3035+
/// VersionType& version();
3036+
/// const VersionType& version() const;
29773037
/// };
29783038
///
29793039
/// } // namespace my_protocol
@@ -3096,6 +3156,7 @@
30963156
/// @li @ref comms::option::app::NoWriteImpl
30973157
/// @li @ref comms::option::app::NoValidImpl
30983158
/// @li @ref comms::option::app::NoLengthImpl
3159+
/// @li @ref comms::option::app::NoDispatchImpl
30993160
///
31003161
/// In order to be able to pass these extra options to message definition classes,
31013162
/// the support from the latter is required. If the protocol definition

comms/include/comms/ErrorStatus.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ enum class ErrorStatus {
3535
BufferOverflow, ///< Used to indicate that stream buffer was overflowed
3636
/// when attempting to write data.
3737
InvalidMsgId, ///< Used to indicate that received message has unknown id
38-
InvalidMsgData, ///<Used to indicate that received message has invalid
39-
/// data.
38+
InvalidMsgData, ///<Used to indicate that a message has invalid data.
4039
MsgAllocFailure, ///<Used to indicate that message allocation has failed.
4140
NotSupported, ///< The operation is not supported.
4241
NumOfErrorStatuses ///< Number of supported error statuses, must be last.

0 commit comments

Comments
 (0)