1 /*
2 	SObjectizer 5
3 */
4 
5 /*!
6 	\file
7 	\brief Error codes.
8 */
9 
10 #pragma once
11 
12 #include <so_5/declspec.hpp>
13 
14 #include <iostream>
15 
16 namespace so_5
17 {
18 
19 //
20 // Standard error codes.
21 //
22 
23 //! so_environment launch is failed.
24 const int rc_environment_error = 1;
25 
26 //! \name Error codes for agent's methods.
27 //! \{
28 
29 //! Trying to switch to the unknown state.
30 const int rc_agent_unknown_state = 10;
31 
32 //! Agent is already bound to the SObjectizer Environment.
33 const int rc_agent_is_already_bind_to_env = 11;
34 
35 //! Agent is already bound to the dispatcher.
36 const int rc_agent_is_already_bind_to_disp = 12;
37 
38 //! Dispatcher with that name is not found.
39 const int rc_named_disp_not_found = 13;
40 
41 //! Agent is not bound to a cooperation.
42 const int rc_agent_has_no_cooperation = 14;
43 
44 //! It is impossible to make a cast to that type.
45 const int rc_agent_incompatible_type_conversion = 15;
46 
47 /*!
48  * \since
49  * v.5.4.0
50  *
51  * \brief An attempt to perform an operation which is enabled only
52  * on agent's working thread.
53  */
54 const int rc_operation_enabled_only_on_agent_working_thread = 16;
55 
56 /*!
57  * \since
58  * v.5.5.15
59  *
60  * \brief An attempt to change agent state to a new composite state which
61  * have no initial state defined.
62  */
63 const int rc_no_initial_substate = 17;
64 
65 /*!
66  * \since
67  * v.5.5.15
68  *
69  * \brief Nesting of agent states is too deep.
70  */
71 const int rc_state_nesting_is_too_deep = 18;
72 
73 /*!
74  * \since
75  * v.5.5.15
76  *
77  * \brief Initial substate for a composite state is already defined.
78  */
79 const int rc_initial_substate_already_defined = 19;
80 
81 //! \}
82 
83 //! \name Error codes for cooperations of agents.
84 //! \{
85 
86 //! A zero pointer is detected.
87 const int rc_zero_ptr_to_coop = 20;
88 
89 //! Cooperation name is not unique.
90 const int rc_coop_with_specified_name_is_already_registered = 21;
91 
92 //! Cooperation has the null reference to an agent or dispatcher binding.
93 const int rc_coop_has_references_to_null_agents_or_binders = 22;
94 
95 //! There is no registered cooperation with that name.
96 const int rc_coop_has_not_found_among_registered_coop = 23;
97 
98 //! Cooperation couldn't be registered.
99 const int rc_coop_define_agent_failed = 24;
100 
101 /*!
102  * \since
103  * v.5.4.0
104  *
105  * \brief Binding of agent to dispatcher failed.
106  */
107 const int rc_agent_to_disp_binding_failed = 27;
108 
109 /*!
110  * \since
111  * v.5.4.0.1
112  *
113  * \brief It is impossible to register cooperation during
114  * SObjectizer Environment shutdown.
115  */
116 const int rc_unable_to_register_coop_during_shutdown = 28;
117 //! \}
118 
119 
120 //! \name Error codes for dispatchers.
121 //! \{
122 
123 //! Unable to start a dispatcher.
124 const int rc_disp_start_failed = 30;
125 
126 //! Unable to create a dispatcher.
127 const int rc_disp_create_failed = 31;
128 
129 //! The expected type of dispatcher and the actual type of the
130 //! agent dispatcher are not the same.
131 const int rc_disp_type_mismatch = 32;
132 
133 /*!
134  * \since
135  * v.5.4.0
136  *
137  * \brief New dispatcher cannot be added because of illegal
138  * state of SObjectizer Environment.
139  */
140 const int rc_disp_cannot_be_added = 34;
141 
142 //! \}
143 
144 //! \name Error codes for event handlers and message interceptors registration.
145 //! \{
146 
147 //! A handler for that event/mbox/state is already registered.
148 const int rc_evt_handler_already_provided = 40;
149 
150 //! A handler for that event/mbox/state is not registered and cannot be
151 //! deregistered.
152 const int rc_no_event_handler_provided = 41;
153 
154 //! Unable to deregister that handler.
155 /*!
156  * There is a handler for the event/mbox/state, but it is another handler.
157  * Not the one is specified for the deregistration.
158  */
159 const int rc_event_handler_match_error = 42;
160 
161 //! Agent doesn't own this state.
162 const int rc_agent_is_not_the_state_owner = 43;
163 
164 //! An interceptor for the event/mbox/state is already registered.
165 const int rc_intercept_handler_already_provided = 44;
166 
167 //! An interceptor for the event/mbox/state is not registered and
168 //! cannot be deregistered.
169 const int rc_no_interception_handler_provided = 45;
170 
171 //! Unable to deregister this interceptor.
172 /*!
173  * There is an interceptor for the event/mbox/state, but it is another handler.
174  * Not the one is specified for the deregistration.
175  */
176 const int rc_interception_handler_match_error = 46;
177 
178 /*!
179  * \since
180  * v.5.4.0
181  *
182  * \brief An attempt to create illegal subscription to mpsc_mbox.
183  */
184 const int rc_illegal_subscriber_for_mpsc_mbox = 47;
185 
186 /*!
187  * \since
188  * v.5.5.4
189  *
190  * \brief An attempt to create subscription to message without
191  * predefined limit for that message type.
192  */
193 const int rc_message_has_no_limit_defined = 48;
194 
195 /*!
196  * \since
197  * v.5.5.4
198  *
199  * \brief An attempt to define several limits for one message type.
200  */
201 const int rc_several_limits_for_one_message_type = 49;
202 
203 //! \}
204 
205 //! \name Error codes for mboxes.
206 //! \{
207 
208 //! The mbox name is not unique.
209 const int rc_mbox_duplicating_name = 80;
210 
211 //! The name of mbox is unknown.
212 const int rc_mbox_unable_to_find_mbox = 81;
213 
214 //! Null message data.
215 /*!
216  * \since
217  * v.5.2.0
218  *
219  *
220  * An attempt to deliver message_t by nullptr pointer to it is an error.
221  * A signal should be used for this.
222  */
223 const int rc_null_message_data = 82;
224 
225 /*!
226  * \since
227  * v.5.3.0
228  *
229  * \brief No handlers for service request found.
230  */
231 const int rc_no_svc_handlers = 83;
232 
233 /*!
234  * \since
235  * v.5.3.0
236  *
237  * \brief There are more then one handler for service request.
238  */
239 const int rc_more_than_one_svc_handler = 84;
240 
241 /*!
242  * \since
243  * v.5.3.0
244  *
245  * \brief Service request has not been handled. Service handler
246  * is disabled in the current agent state.
247  */
248 const int rc_svc_not_handled = 85;
249 
250 /*!
251  * \since
252  * v.5.3.0
253  *
254  * \brief Service request result has not beed received yet.
255  */
256 const int rc_svc_result_not_received_yet = 86;
257 
258 /*!
259  * \since
260  * v.5.3.0
261  *
262  * \brief Unable to cast service call description object to
263  * the appropriate type.
264  *
265  * This error is possible when type of service request doesn't match
266  * actual type of request handler. For example:
267  *
268  *
269 \code
270 // Actual service type.
271 int a_some_svc_t::evt_query_state( mhood_t< msg_query_state > )
272 	{ ... }
273 
274 // Service request call with wrong return type.
275 mbox.get_one< std::string >().wait_forever().sync_get<msg_query_state>();
276 \endcode
277  */
278 const int rc_msg_service_request_bad_cast = 87;
279 
280 /*!
281  * \since
282  * v.5.5.4.
283  *
284  * \brief Unable to transform service request as part of overlimit reaction.
285  */
286 const int rc_svc_request_cannot_be_transfomred_on_overlimit = 88;
287 
288 /*!
289  * \since
290  * v.5.5.5
291  *
292  * \brief Delivery filter is not applicable to MPSC-mboxes.
293  */
294 const int rc_delivery_filter_cannot_be_used_on_mpsc_mbox = 89;
295 
296 //! \}
297 
298 //! \name Error codes for delayed or repeated events.
299 //! \{
300 
301 //! Unable to schedule a timer event.
302 const int rc_unable_to_schedule_timer_act = 90;
303 //! \}
304 
305 //! \name Error codes for layers.
306 //! \{
307 
308 //! The layer is not bound to the SObjectizer Environment.
309 const int rc_layer_not_binded_to_so_env = 100;
310 
311 //! Unable to bind a layer by the null pointer to it.
312 const int rc_trying_to_add_nullptr_extra_layer = 101;
313 
314 //! The layer is already bound to the SObjectizer Environment as a default layer.
315 const int rc_trying_to_add_extra_layer_that_already_exists_in_default_list = 102;
316 
317 //! The layer is already bound to the SObjectizer Environment as an extra layer.
318 const int rc_trying_to_add_extra_layer_that_already_exists_in_extra_list = 103;
319 
320 //! Layer initialization is failed.
321 const int rc_unable_to_start_extra_layer = 104;
322 
323 //! A layer with the specified type doesn't exist.
324 const int rc_layer_does_not_exist = 105;
325 //! \}
326 
327 //! \name Error codes for priorities.
328 //! \{
329 
330 //! Illegal value of quote for a priority.
331 const int rc_priority_quote_illegal_value = 120;
332 
333 //! \}
334 
335 //! \name Error codes for SObjectizer Environment related errors.
336 //! \{
337 
338 //! Message delivery tracing is disabled and cannot be used.
339 const int rc_msg_tracing_disabled = 140;
340 
341 //! \}
342 
343 //! \name Error codes for message chains.
344 //! \{
345 
346 //! Attempt to get message from empty message queue.
347 const int rc_msg_chain_is_empty = 160;
348 
349 //! Attempt to push a message to full message queue.
350 const int rc_msg_chain_is_full = 161;
351 
352 //! Attempt to make subscription for message chain.
353 const int rc_msg_chain_doesnt_support_subscriptions = 162;
354 
355 //! Attempt to set delivery_filter for message chain.
356 const int rc_msg_chain_doesnt_support_delivery_filters = 163;
357 
358 //! Attempt to added a message to full message chain when
359 //! throw_exception overflow reaction is used.
360 const int rc_msg_chain_overflow = 164;
361 
362 //! Attempt to define several handlers for one msg_type.
363 const int rc_several_handlers_for_one_message_type = 165;
364 
365 //! \}
366 
367 /*!
368  * \brief An attempt to switch agent state when another switch operation
369  * is in progress.
370  *
371  * \since
372  * v.5.5.18
373  */
374 const int rc_another_state_switch_in_progress = 170;
375 
376 /*!
377  * \brief An attempt to launch environment with autoshutdown disabled in
378  * conditions where autoshutdown must be enabled.
379  *
380  * For example so_5::env_infrastructures::simple_not_mtsafe requires
381  * autoshutdown feature.
382  *
383  * \since
384  * v.5.5.19
385  */
386 const int rc_autoshutdown_must_be_enabled = 171;
387 
388 /*!
389  * \brief An attempt to deliver mutable message via MPMC mbox.
390  *
391  * \since
392  * v.5.5.19
393  */
394 const int rc_mutable_msg_cannot_be_delivered_via_mpmc_mbox = 172;
395 
396 /*!
397  * \brief An attempt to send mutable message as a periodic message
398  *
399  * \since
400  * v.5.5.19
401  */
402 const int rc_mutable_msg_cannot_be_periodic = 173;
403 
404 /*!
405  * \brief An attempt to make subscription on mutable message from
406  * MPMC mbox.
407  *
408  * Delivery of mutable messages via MPMC mboxes is prohibited.
409  *
410  * \since
411  * v.5.5.19
412  */
413 const int rc_subscription_to_mutable_msg_from_mpmc_mbox = 174;
414 
415 /*!
416  * \brief An attempt to set up a new stop_guard when the stop operation
417  * is already in progress.
418  *
419  * \since
420  * v.5.5.19.2
421  */
422 const int rc_cannot_set_stop_guard_when_stop_is_started = 175;
423 
424 /*!
425  * \brief An attempt to use negative value for pause argument for
426  * delayed or periodic message/signal.
427  *
428  * A value of `pause` argument for so_5::send_delayed() and
429  * so_5::send_periodic() must be non-negative.
430  *
431  * \since
432  * v.5.5.21
433  */
434 const int rc_negative_value_for_pause = 176;
435 
436 /*!
437  * \brief An attempt to use negative value for period argument for
438  * periodic message/signal.
439  *
440  * A value of `pause` argument for so_5::send_periodic() must be non-negative.
441  *
442  * \since
443  * v.5.5.21
444  */
445 const int rc_negative_value_for_period = 177;
446 
447 /*!
448  * \brief A loop in transfer_to_state detected.
449  *
450  * There could be a case when usage of transfer_to_state leads to a loop.
451  * For a very simple example:
452  * \code
453  * class a_two_state_loop_t final : public so_5::agent_t
454  * {
455  * 	state_t st_one{ this, "one" };
456  * 	state_t st_two{ this, "two" };
457  *
458  * 	struct message {};
459  *
460  * public :
461  * 	a_two_state_loop_t(context_t ctx) : so_5::agent_t{ctx} {
462  * 		this >>= st_one;
463  *
464  * 		st_one.transfer_to_state<message>(st_two);
465  * 		st_two.transfer_to_state<message>(st_one);
466  * 	}
467  *
468  * 	virtual void so_evt_start() override {
469  * 		so_5::send<message>(*this);
470  * 	}
471  * };
472  * \endcode
473  * Since v.5.5.22.1 an attempt to handle `message` in the example above
474  * will lead to an exception with this error code.
475  *
476  * Note that there could be more tricky examples when hierarchical states
477  * are used:
478  * \code
479  * class a_hsm_case_t final : public so_5::agent_t
480  * {
481  * 	state_t st_base{ this, "base" };
482  * 	state_t st_disconnected{ initial_substate_of{st_base}, "disconnected" };
483  * 	state_t st_connected{ substate_of{st_base}, "connected" };
484  *
485  * 	struct message {};
486  *
487  * public :
488  * 	a_hsm_case_t(context_t ctx) : so_5::agent_t{ctx} {
489  * 		this >>= st_base;
490  *
491  * 		st_base.transfer_to_state<message>(st_disconnected);
492  * 	}
493  *
494  * 	virtual void so_evt_start() override {
495  * 		so_5::send<message>(*this);
496  * 	}
497  * };
498  * \endcode
499  *
500  * \since
501  * v.5.5.22.1
502  */
503 const int rc_transfer_to_state_loop = 178;
504 
505 /*!
506  * \brief An attempt to cast message to message envelope when
507  * a pointer to message is NULL.
508  *
509  * Envelopes were introduced in v.5.5.23. Envelopes are sent and
510  * delivered as ordinary messages (it means that pointer to envelope
511  * will be sent as pointer to message_t). For processing of an envelope
512  * it is necessary to cast a pointer from message_t to envelope_t.
513  * But it is impossible if a pointer to message_t is null.
514  *
515  * \since
516  * v.5.5.23
517  */
518 const int rc_attempt_to_cast_to_envelope_on_nullptr = 180;
519 
520 /*!
521  * \brief New step can't be defined if testing scenario is already
522  * started or finished.
523  *
524  * \since
525  * v.5.5.24
526  */
527 const int rc_unable_to_define_new_step = 181;
528 
529 /*!
530  * \brief Testing scenario must be completed before an attempt
531  * to do the current operation.
532  *
533  * \since
534  * v.5.5.24
535  */
536 const int rc_scenario_must_be_completed = 182;
537 
538 /*!
539  * \brief There is no stored state name in the testing scenario.
540  *
541  * \since
542  * v.5.5.24
543  */
544 const int rc_stored_state_name_not_found = 183;
545 
546 /*!
547  * \brief An attempt to get a pointer to already destroyed cooperation.
548  *
549  * This error can be reported when a coop_handle instance for already
550  * destroyed coop is used.
551  *
552  * \since
553  * v.5.6.0
554  */
555 const int rc_coop_already_destroyed = 184;
556 
557 /*!
558  * \brief An attempt to do something with coop that is not in registered
559  * state.
560  *
561  * For example if can be an attempt to add a new child coop when
562  * the parent coop is being deregistered.
563  *
564  * \since
565  * v.5.6.0
566  */
567 const int rc_coop_is_not_in_registered_state = 185;
568 
569 /*!
570  * \brief An attempt to call join() from the joinable thread itself.
571  *
572  * \since
573  * v.5.6.0
574  */
575 const int rc_unable_to_join_thread_by_itself = 186;
576 
577 /*!
578  * \brief An attempt to modify or activate extensible-select when an operation
579  * on that extensible-select object is already active.
580  *
581  * \since
582  * v.5.6.1
583  */
584 const int rc_extensible_select_is_active_now = 187;
585 
586 /*!
587  * \brief An attempt to activate prepared-select when an operation
588  * on that prepared-select object is already active.
589  *
590  * \since
591  * v.5.6.1
592  */
593 const int rc_prepared_select_is_active_now = 188;
594 
595 //! \name Common error codes.
596 //! \{
597 
598 //! The empty name doesn't allowed.
599 const int rc_empty_name = 500;
600 
601 /*!
602  * \brief Invalid value of time limit for an agent's state.
603  * \since
604  * v.5.5.15
605  */
606 const int rc_invalid_time_limit_for_state = 501;
607 
608 /*!
609  * \brief Feature or method has no implementation yet.
610  * \since
611  * v.5.5.16
612  */
613 const int rc_not_implemented = 502;
614 
615 /*!
616  * \brief An exception of unknown type is caught.
617  *
618  * SObjectizer expects that all exceptions are derived from std::exception
619  * class.
620  *
621  * \since
622  * v.5.5.24.3
623  */
624 const int rc_unknown_exception_type = 503;
625 
626 //! Unclassified error.
627 const int rc_unexpected_error = 0xFFFFFF;
628 //! \}
629 
630 } /* namespace so_5 */
631 
632