Motr  M0
service.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include "lib/memory.h" /* M0_ALLOC_PTR */
24 #include "lib/misc.h" /* M0_SET0 */
25 #include "lib/errno.h" /* ENOENT */
26 
27 #include "net/test/service.h"
28 
40 const static bool
47  },
50  [M0_NET_TEST_SERVICE_READY] = false,
53  },
56  [M0_NET_TEST_SERVICE_READY] = false,
59  },
62  [M0_NET_TEST_SERVICE_READY] = false,
65  },
66 };
67 
70 {
71  M0_PRE(svc != NULL);
72  M0_PRE(ops != NULL);
73 
74  M0_SET0(svc);
75  svc->nts_ops = ops;
76 
78  if (svc->nts_svc_ctx != NULL)
81 
84 
85  return svc->nts_errno;
86 }
87 
89 {
92 
96 }
97 
99 {
100  if (svc == NULL)
101  return false;
102  if (svc->nts_ops == NULL)
103  return false;
104  return true;
105 }
106 
108 {
111 
113  if (svc->nts_errno != 0)
116 
118  return svc->nts_errno;
119 }
120 
122  struct m0_net_test_cmd *cmd,
123  struct m0_net_test_cmd *reply)
124 {
125  struct m0_net_test_service_cmd_handler *handler;
126  int i;
127 
129  M0_PRE(cmd != NULL);
130  M0_PRE(reply != NULL);
132 
133  svc->nts_errno = -ENOENT;
134  for (i = 0; i < svc->nts_ops->ntso_cmd_handler_nr; ++i) {
135  handler = &svc->nts_ops->ntso_cmd_handler[i];
136  if (handler->ntsch_type == cmd->ntc_type) {
137  svc->nts_errno = handler->ntsch_handler(
138  svc->nts_svc_ctx, cmd, reply);
139  break;
140  }
141  }
142 
144  return svc->nts_errno;
145 }
146 
148  enum m0_net_test_service_state state)
149 {
151 
153  svc->nts_state = state;
154 
156 }
157 
160 {
162 
163  return svc->nts_state;
164 }
165 
170 /*
171  * Local variables:
172  * c-indentation-style: "K&R"
173  * c-basic-offset: 8
174  * tab-width: 8
175  * fill-column: 79
176  * scroll-step: 1
177  * End:
178  */
enum m0_net_test_cmd_type ntsch_type
Definition: service.h:52
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
bool m0_net_test_service_invariant(struct m0_net_test_service *svc)
Definition: service.c:98
enum m0_net_test_service_state m0_net_test_service_state_get(struct m0_net_test_service *svc)
Definition: service.c:159
#define ergo(a, b)
Definition: misc.h:293
void m0_net_test_service_state_change(struct m0_net_test_service *svc, enum m0_net_test_service_state state)
Definition: service.c:147
int(* ntso_step)(void *ctx)
Definition: service.h:80
struct m0_net_test_service_ops * nts_ops
Definition: service.h:92
#define M0_SET0(obj)
Definition: misc.h:64
int i
Definition: dir.c:1033
int m0_net_test_service_step(struct m0_net_test_service *svc)
Definition: service.c:107
#define M0_ASSERT(cond)
struct m0_net_test_service_cmd_handler * ntso_cmd_handler
Definition: service.h:82
#define M0_POST(cond)
enum m0_net_test_service_state nts_state
Definition: service.h:94
size_t ntso_cmd_handler_nr
Definition: service.h:84
void m0_net_test_service_fini(struct m0_net_test_service *svc)
Definition: service.c:88
int m0_net_test_service_cmd_handle(struct m0_net_test_service *svc, struct m0_net_test_cmd *cmd, struct m0_net_test_cmd *reply)
Definition: service.c:121
m0_net_test_service_state
Definition: service.h:60
int(* ntsch_handler)(void *ctx, const struct m0_net_test_cmd *cmd, struct m0_net_test_cmd *reply)
Definition: service.h:54
static struct m0_net_test_service svc
Definition: service.c:34
void * nts_svc_ctx
Definition: service.h:90
enum m0_net_test_cmd_type ntc_type
Definition: commands.h:204
void(* ntso_fini)(void *ctx)
Definition: service.h:78
void *(* ntso_init)(struct m0_net_test_service *svc)
Definition: service.h:76
struct m0_fom_ops ops
Definition: io_foms.c:623
static struct m0_dtm_oper_descr reply
Definition: transmit.c:94
int m0_net_test_service_init(struct m0_net_test_service *svc, struct m0_net_test_service_ops *ops)
Definition: service.c:68