Giter Site home page Giter Site logo

embxx's People

Contributors

0xc0170 avatar ajneu avatar arobenko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

embxx's Issues

EMBXX in Cygwin and Windows 10 compile?

Hello. Congratulations for the work.

I am aware of it researching the use of C ++ in embedded systems, then found his book on gitbook and became interested in following your suggested steps.

I tried to compile the embedxx on my machine, but I'm in trouble.

My environment is:

  • Windows 10
  • Cygwin 2.874 (64 Bits)
  • gcc version 5.4.1 20160609 (release) [ARM/embedded-5-branch revision 237715](GNU Tools for ARM Embedded Processors)
  • gcc version 5.4.0 (GCC)

The Erro:

consu_000@SocialSLA ~/Documents/GitHub/embxx/build
$ make install
[  1%] Building CXX object module/io/test/CMakeFiles/io.InStreamBufTest.dir/InStreamBufTestRunner.cpp.o
In file included from /usr/include/boost/asio/detail/signal_blocker.hpp:25:0,
                 from /usr/include/boost/asio/detail/impl/select_reactor.ipp:29,
                 from /usr/include/boost/asio/detail/select_reactor.hpp:212,
                 from /usr/include/boost/asio/detail/reactor.hpp:29,
                 from /usr/include/boost/asio/detail/impl/task_io_service.ipp:24,
                 from /usr/include/boost/asio/detail/task_io_service.hpp:198,
                 from /usr/include/boost/asio/impl/io_service.hpp:71,
                 from /usr/include/boost/asio/io_service.hpp:767,
                 from /usr/include/boost/asio/basic_io_object.hpp:19,
                 from /usr/include/boost/asio/basic_socket.hpp:20,
                 from /usr/include/boost/asio/basic_datagram_socket.hpp:20,
                 from /usr/include/boost/asio.hpp:21,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/ReadFifo.h:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/UartDevice.h:36,
                 from /home/consu_000/Documents/GitHub/embxx/module/io/test/InStreamBuf.th:30,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:23:
/usr/include/boost/asio/detail/posix_signal_blocker.hpp: In constructor ‘boost::asio::detail::posix_signal_blocker::posix_signal_blocker()’:
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:42:25: error: ‘sigfillset’ was not declared in this scope
     sigfillset(&new_mask);
                         ^
/usr/include/boost/asio/detail/posix_signal_blocker.hpp: In member function ‘void boost::asio::detail::posix_signal_blocker::block()’:
/usr/include/boost/asio/detail/posix_signal_blocker.hpp:59:27: error: ‘sigfillset’ was not declared in this scope
       sigfillset(&new_mask);
                           ^
In file included from /usr/include/boost/asio/detail/signal_set_service.hpp:213:0,
                 from /usr/include/boost/asio/signal_set_service.hpp:20,
                 from /usr/include/boost/asio/basic_signal_set.hpp:24,
                 from /usr/include/boost/asio.hpp:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/ReadFifo.h:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/UartDevice.h:36,
                 from /home/consu_000/Documents/GitHub/embxx/module/io/test/InStreamBuf.th:30,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:23:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp: In member function ‘boost::system::error_code boost::asio::detail::signal_set_service::add(boost::asio::detail::signal_set_service::implementation_type&, int, boost::system::error_code&)’:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp:266:29: error: ‘sigfillset’ was not declared in this scope
       sigfillset(&sa.sa_mask);
                             ^
/usr/include/boost/asio/detail/impl/signal_set_service.ipp:267:44: error: no matching function for call to ‘sigaction::sigaction(int&, sigaction*, int)’
       if (::sigaction(signal_number, &sa, 0) == -1)
                                            ^
In file included from /usr/include/sys/signal.h:112:0,
                 from /usr/include/signal.h:6,
                 from /usr/include/pthread.h:12,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr-default.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr.h:148,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ext/atomicity.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/ios_base.h:39,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ios:42,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/istream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/sstream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/complex:45,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/StdHeaders.h:24,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/StdValueTraits.h:22,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/ValueTraits.h:400,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/TestSuite.h:24,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/RealDescriptions.h:20,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/TestRunner.h:22,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:10:
