acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
matter.h
1#pragma once
2
3
4#include "particle.h"
5#include "pointer.h"
6#include "atom.h"
7#include "factory.h"
8#include "function.h"
9#include "acme/platform/tracer.h"
10#include "acme/prototype/collection/pointer_array.h"
11#include "acme/prototype/collection/procedure_array.h"
12#include "acme/parallelization/synchronous_lock.h"
13
14
15class CLASS_DECL_ACME matter :
16 virtual public ::particle
17{
18public:
19
20
21 typedef void POSTING_PROCEDURE(const ::procedure & procedure);
22 typedef ::payload RETURNING_PROCEDURE();
23
24
25 union
26 {
27
28 ::u32 m_uError;
29
30 struct
31 {
32
33 bool m_bTimeout : 1;
34
35 };
36
37 };
38
39
40 class ::atom m_atomMatterId;
41
42// ::eobject m_eobject;
43
44//#if REFERENCING_DEBUGGING
45// inline matter() : m_pmutex(nullptr), m_pobjrefdbg(nullptr), m_countReference(0), m_uObject(0), system()(nullptr) { increment_reference_count( REFERENCING_DEBUGGING_COMMA_NOTE("Initial Reference")); }
46// inline matter(const eobject& eobject) : m_pmutex(nullptr), m_pobjrefdbg(nullptr), m_countReference(0), m_eobject(eobject), m_uObject(0), system()(nullptr) { increment_reference_count( REFERENCING_DEBUGGING_COMMA_NOTE("Initial Reference (2)")); }
47// inline matter(const matter& matter) : m_pmutex(nullptr), m_pobjrefdbg(nullptr), m_countReference(0), m_eobject(matter.m_eobject), m_uObject(0), system()(nullptr) { if (matter.m_pmutex) defer_create_synchronization(); increment_reference_count( REFERENCING_DEBUGGING_COMMA_NOTE("Initial Reference (3)")); }
48// inline matter(matter&& matter) : m_pmutex(matter.m_pmutex), m_pobjrefdbg(matter.m_pobjrefdbg), m_countReference(matter.m_countReference), m_eobject(matter.m_eobject), m_uObject(0), system()(nullptr) { matter.m_pmutex = nullptr; matter.m_pobjrefdbg = nullptr; }
49//#else
50// inline matter() : m_pmutex(nullptr), m_countReference(1), m_uObject(0), system()(nullptr) { }
51// inline matter(const eobject& eobject) : m_pmutex(nullptr), m_countReference(1), m_eobject(eobject), m_uObject(0), system()(nullptr) { }
52// inline matter(const matter& matter) : m_pmutex(nullptr), m_countReference(1), m_eobject(matter.m_eobject), m_uObject(0), system()(nullptr) { if (matter.m_pmutex) defer_create_synchronization(); }
53// inline matter(matter&& matter) : m_pmutex(matter.m_pmutex), m_countReference(matter.m_countReference), m_eobject(matter.m_eobject), m_uObject(0), system()(nullptr) { matter.m_pmutex = nullptr; }
54//#endif
55
56//#if REFERENCING_DEBUGGING
57// inline matter() : m_pmutex(nullptr), m_estatus(e_status_none), m_ematter(e_element_none), m_uError(0), m_countReference(0), m_eobject(e_object_none), m_papplication(nullptr), m_pobjrefdbg(nullptr) { }
58// inline matter(const eobject& eobject) : m_pmutex(nullptr), m_estatus(e_status_none), m_ematter(e_element_none), m_uError(0), m_countReference(0), m_eobject(eobject), m_papplication(nullptr), m_pobjrefdbg(nullptr) { }
59// inline matter(const matter& matter) : m_pmutex(nullptr), m_estatus(e_status_none), m_ematter(matter.m_ematter), m_uError(matter.m_uError), m_countReference(0), m_eobject(matter.m_eobject), m_papplication(matter.m_papplication), m_pobjrefdbg(nullptr) { }
60// inline matter(matter&& matter) : referenceable(matter),m_pmutex(matter.m_pmutex), m_estatus(e_status_none), m_ematter(matter.m_ematter), m_uError(matter.m_uError), m_countReference(matter.m_countReference), m_eobject(matter.m_eobject), m_papplication(matter.m_papplication), m_pobjrefdbg(matter.m_pobjrefdbg) { matter.m_pmutex = nullptr; matter.m_pobjrefdbg = nullptr; }
61// inline matter(::platform::context * pcontext) : m_papplication(pcontext), m_pmutex(nullptr), m_estatus(e_status_none), m_ematter(e_element_none), m_uError(0), m_eobject(e_object_none), m_pobjrefdbg(matter.m_pobjrefdbg) { }
62//#else
63// inline matter() : m_pmutex(nullptr), m_uError(0), m_eobject(e_object_none) { }
64// inline matter(const eobject& eobject) : m_pmutex(nullptr), m_uError(0), m_eobject(eobject) { }
65// inline matter(const matter& matter) : m_pmutex(nullptr), m_uError(matter.m_uError), m_eobject(matter.m_eobject), m_papplication(matter.m_papplication) { if (matter.m_pmutex) defer_create_synchronization(); }
66// inline matter(matter&& matter) : element(matter), m_pmutex(matter.m_pmutex), m_uError(matter.m_uError), m_eobject(matter.m_eobject), m_papplication(matter.m_papplication) { matter.m_pmutex = nullptr; }
67// inline matter(::platform::context * pcontext) : m_papplication(pcontext), m_pmutex(nullptr), m_uError(0), m_eobject(e_object_none) { }
68//#endif
69
70 matter() { }
71 ~matter() override;
72
73
74 //virtual void assert_ok() const;
75 //virtual void dump(dump_context& dumpcontext) const;
76
77
78 ::atom & id() { return m_atomMatterId; }
79 const ::atom & id() const { return m_atomMatterId; }
80
81
82
83 void operator()(::topic * ptopic, ::handler_context * phandlercontext) override;
84
85 virtual void operator()(::message::message * pmessage);
86 //virtual void operator()(const ::payload & payload);
87
88
90 virtual void handle_command(const ::atom & atom);
91//{
92//
93// //return ::success_none;
94//
95//}
96
97 inline bool has_error() const {return m_uError != 0;}
98
99 //inline bool is_set() const { return ::is_set(this); }
100
101
102
103
104 virtual bool is_ready_to_quit() const;
105
106 // synchronization/::pointer < ::mutex >
107
108 //void branch();
109
110
111 //::platform::context * get_context() const { return (::platform::context *) m_papplication; }
112 //::platform::system * system() const;
113
114 inline ::platform::application * get_app() { return _get_app(); }
115
116 virtual ::platform::application * _get_app();
117
118 virtual bool is_thread_class() const;
119 virtual ::thread * get_thread();
120 virtual bool thread_is_running() const;
121
122
123 virtual ::task * get_task();
124 virtual const_char_pointer get_task_tag();
125 //virtual ::collection::index task_add(::task* pthread);
126 virtual void task_erase(::task* pthread);
127
128 virtual void notify_on_destroy(::property_object * pparticle);
129
130
131 void set_finish() override;
132 void destroy() override;
133
134 virtual void on_set_finish();
135
136
137 //virtual void do_task();
138 //virtual void on_task();
139
140
141 // virtual void task_osinit();
142 // virtual void __task_init();
143 // virtual void __task_main();
144 // virtual void __task_term();
145 // virtual void task_osterm();
146
147
148// virtual void add_composite(::particle * pparticle);
149// virtual void add_reference(::particle * pparticle);
150//
151//
152// virtual void release_composite2(::particle * pparticle);
153// virtual void finalize_composite(::particle * pparticle);
154// virtual void release_reference(::particle * pparticle);
155
156
157 //virtual void set_generic_object_name(const ::scoped_string & scopedstrName);
158
159
160
161 //virtual ::task * defer_branch(const ::atom & atom, const ::procedure & procedure);
162
163
164 //void delete_this() override;
165
166
167 //::particle * clone() const override;
168
169
170 using particle::has_flag;
171 using particle::set_flag;
172 using particle::clear_flag;
173
174
175// inline bool has(const ::eobject& eobject) const { return m_eobject.has(eobject); }
176// inline void set(const ::eobject& eobject, bool bSet) { if (bSet) set(eobject); else clear(eobject); }
177// inline void set(const ::eobject & eobject) { m_eobject |= eobject; }
178// inline void clear(const ::eobject& eobject) { m_eobject -= eobject; }
179
180
181 //inline ::u64 get_object_flag() { return m_eobject; }
182
183
184 //inline bool is(enum_matter ematter) const { return (m_ematter & ematter) == ematter; }
185 //inline void set(enum_matter ematter) { m_ematter = (enum_matter) ((::u32)(m_ematter) | (::u32)(ematter)); }
186 //inline void unset(enum_matter ematter) { m_ematter = (enum_matter)((::u32)(m_ematter) & (~(::u32)(ematter))); }
187
188
189 //inline bool is_finishing() const { return is(e_element_finishing); }
190 //inline void set_finishing() { set(e_element_finishing); }
191 //inline void unset_finishing() { unset(e_element_finishing); }
192
193
194 //inline bool is_heap_allocated() const { return is(e_element_heap_allocated); }
195 //inline void set_heap_allocated() { set(e_element_heap_allocated); }
196 //inline void unset_heap_allocated() { unset(e_element_heap_allocated); }
197
198
199 //inline bool is_destroying() const { return is(e_element_destroying); }
200 //inline void set_destroying() { set(e_element_destroying); }
201 //inline void unset_destroying() { unset(e_element_destroying); }
202
203
204 //virtual void on_finish();
205 //virtual void set_finish(::property_object * pcontextobjectFinish);
206 //virtual void set_finish();
207
208
209 // returns success when object is ready to have destroy called
210 // returns error_pending if any child or ascendant is still active
211 //virtual void finish(::property_object * pcontextobjectFinish = nullptr);
212 //virtual void destroy_composites();
213
214 virtual bool __get_posted_payload_synchronously(const ::function < void(const ::procedure &) > & functionPost, const ::function < ::payload(void) > & functionReturn, ::payload & payload);
215
216 virtual void __send_procedure(const ::function < void(const ::procedure &) > & functionPost, const ::procedure & procedure);
217
218 virtual void post_quit();
219
220
221
222
223
224 inline const ::particle * context_trace_object() const { return this; }
225
226
227 //virtual void __tracea(enum_trace_level elevel, const ::scoped_string & scopedstrFunction, const ::scoped_string & scopedstrFile, ::i32 iLine, const ::scoped_string & scopedstr) const;
228 //virtual void __tracef(enum_trace_level elevel, const ::scoped_string & scopedstrFunction, const ::scoped_string & scopedstrFile, ::i32 iLine, const ::scoped_string & scopedstrFormat, ...) const;
229 //virtual void __tracev(enum_trace_level elevel, const ::scoped_string & scopedstrFunction, const ::scoped_string & scopedstrFile, ::i32 iLine, const ::scoped_string & scopedstrFormat, va_list args) const;
230
231 //virtual void __simple_tracev(enum_trace_level elevel, const ::scoped_string & scopedstrFunction, const ::scoped_string & scopedstrFile, ::i32 iLine, const ::scoped_string & scopedstrFormat, va_list args) const;
232 //virtual void __simple_tracea(enum_trace_level elevel, const ::scoped_string & scopedstrFunction, const ::file::path & path, ::i32 iLine, const ::scoped_string & scopedstr) const;
233
234
235
236
237
238
239
240
241
242 //using particle::trace;
243 //using particle::trace_log_information;
244 //using particle::trace_log_warning;
245 //using particle::trace_log_error;
246 //using particle::trace_log_fatal;
247
248
249 virtual void trace_last_status();
250
251
252 //virtual void on_sequence(const ::payload & payload);
253
254 virtual void clear_member() { }
255
256
257
258 //::pointer < ::subparticle > message_box(const ::scoped_string & scopedstrMessage, const ::scoped_string & scopedstrTitle = nullptr, const ::user::e_message_box & emessagebox = ::user::e_message_box_ok, const ::scoped_string & scopedstrDetails = nullptr);
259
260
261 //::topic_pointer create_topic(const ::atom & atom);
262
263
264 bool _handle_uri(const ::scoped_string & scopedstrUri) override;
265 bool _handle_call(::payload & payload, const ::scoped_string & scopedstrObject, const ::scoped_string & scopedstrMember, ::property_set & propertyset) override;
266
267
268 virtual bool handle_uri(const ::scoped_string & scopedstringUri);
269 virtual bool handle_call(::payload & payload, const ::scoped_string & scopedstrObject, const ::scoped_string & scopedstrMember, ::property_set & propertyset);
270
271
272 inline ::file_pointer get_reader(const ::payload& payloadFile, ::file::e_open eopen = ::file::e_open());
273 inline ::file_pointer get_writer(const ::payload& payloadFile, ::file::e_open eopen = ::file::e_open());
274 inline ::file_pointer fully_shared_reader(const ::payload& payloadFile) { return get_reader(payloadFile, ::file::e_open_share_deny_none); }
275
276 //virtual void to_string(string & str) const override;
277
278 virtual ::string class_title();
279
280
281
282};
283
284
285
286
287
288//template < typename INTERMEDIATE, typename RELEASEE >
289//inline void release(INTERMEDIATE*, RELEASEE* & p)
290//{
291//
292// ::release(p);
293//
294//}
295//
296
297
298class __construct_site
299{
300public:
301
302
303 template < typename T >
304 __construct_site(::pointer < T >& p COMMA_REFERENCING_DEBUGGING_PARAMETERS_DECLARATION)
305 {
306
307 p = __pointer_site(__refdbg_referer__) << new T;
308
309 }
310
311
312};
313
314
315template < typename TYPE >
316inline void __call__raw_construct_new(::pointer<TYPE> & ptype)
317{
318
319 ptype = { transfer_t{}, __new_refdbg_continuation TYPE() };
320
321}
322
323
324template < typename TYPE >
325inline bool __defer_raw_construct_new(::pointer<TYPE> & ptype)
326{
327
328 if(ptype.is_null())
329 {
330
331 __raw_construct_new(ptype);
332
333 return ptype.is_set();
334
335 }
336
337 return false;
338
339}
340
341
342//template < typename TYPE >
343//inline ::pointer<TYPE> matter::createø(::factory::factory * pfactory)
344//{
345//
346// return ::createø<TYPE>(this, pfactory);
347//
348//}
349
350
351
352//
353//template < typename TYPE >
354//inline ::pointer<TYPE>matter::øcreate_by_type(const ::atom & atom, ::factory::factory * pfactory)
355//{
356//
357// auto pfactoryitem = pfactory->get_factory_item(atom);
358//
359// if (!pfactoryitem)
360// {
361//
362// throw_exception(error_no_factory);
363//
364// }
365//
366// auto ptypeNew = pfactoryitem->create_particle();
367//
368// if (!ptypeNew)
369// {
370//
371// throw_exception(error_no_memory);
372//
373// }
374//
375// ::pointer<TYPE>p;
376//
377// p = ptypeNew;
378//
379// if (!p)
380// {
381//
382// throw_exception(error_wrong_type);
383//
384// }
385//
386// p->set_flag(e_flag_factory);
387//
388// //auto estatus = p->initialize(this);
389//
390// p->initialize(this);
391//
392// //if (!estatus)
393// //{
394//
395// // return estatus;
396//
397// //}
398//
399// return ::transfer(p);
400//
401//}
402//
403
404//template < typename TYPE >
405//inline ::pointer<TYPE>matter::create_newø()
406//{
407//
408// return ::create_newø<TYPE>(this);
409//
410//}
411
412
413
414//template < typename BASE_TYPE >
415//inline void matter::øraw_construct(::pointer<BASE_TYPE> & p, ::factory::factory * pfactory)
416//{
417//
418// ::øraw_construct(this, p, pfactory);
460//
461//}
462
463//
464//template < typename TYPE >
465//inline void particle::constructø(::pointer<TYPE> & p, ::factory::factory * pfactory)
466//{
467//
468// ::constructø(this, p, pfactory);
469//
470//}
471
472
473//template < typename BASE_TYPE, typename TYPE >
474//inline void particle::__call__construct(::pointer<BASE_TYPE> & ptype, const ::pointer < TYPE > & p)
475//{
476//
477// __call__construct(ptype, p.m_p);
478//
479//}
480//
481//
482//template < typename BASE_TYPE, typename TYPE >
483//inline void particle::__call__construct(::pointer<BASE_TYPE> & ptype, TYPE * p)
484//{
485//
486// if (::is_null(p))
487// {
488//
489// error() << "particle::constructø p is null";
490//
491// throw_exception(::error_null_pointer);
492//
493// }
494//
495// ptype = p;
496//
497// if (::is_null(ptype))
498// {
499//
500// error() <<"particle::constructø p is null (is assignee type derived from BASE_TYPE?";
501//
502// throw_exception(::error_null_pointer);
503//
504// }
505//
506// ptype->initialize(this);
507//
508//}
509
510
511//template < typename TYPE >
512//inline void particle::øconstruct_by_id(::pointer<TYPE> & p, const ::atom & atom)
513//{
514//
515// ::øconstruct_by_id(this, p, atom);
516//
517//}
518
519
520//
521//template < typename TYPE >
522//inline void matter::construct_newø(::pointer<TYPE> & p)
523//{
524//
525// ::construct_newø(this, p);
526//
527//}
528
529
530//template < typename BASE_TYPE >
531//inline void matter::__release(::pointer<BASE_TYPE> pcomposite)
532//{
533//
534// if (::is_set(pcomposite))
535// {
536//
537// //synchronous_lock synchronouslock(this->synchronization(), DEFAULT_SYNCHRONOUS_LOCK_SUFFIX);
538//
539// //if (m_pcompositea)
540// //{
541//
542// // if (m_pcompositea->erase(pcomposite.get()) >= 0)
543// // {
544//
545// pcomposite.clear_member();
546//
547// // }
548//
549// //}
550//
551// }
552//
553// //return ::success;
554//
555//}
556//
557//
558//template < typename BASE_TYPE >
559//inline void matter::__release(::pointer<BASE_TYPE> preference)
560//{
561//
562// if (::is_set(preference))
563// {
564//
565// //synchronous_lock synchronouslock(this->synchronization(), DEFAULT_SYNCHRONOUS_LOCK_SUFFIX);
566//
567// //if (m_preferencea)
568// //{
569//
570// // if (m_preferencea->erase(preference.get()) >= 0)
571// // {
572//
573// //preference->release();
574//
575// preference.clear_member();
576//
577// // }
578// // else
579// // {
580//
581// // return ::error_failed;
582//
583// // }
584//
585// // }
586//
587// }
588//
589// //return ::success;
590//
591//}
592//
593//
594//template < typename SOURCE >
595//inline void matter::__release(::pointer<SOURCE> psource)
596//{
597//
598// release_reference(psource.m_p);
599//
600//}
601
602
603//CLASS_DECL_ACME void object_on_add_composite(const element* pusermessage);
604
605
606//template < typename BASE_TYPE, typename SOURCE >
607//inline void matter::__refer(::pointer<BASE_TYPE> preference, const ::pointer<SOURCE>psource )
608//{
609//
610// __refer(preference, psource.get() );
611//
612//}
613//
614//
615//template < typename BASE_TYPE, typename SOURCE >
616//inline void matter::__refer(::pointer<BASE_TYPE> preference, const ::prototype::member < SOURCE >& pmember)
617//{
618//
619// __refer(preference, pmember.get() );
620//
621//}
622//
623//
624//template < typename BASE_TYPE, typename SOURCE >
625//inline void matter::__refer(::pointer<BASE_TYPE> preference, const SOURCE* psource)
626//{
627//
628// preference = psource;
629//
630// if (!preference)
631// {
632//
633// throw_exception(error_wrong_type);
634//
635// }
636//
637// add_reference(preference);
638//
639//}
640//
641//
642//template < typename BASE_TYPE, typename SOURCE >
643//inline void matter::__defer_refer(::pointer<BASE_TYPE> preference, const ::pointer<SOURCE>psource )
644//{
645//
646// __defer_refer(preference, psource.get() );
647//
648//}
649//
650//
651//template < typename BASE_TYPE, typename SOURCE >
652//inline void matter::__defer_refer(::pointer<BASE_TYPE> preference, const SOURCE* psource)
653//{
654//
655// if (preference.get() != psource)
656// {
657//
658// __release(preference);
659//
660// preference = psource;
661//
662// if (preference)
663// {
664//
665// add_reference(preference);
666//
667// }
668//
669// }
670//
671//}
672//
673//
674//template < typename SOURCE >
675//inline void matter::add_reference(::pointer<SOURCE> psource )
676//{
677//
678// add_reference(psource.get());
679//
680//}
681//
682//
683//template < typename SOURCE >
684//inline void matter::add_reference(::pointer<SOURCE> preference)
685//{
686//
687// add_reference(preference.get());
688//
689//}
690//
691//
692//template < typename SOURCE >
693//inline void matter::add_reference(SOURCE* psource)
694//{
695//
696// ::particle * pparticle = psource;
697//
698// if (::is_null(pelement))
699// {
700//
701// throw_exception(error_wrong_type);
702//
703// }
704//
705// add_reference(pelement);
706//
707//}
708
709
710inline ::file_pointer matter::get_reader(const ::payload & payloadFile, ::file::e_open eopen)
711{
712
713 return get_file(payloadFile, eopen | ::file::e_open_read);
714
715}
716
717
718inline ::file_pointer matter::get_writer(const ::payload & payloadFile, ::file::e_open eopen)
719{
720
721 return get_file(payloadFile, eopen | ::file::e_open_write);
722
723}
724
725
726
727
Definition pointer.h:1461
Definition atom.h:237
Definition handler_context.h:9
Definition payload.h:54
Definition property_object.h:21
Definition property_set.h:512
Definition task.h:117
Definition topic.h:17
Definition _structures.h:6