Embedded Multicore Building Blocks V1.0.0
action.h
1 /*
2  * Copyright (c) 2014-2017, Siemens AG. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef EMBB_MTAPI_ACTION_H_
28 #define EMBB_MTAPI_ACTION_H_
29 
30 #include <embb/mtapi/internal/check_status.h>
31 #include <embb/mtapi/action_attributes.h>
32 #include <embb/mtapi/job.h>
33 
34 namespace embb {
35 namespace mtapi {
36 
42 class Action {
43  public:
49  Action() {
50  handle_.id = 0;
51  handle_.tag = 0;
52  }
53 
59  Action const & other
60  ) : handle_(other.handle_) {
61  // empty
62  }
63 
71  Action const & other
72  ) {
73  handle_ = other.handle_;
74  return *this;
75  }
76 
82  void Delete() {
83  mtapi_action_delete(handle_, MTAPI_INFINITE, MTAPI_NULL);
84  }
85 
93  mtapi_action_hndl_t GetInternal() const {
94  return handle_;
95  }
96 
97  friend class Node;
98 
99  private:
104  Action(
105  mtapi_job_id_t job_id,
107  const void * node_local_data,
109  mtapi_size_t node_local_data_size,
110  mtapi_action_attributes_t const * attributes
112  ) {
113  mtapi_status_t status;
114  handle_ = mtapi_action_create(job_id, func,
115  node_local_data, node_local_data_size,
116  attributes, &status);
117  internal::CheckStatus(status);
118  }
119 
120  mtapi_action_hndl_t handle_;
121 };
122 
123 } // namespace mtapi
124 } // namespace embb
125 
126 #endif // EMBB_MTAPI_ACTION_H_
Definition: lock_free_mpmc_queue.h:40
A singleton representing the MTAPI runtime.
Definition: node.h:70
Action(Action const &other)
Copies an Action.
Definition: action.h:58
Action()
Constructs an Action.
Definition: action.h:49
mtapi_action_hndl_t mtapi_action_create(const mtapi_job_id_t job_id, const mtapi_action_function_t function, const void *node_local_data, const mtapi_size_t node_local_data_size, const mtapi_action_attributes_t *attributes, mtapi_status_t *status)
This function creates a software action (hardware actions are considered to be pre-existent and do no...
void Delete()
Deletes an Action.
Definition: action.h:82
mtapi_action_hndl_t GetInternal() const
Returns the internal representation of this object.
Definition: action.h:93
void(* mtapi_action_function_t)(const void *args, mtapi_size_t args_size, void *result_buffer, mtapi_size_t result_buffer_size, const void *node_local_data, mtapi_size_t node_local_data_size, mtapi_task_context_t *context)
An action function is the executable software function that implements an action. ...
Definition: mtapi.h:941
Action & operator=(Action const &other)
Copies an Action.
Definition: action.h:70
Holds the actual worker function used to execute a Task.
Definition: action.h:42
void mtapi_action_delete(const mtapi_action_hndl_t action, const mtapi_timeout_t timeout, mtapi_status_t *status)
This function deletes a software action (Hardware actions exist perpetually and cannot be deleted)...