AsynchronCall.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "AsynchronCall.h"
  2. using namespace Framework;
  3. // Content of the AsynchronCall class
  4. // Constructor
  5. // f: The function to be called asynchronously
  6. // Must be called with new. The object deletes itself
  7. AsynchronCall::AsynchronCall(std::function<void()> f)
  8. : Thread()
  9. {
  10. this->finished = 0;
  11. this->f = f;
  12. start();
  13. }
  14. // Content of the AsynchronCall class
  15. // Constructor
  16. // name: The name of the thread
  17. // f: The function to be called asynchronously
  18. // Must be called with new. The object deletes itself
  19. AsynchronCall::AsynchronCall(const char* name, std::function<void()> f)
  20. : Thread()
  21. {
  22. setName(name);
  23. this->finished = 0;
  24. this->f = f;
  25. start();
  26. }
  27. // Constructor
  28. // f: The function to be called asynchronously
  29. // finished: Set to 1 when the call has been processed
  30. // Must be called with new. The object deletes itself
  31. AsynchronCall::AsynchronCall(std::function<void()> f, bool* finished)
  32. : Thread()
  33. {
  34. this->finished = finished;
  35. this->f = f;
  36. if (finished) finished = 0;
  37. start();
  38. }
  39. // Constructor
  40. // name: The name of the thread
  41. // f: The function to be called asynchronously
  42. // finished: Set to 1 when the call has been processed
  43. // Must be called with new. The object deletes itself
  44. AsynchronCall::AsynchronCall(
  45. const char* name, std::function<void()> f, bool* finished)
  46. : Thread()
  47. {
  48. setName(name);
  49. this->finished = finished;
  50. this->f = f;
  51. if (finished) finished = 0;
  52. start();
  53. }
  54. void AsynchronCall::thread()
  55. {
  56. f();
  57. }
  58. void AsynchronCall::threadEnd()
  59. {
  60. Thread::threadEnd();
  61. if (finished) *finished = 1;
  62. release();
  63. }