ARMmbed / mbed-client-for-aws

AWS IoT SDK port for Mbed OS
Apache License 2.0
8 stars 13 forks source link

Created class to eliminate lambda that was causing build issues. #8

Closed AGlass0fMilk closed 4 years ago

AGlass0fMilk commented 4 years ago

I created a new class, AWSDetachedThread, that captures the argument and routine context given by the AWS layer of the application. This is to avoid problems with starting a thread using a callback created with a lambda expression.

I have used lambdas to create callbacks before with Mbed-OS but haven't seen this kind of error before:

[ERROR] ./mbed-aws-client/mbed/src/iot_thread.cpp: In function 'bool Iot_CreateDetachedThread(IotThreadRoutine_t, void*, int32_t, size_t)':
./mbed-aws-client/mbed/src/iot_thread.cpp:25:6: error: no matching function for call to 'rtos::Thread::start(Iot_CreateDetachedThread(IotThreadRoutine_t, void*, int32_t, size_t)::<lambda()>)'
   25 |     });
      |      ^
In file included from ./mbed-os/rtos/rtos.h:28,
                 from ./mbed-os/mbed.h:22,
                 from ./mbed-aws-client/mbed/src/iot_thread.cpp:1:
./mbed-os/rtos/Thread.h:264:14: note: candidate: 'osStatus rtos::Thread::start(mbed::Callback<void()>)'
  264 |     osStatus start(mbed::Callback<void()> task);
      |              ^~~~~
./mbed-os/rtos/Thread.h:264:43: note:   no known conversion for argument 1 from 'Iot_CreateDetachedThread(IotThreadRoutine_t, void*, int32_t, size_t)::<lambda()>' to 'mbed::Callback<void()>'
  264 |     osStatus start(mbed::Callback<void()> task);
      |                    ~~~~~~~~~~~~~~~~~~~~~~~^~~~
./mbed-os/rtos/Thread.h:279:14: note: candidate: 'template<class T, class M> osStatus rtos::Thread::start(T*, M)'
  279 |     osStatus start(T *obj, M method)
      |              ^~~~~
./mbed-os/rtos/Thread.h:279:14: note:   template argument deduction/substitution failed:
./mbed-aws-client/mbed/src/iot_thread.cpp:25:6: note:   mismatched types 'T*' and 'Iot_CreateDetachedThread(IotThreadRoutine_t, void*, int32_t, size_t)::<lambda()>'
   25 |     });
      |      ^

[mbed] ERROR: "/home/gdbeckstein/python-mbed/bin/python" returned error.
       Code: 1
       Path: "/home/gdbeckstein/Documents/embeddedplanet/aws-updates/mbed-os-example-aws"

I am building with mbed-os 5.15.4 (default for this example I think?) and it was failing to compile with the above error. I was not able to tweak the lambda declaration (using mbed::callback, mbed::Callback<void(void)>, or any other more explicit declaration) to compile so I implemented the patch in this PR.

boraozgen commented 4 years ago

This example project uses Mbed OS 6, maybe you should try with that.

AGlass0fMilk commented 4 years ago

This example project uses Mbed OS 6, maybe you should try with that.

Not sure why I didn't try that first. That fixed the compilation issue. Better to work with Mbed OS 6 anyway.