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 #include <assert.h>
28 
29 #include <embb/mtapi/c/mtapi.h>
30 
31 #include <embb_mtapi_log.h>
32 #include <mtapi_status_t.h>
33 #include <embb_mtapi_attr.h>
34 
35 
36 /* ---- INTERFACE FUNCTIONS ------------------------------------------------ */
37 
mtapi_actionattr_init(MTAPI_OUT mtapi_action_attributes_t * attributes,MTAPI_OUT mtapi_status_t * status)38 void mtapi_actionattr_init(
39   MTAPI_OUT mtapi_action_attributes_t* attributes,
40   MTAPI_OUT mtapi_status_t* status) {
41   mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
42 
43   embb_mtapi_log_trace("mtapi_actionattr_init() called\n");
44 
45   if (MTAPI_NULL != attributes) {
46     attributes->domain_shared = MTAPI_TRUE;
47     attributes->global = MTAPI_TRUE;
48     mtapi_affinity_init(&attributes->affinity, MTAPI_TRUE, &local_status);
49   } else {
50     local_status = MTAPI_ERR_PARAMETER;
51   }
52 
53   mtapi_status_set(status, local_status);
54 }
55 
mtapi_actionattr_set(MTAPI_INOUT mtapi_action_attributes_t * attributes,MTAPI_IN mtapi_uint_t attribute_num,MTAPI_IN void * attribute,MTAPI_IN mtapi_size_t attribute_size,MTAPI_OUT mtapi_status_t * status)56 void mtapi_actionattr_set(
57   MTAPI_INOUT mtapi_action_attributes_t* attributes,
58   MTAPI_IN mtapi_uint_t attribute_num,
59   MTAPI_IN void* attribute,
60   MTAPI_IN mtapi_size_t attribute_size,
61   MTAPI_OUT mtapi_status_t* status) {
62   mtapi_status_t local_status = MTAPI_ERR_UNKNOWN;
63 
64   embb_mtapi_log_trace("mtapi_actionattr_set() called\n");
65 
66   if (MTAPI_NULL != attributes) {
67     if (MTAPI_ATTRIBUTE_POINTER_AS_VALUE != attribute_size &&
68       MTAPI_NULL == attribute) {
69       local_status = MTAPI_ERR_PARAMETER;
70     } else {
71       switch (attribute_num) {
72       case MTAPI_ACTION_GLOBAL:
73         local_status = embb_mtapi_attr_set_mtapi_boolean_t(
74           &attributes->global, attribute, attribute_size);
75         break;
76 
77       case MTAPI_ACTION_AFFINITY:
78         local_status = embb_mtapi_attr_set_mtapi_affinity_t(
79           &attributes->affinity, attribute, attribute_size);
80         break;
81 
82       case MTAPI_ACTION_DOMAIN_SHARED:
83         local_status = embb_mtapi_attr_set_mtapi_boolean_t(
84           &attributes->domain_shared, attribute, attribute_size);
85         break;
86 
87       default:
88         /* attribute unknown */
89         local_status = MTAPI_ERR_ATTR_NUM;
90         break;
91       }
92     }
93   } else {
94     /* this should not happen, if someone calls set, a valid action_attributes
95        pointer should be supplied */
96     local_status = MTAPI_ERR_PARAMETER;
97   }
98 
99   mtapi_status_set(status, local_status);
100 }
101