/usr/include/cygwin/signal.h:317:8: note: candidate: sigaction::sigaction()
 struct sigaction
        ^
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 0 arguments, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: constexpr sigaction::sigaction(const sigaction&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: constexpr sigaction::sigaction(sigaction&&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
In file included from /usr/include/boost/asio/detail/signal_set_service.hpp:213:0,
                 from /usr/include/boost/asio/signal_set_service.hpp:20,
                 from /usr/include/boost/asio/basic_signal_set.hpp:24,
                 from /usr/include/boost/asio.hpp:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/ReadFifo.h:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/UartDevice.h:36,
                 from /home/consu_000/Documents/GitHub/embxx/module/io/test/InStreamBuf.th:30,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:23:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp: In member function ‘boost::system::error_code boost::asio::detail::signal_set_service::remove(boost::asio::detail::signal_set_service::implementation_type&, int, boost::system::error_code&)’:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp:337:44: error: no matching function for call to ‘sigaction::sigaction(int&, sigaction*, int)’
       if (::sigaction(signal_number, &sa, 0) == -1)
                                            ^
In file included from /usr/include/sys/signal.h:112:0,
                 from /usr/include/signal.h:6,
                 from /usr/include/pthread.h:12,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr-default.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr.h:148,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ext/atomicity.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/ios_base.h:39,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ios:42,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/istream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/sstream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/complex:45,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/StdHeaders.h:24,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/StdValueTraits.h:22,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/ValueTraits.h:400,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/TestSuite.h:24,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/RealDescriptions.h:20,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/TestRunner.h:22,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:10:
/usr/include/cygwin/signal.h:317:8: note: candidate: sigaction::sigaction()
 struct sigaction
        ^
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 0 arguments, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: constexpr sigaction::sigaction(const sigaction&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: constexpr sigaction::sigaction(sigaction&&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
In file included from /usr/include/boost/asio/detail/signal_set_service.hpp:213:0,
                 from /usr/include/boost/asio/signal_set_service.hpp:20,
                 from /usr/include/boost/asio/basic_signal_set.hpp:24,
                 from /usr/include/boost/asio.hpp:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/ReadFifo.h:27,
                 from /home/consu_000/Documents/GitHub/embxx/module/device/test/UartDevice.h:36,
                 from /home/consu_000/Documents/GitHub/embxx/module/io/test/InStreamBuf.th:30,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:23:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp: In member function ‘boost::system::error_code boost::asio::detail::signal_set_service::clear(boost::asio::detail::signal_set_service::implementation_type&, boost::system::error_code&)’:
/usr/include/boost/asio/detail/impl/signal_set_service.ipp:391:50: error: no matching function for call to ‘sigaction::sigaction(int&, sigaction*, int)’
       if (::sigaction(reg->signal_number_, &sa, 0) == -1)
                                                  ^
In file included from /usr/include/sys/signal.h:112:0,
                 from /usr/include/signal.h:6,
                 from /usr/include/pthread.h:12,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr-default.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/x86_64-pc-cygwin/bits/gthr.h:148,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ext/atomicity.h:35,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/bits/ios_base.h:39,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/ios:42,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/istream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/sstream:38,
                 from /usr/lib/gcc/x86_64-pc-cygwin/5.4.0/include/c++/complex:45,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/StdHeaders.h:24,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/StdValueTraits.h:22,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/ValueTraits.h:400,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/TestSuite.h:24,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/RealDescriptions.h:20,
                 from /home/consu_000/Documents/GitHub/embxx/external/cxxtest/cxxtest/TestRunner.h:22,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:10:
/usr/include/cygwin/signal.h:317:8: note: candidate: sigaction::sigaction()
 struct sigaction
        ^
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 0 arguments, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: constexpr sigaction::sigaction(const sigaction&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
/usr/include/cygwin/signal.h:317:8: note: candidate: constexpr sigaction::sigaction(sigaction&&)
/usr/include/cygwin/signal.h:317:8: note:   candidate expects 1 argument, 3 provided
In file included from /home/consu_000/Documents/GitHub/embxx/module/io/test/InStreamBuf.th:23:0,
                 from /home/consu_000/Documents/GitHub/embxx/build/module/io/test/InStreamBufTestRunner.cpp:23:
/home/consu_000/Documents/GitHub/embxx/embxx/driver/Character.h: In instantiation of ‘void embxx::driver::details::CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1ul>::readCompleteInterruptHandler(const ErrorStatus&) [with TDevice = embxx::device::test::UartDevice<embxx::device::test::EventLoopLock, char>; TEventLoop = embxx::util::EventLoop<1024ul, embxx::device::test::EventLoopLock, embxx::device::test::EventLoopCond>; THandler = embxx::util::StaticFunction<void(const embxx::error::ErrorStatusT<embxx::error::ErrorCode>&, long unsigned int)>; TReadUntilPred = std::nullptr_t; embxx::error::ErrorStatus = embxx::error::ErrorStatusT<embxx::error::ErrorCode>]’:
/home/consu_000/Documents/GitHub/embxx/embxx/driver/Character.h:353:17:   required from ‘embxx::driver::details::CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1ul>::CharacterReadSupport(embxx::driver::details::CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1ul>::Device&, embxx::driver::details::CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1ul>::EventLoop&) [with TDevice = embxx::device::test::UartDevice<embxx::device::test::EventLoopLock, char>; TEventLoop = embxx::util::EventLoop<1024ul, embxx::device::test::EventLoopLock, embxx::device::test::EventLoopCond>; THandler = embxx::util::StaticFunction<void(const embxx::error::ErrorStatusT<embxx::error::ErrorCode>&, long unsigned int)>; TReadUntilPred = std::nullptr_t; embxx::driver::details::CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1ul>::Device = embxx::device::test::UartDevice<embxx::device::test::EventLoopLock, char>; embxx::driver::details::CharacterReadSupport<TDevice, TEventLoop, THandler, TReadUntilPred, 1ul>::EventLoop = embxx::util::EventLoop<1024ul, embxx::device::test::EventLoopLock, embxx::device::test::EventLoopCond>]’
/home/consu_000/Documents/GitHub/embxx/embxx/driver/Character.h:1038:27:   required from ‘embxx::driver::Character<TDevice, TEventLoop, TTraits>::Character(embxx::driver::Character<TDevice, TEventLoop, TTraits>::Device&, embxx::driver::Character<TDevice, TEventLoop, TTraits>::EventLoop&) [with TDevice = embxx::device::test::UartDevice<embxx::device::test::EventLoopLock, char>; TEventLoop = embxx::util::EventLoop<1024ul, embxx::device::test::EventLoopLock, embxx::device::test::EventLoopCond>; TTraits = InStreamBufTestSuite::CharacterTraits; embxx::driver::Character<TDevice, TEventLoop, TTraits>::Device = embxx::device::test::UartDevice<embxx::device::test::EventLoopLock, char>; embxx::driver::Character<TDevice, TEventLoop, TTraits>::EventLoop = embxx::util::EventLoop<1024ul, embxx::device::test::EventLoopLock, embxx::device::test::EventLoopCond>]’
/home/consu_000/Documents/GitHub/embxx/module/io/test/InStreamBuf.th:62:29:   required from here
/home/consu_000/Documents/GitHub/embxx/embxx/driver/Character.h:433:14: error: converting to ‘bool’ from ‘embxx::driver::details::CharacterReadSupportBase<embxx::device::test::UartDevice<embxx::device::test::EventLoopLock, char>, embxx::util::EventLoop<1024ul, embxx::device::test::EventLoopLock, embxx::device::test::EventLoopCond>, embxx::util::StaticFunction<void(const embxx::error::ErrorStatusT<embxx::error::ErrorCode>&, long unsigned int)>, std::nullptr_t>::ReadUntilPred {aka std::nullptr_t}’ requires direct-initialization [-fpermissive]
             (!info_.readUntilPred_) ||
              ^
make[2]: *** [module/io/test/CMakeFiles/io.InStreamBufTest.dir/build.make:67: module/io/test/CMakeFiles/io.InStreamBufTest.dir/InStreamBufTestRunner.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:182: module/io/test/CMakeFiles/io.InStreamBufTest.dir/all] Error 2
make: *** [Makefile:139: all] Error 2

consu_000@SocialSLA ~/Documents/GitHub/embxx/build

EventLoop - runOnce

Hi!

In my embedded application, which is based mainly on your EventLoop, I have to use 3rd party library. This library is written in pure C and needs to be polled from main loop cyclically:

while(1)
{
   ...
   library_runOnce();
   ...
}

There is a need to extend EventLoop, by adding something like runOnce(). It will be similar to the Boost::Asio's io_service::run_one() or ROS's ros::spinOnce(). It has to execute only one event and return back to the caller. I have implemented this, by adding to the EventLoop code like this:

template <std::size_t TSize,
          typename TLock,
          typename TCond>
void EventLoop<TSize, TLock, TCond>::runOnce()
{
    lock_.lock();
    auto lockGuard = embxx::util::makeScopeGuard(
        [this]()
        {
            lock_.unlock();
        });

    volatile bool empty = queue_.isEmpty();
    if (empty) {
        return;
    }

    auto taskPtr = reinterpret_cast<Task*>(&queue_.front());
    auto sizeToRemove = taskPtr->getSize();
    lock_.unlock();
    taskPtr->exec();
    taskPtr->~Task();
    lock_.lock();
    queue_.popFront(sizeToRemove);
}

It has of course one serious disadvantage: it is not invoking cond_.wait(lock_);, but it allows now to use EventLoop with 3rd party libraries:

while(1)
{
   library_runOnce();
   _evenLoop.runOnce();
}

I think it would be nice to have this feature in embxx.

Trying to compile the StaticQueue in STM32cubeIde (arm-none-eabi) throws an error

... template <typename T> class StaticQueueBase<T>::ConstIterator : public StaticQueueBase<T>::template IteratorBase<typename StaticQueueBase<T>::ConstIterator, const StaticQueueBase<T> > { ... template <typename T> class StaticQueueBase<T>::Iterator : public StaticQueueBase<T>::template IteratorBase<typename StaticQueueBase<T>::Iterator, StaticQueueBase<T> > { ...

throws an error "expected class-name before '{' token".

Moving the documentation

Hello,

Dropbox suffers from "security issues" and various IT team just block it.

Could you move the documentation somewhere else ?

Best regards

Throw used in StaticQueue

In the README you have said, that this library is not using exceptions. When I tried to compile simple program, that uses your EventLoop (which has inside a StaticQueue object) with explicity disabled exceptions (-fno-exceptions) I got an error, because there is throw used (StaticQueue.h:242):

ConstReference at(std::size_t index) const
{
    if (index >= size()) {
        throw std::out_of_range(std::string("Index is out of range"));
    }
    return (*this)[index];
}

Maybe do you just replace this statement with GASSERT(index < size()); and then leave operator[] without any assertion?

By the way, great work - awesome library!

CompilerOptionsFuncs.cmake - Unix conditions

Why many macros in the CompilerOptionsFuncs cmake contain condition if (UNIX) ? Is there any intention?

An example:

macro (embxx_disable_exceptions)
    if (UNIX)
        embxx_add_cxx_flags("-fno-exceptions -fno-unwind-tables")
    endif ()
endmacro ()

I would like to remove that UNIX, because I don't think those flags contain anything specific for UNIX. I'll send PR shortly removing it from there

StaticFunction

Hi,

the following code will fail to compile. (It only compiles, if I uncomment the const.)

#include <iostream>

#include "StaticFunction.h"

struct Func1
{
    int operator()(int val) // const
    {
        return val * 2;
    }
    
    int a[10];
};

struct Func2
{
    int operator()(int val) // const
    {
        return val * a;
    }
    
    int& a;
};


typedef embxx::util::StaticFunction<int(int), 48> embxx_util_StaticFunction;

int main()
{
    embxx::util::StaticFunction<int(int), sizeof(Func1{})> f1(Func1{});
    std::cout << f1(3) << std::endl;

    int a = 4;
    embxx::util::StaticFunction<int(int), sizeof(Func2{a})> f2(Func2{a});
    std::cout << f2(3) << std::endl;
    return 0;
}

Compilation error is

In file included from main.cpp:3:0:
StaticFunction.h: In instantiation of ‘TRet embxx::util::StaticFunction<TRet(TArgs ...), TSize>::InvokerBound<TBound>::exec(TArgs ...) const [with TBound = Func2; long unsigned int TSize = 8ul; TRet = int; TArgs = {int}]’:
main.cpp:37:1:   required from here
StaticFunction.h:361:46: error: no match for call to ‘(const Func2) (int)’
     return func_(std::forward<TArgs>(args)...);
                                              ^
main.cpp:17:9: note: candidate: int Func2::operator()(int) <near match>
     int operator()(int val)
         ^~~~~~~~
main.cpp:17:9: note:   passing ‘const Func2*’ as ‘this’ argument discards qualifiers
In file included from main.cpp:3:0:
StaticFunction.h: In instantiation of ‘TRet embxx::util::StaticFunction<TRet(TArgs ...), TSize>::InvokerBound<TBound>::exec(TArgs ...) const [with TBound = Func1; long unsigned int TSize = 40ul; TRet = int; TArgs = {int}]’:
main.cpp:37:1:   required from here
StaticFunction.h:361:46: error: no match for call to ‘(const Func1) (int)’
     return func_(std::forward<TArgs>(args)...);
                                              ^
main.cpp:7:9: note: candidate: int Func1::operator()(int) <near match>
     int operator()(int val)
         ^~~~~~~~
main.cpp:7:9: note:   passing ‘const Func1*’ as ‘this’ argument discards qualifiers

(See it on Wandbox here.)

To get it to compile I need to change the functors' operator() to const, i.e.

struct Func1
{
    int operator()(int val) const
// .................
}

struct Func2
{
    int operator()(int val) const
// .................

Anyway... I tripped over this, when trying to get your embxx::util::StaticFunction to work with a benchmark. See here: https://github.com/user706/CxxFunctionBenchmark/tree/embxx . (It will only compile, if I put in the const here and here)

Regards,
user706

Can't build embxx with msys2 g++-7.3.0

Errors:
FAILED: module/io/test/CMakeFiles/io.WriteQueueTest.dir/WriteQueueTestRunner.cpp.obj
D:\bin\msys64\mingw32\bin\g++.exe -I../../ -I../../external/cxxtest -isystem D:/bin/msys64/mingw32/include -Wall -Wextra -Werror -Wcast-align -Wcast-qual -Wmissing-include-dirs -Wlogical-op -Wstrict-null-sentinel -Wredundant-decls -Wno-unknown-pragmas -Wundef -Wunused -Wshadow -fdiagnostics-show-option -Woverloaded-virtual -Wno-unused-local-typedefs -Wctor-dtor-privacy -Wnoexcept -O3 -DNDEBUG -std=c++11 -MD -MT module/io/test/CMakeFiles/io.WriteQueueTest.dir/WriteQueueTestRunner.cpp.obj -MF module\io\test\CMakeFiles\io.WriteQueueTest.dir\WriteQueueTestRunner.cpp.obj.d -o module/io/test/CMakeFiles/io.WriteQueueTest.dir/WriteQueueTestRunner.cpp.obj -c module/io/test/WriteQueueTestRunner.cpp
In file included from D:\projects\cpplibs\embxx\module\io\test\WriteQueue.th:21:0,
from module/io/test/WriteQueueTestRunner.cpp:23:
../../embxx/io/WriteQueue.h: In member function 'void embxx::io::WriteQueue<TDriver, TSize, THandler>::cancelAllWrites()':
../../embxx/io/WriteQueue.h:308:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
return false;
^~~~~

FAILED: module/util/test/CMakeFiles/util.AllocatorsTest.dir/AllocatorsTestRunner.cpp.obj
D:\bin\msys64\mingw32\bin\g++.exe -I../../ -I../../external/cxxtest -isystem D:/bin/msys64/mingw32/include -Wall -Wextra -Werror -Wcast-align -Wcast-qual -Wmissing-include-dirs -Wlogical-op -Wstrict-null-sentinel -Wredundant-decls -Wno-unknown-pragmas -Wundef -Wunused -Wshadow -fdiagnostics-show-option -Woverloaded-virtual -Wno-unused-local-typedefs -Wctor-dtor-privacy -Wnoexcept -O3 -DNDEBUG -std=c++11 -MD -MT module/util/test/CMakeFiles/util.AllocatorsTest.dir/AllocatorsTestRunner.cpp.obj -MF module\util\test\CMakeFiles\util.AllocatorsTest.dir\AllocatorsTestRunner.cpp.obj.d -o module/util/test/CMakeFiles/util.AllocatorsTest.dir/AllocatorsTestRunner.cpp.obj -c module/util/test/AllocatorsTestRunner.cpp
In file included from D:\projects\cpplibs\embxx\module\util\test\Allocators.th:18:0,
from module/util/test/AllocatorsTestRunner.cpp:23:
../../embxx/util/Allocators.h: In member function 'decltype (embxx::util::SpecificInPlaceAllocator::Allocator().alloc((forward)(args)...)) embxx::util::SpecificInPlaceAllocator::alloc(TArgs&& ...)':
../../embxx/util/Allocators.h:283:37: error: expected primary-expression before '>' token
return allocator_.alloc(std::forward(args)...);
^
../../embxx/util/Allocators.h:283:67: error: expected binary operator before ')' token
return allocator_.alloc(std::forward(args)...);
^

StaticFunction const, nonconst

Hi,

related to #19 (and thus using code from branch develop) ... I'm just meddling with a similar library (ref),
and came across an issue, that affects StaticFunction as well:

// ...

#include <iostream>

struct Func {
    void operator()() const {
        std::cout << "const   ";
    }

    void operator()()  {
        std::cout << "nonconst";
    }
};



int main()
{
    {
        Func func{};
        embxx::util::StaticFunction<void(), 32> f(func);
        f();
        std::cout << "\t should get ";
        func();
        std::cout << std::endl;
    }
    {
        const Func func{};
        embxx::util::StaticFunction<void(), 32> f(func);
        f();
        std::cout << "\t should get ";
        func();
        std::cout << std::endl;
    }
}

This prints

nonconst	 should get nonconst
nonconst	 should get const   

So with the mutable (ref)... the void operator()() const is not called in the end...

TimerMgr - support for periodic timers

Hi!

At the moment, Timer class is a simple deadline timer. Using it we can implement something like periodic timer, but in my opinion it is not a performance-optimal solution:

void SomeClass::periodicTask()
{
   /* do some work */
   timer.asyncWait(std::chrono::seconds(1), 
      [this](const auto& errorStatus)
      {
         if(errorStatus) // optional - stop the interval
         {
            /* LOG_ERROR(...) */
            return;
         }
         periodicTask(); 
      });
}

void SomeClass::start()
{
   timer.asyncWait(std::chrono::seconds(1), 
      [this](const auto& errorStatus)
      {
         if(errorStatus) // optional - stop the interval
         {
            /* LOG_ERROR(...) */
            return;
         }
         periodicTask(); 
      });
}

Correct me, if I'm wrong, but I think this code is re-assigning callback to the StaticFunction object every second. It is arleady not needed, because the callback is always the same. Additionally, body of the callback's lambda will be repeated. It would be nice to have solution like this:

void SomeClass::periodicTask()
{
   /* do some work */
}

void SomeClass::start()
{
   interval.start(std::chrono::seconds(1),
      [this](const auto& errorStatus)
      {
         if(errorStatus) // on error, interval is stopped, but it can be restarted
         {
            /* LOG_ERROR(...) */
            interval.restart();
            return;
         }
         periodicTask();
      });
}

Periodic timer would be very useful to implement cyclical tasks using e.g. SysTick. It can be of course implemented using current Timer class, but the problem of reasigning the same callbacks every time is still not solved. On the other hand, I'm not sure, if current TimerMgr driver is suitable to implement this feature... Maybe another Timer driver has to be implemented? What do you think about this?

Unable to use StaticFunction without `operator delete`

With code similar to this:

class i2c_slave {
    typedef embxx::util::StaticFunction<void(uint8_t *)> rx_complete_t;
    rx_complete_t rx_complete;
}

I'm getting this error message:

In function `embxx::util::StaticFunction<void (unsigned char*), 12u>::InvokerBound<display_ctrl_i2c::display_ctrl_i2c()::{lambda(unsigned char*)#2}>::~InvokerBound()':
../thirdparty/embxx/embxx/util/StaticFunction.h:353: undefined reference to `operator delete(void*, unsigned int)'

which was kinda surprising given the name of the class. Am I using the class in a bad way or what am I missing?

GCC 5.x support?

I am currently using gcc 5.x which caused some breakage in the c++11 support (reference https://gcc.gnu.org/gcc-5/porting_to.html). This affects this code base, I found few issues so far, therefore I ask before I do any bug fixing in this area.

A question - move to gcc 5, or stay within gcc 4 ? The decision shall be documented in the readme

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.