00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00050 #ifndef TOPPERS_OBJECT_HPP_
00051 #define TOPPERS_OBJECT_HPP_
00052
00053 #include <toppers/raw_stub.hpp>
00054 #include <toppers/assert.hpp>
00055 #include <toppers/diagnostics.hpp>
00056
00057 #ifndef TOPPERS_DEFAULT_STUB
00058 #define TOPPERS_DEFAULT_STUB raw_stub<>
00059 #endif
00060
00061 namespace toppers
00062 {
00063
00076 template <ID Id>
00077 class object_id
00078 {
00079
00080
00081 public:
00083 object_id() {}
00085 explicit object_id(ID id)
00086 {
00087 TOPPERS_ASSERT(id == Id);
00088 }
00090 void attach(ID) {}
00092 ID detach() { return Id; }
00094 ID id() const { return Id; }
00095 };
00096
00097 template <>
00098 class object_id<0>
00099 {
00100 ER_ID id_;
00101
00102 public:
00103 object_id() : id_(E_ID) {}
00104 explicit object_id(ID id) : id_(id) {}
00105 void attach(ID id) { id_ = id; }
00106 ID detach() { ID prev = id_; id_ = E_ID; return (ID)prev; }
00107 ID id() const { return (ID)id_; }
00108 };
00109
00122 template <ID Id, object_type Object, class Stub>
00123 class object_controller;
00124
00125 template <ID Id, class Stub>
00126 class object_controller<Id, obj_semaphore, Stub>
00127 {
00128 public:
00129 typedef t_csem creation;
00130 typedef t_rsem reference;
00131
00132 static ER create(object_id<Id>& objid, creation* pk_cobj)
00133 {
00134 if (Id == 0)
00135 {
00136 ER_ID erid = Stub::stub_acre_sem(pk_cobj);
00137 if (erid > 0)
00138 {
00139 objid.attach(erid);
00140 erid = 0;
00141 }
00142 return static_cast<ER>(erid);
00143 }
00144 return Stub::stub_cre_sem(objid.id(), pk_cobj);
00145 }
00146 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00147 {
00148 if (Id == 0)
00149 {
00150 ER_ID erid = Stub::stub_acre_sem(pk_cobj);
00151 if (erid > 0)
00152 {
00153 objid.attach(erid);
00154 erid = 0;
00155 }
00156 return static_cast<ER>(erid);
00157 }
00158 return Stub::stub_cre_sem(objid.id(), pk_cobj);
00159 }
00160 static ER destroy(object_id<Id>& objid)
00161 {
00162 ER ercd = Stub::stub_del_sem(objid.id());
00163 if (ercd == E_OK)
00164 objid.detach();
00165 return ercd;
00166 }
00167 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00168 {
00169 return Stub::stub_ref_sem(objid.id(), pk_robj);
00170 }
00171 };
00172
00173 template <ID Id, class Stub>
00174 class object_controller<Id, obj_eventflag, Stub>
00175 {
00176 public:
00177 typedef t_cflg creation;
00178 typedef t_rflg reference;
00179
00180 static ER create(object_id<Id>& objid, creation* pk_cobj)
00181 {
00182 if (Id == 0)
00183 {
00184 ER_ID erid = Stub::stub_acre_flg(pk_cobj);
00185 if (erid > 0)
00186 {
00187 objid.attach(erid);
00188 erid = 0;
00189 }
00190 return static_cast<ER>(erid);
00191 }
00192 return Stub::stub_cre_flg(objid.id(), pk_cobj);
00193 }
00194 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00195 {
00196 if (Id == 0)
00197 {
00198 ER_ID erid = Stub::stub_acre_flg(pk_cobj);
00199 if (erid > 0)
00200 {
00201 objid.attach(erid);
00202 erid = 0;
00203 }
00204 return static_cast<ER>(erid);
00205 }
00206 return Stub::stub_cre_flg(objid.id(), pk_cobj);
00207 }
00208 static ER destroy(object_id<Id>& objid)
00209 {
00210 ER ercd = Stub::stub_del_flg(objid.id());
00211 if (ercd == E_OK)
00212 objid.detach();
00213 return ercd;
00214 }
00215 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00216 {
00217 return Stub::stub_ref_flg(objid.id(), pk_robj);
00218 }
00219 };
00220
00221 template <ID Id, class Stub>
00222 class object_controller<Id, obj_dataqueue, Stub>
00223 {
00224 public:
00225 typedef t_cdtq creation;
00226 typedef t_rdtq reference;
00227
00228 static ER create(object_id<Id>& objid, creation* pk_cobj)
00229 {
00230 if (Id == 0)
00231 {
00232 ER_ID erid = Stub::stub_acre_dtq(pk_cobj);
00233 if (erid > 0)
00234 {
00235 objid.attach(erid);
00236 erid = 0;
00237 }
00238 return static_cast<ER>(erid);
00239 }
00240 return Stub::stub_cre_dtq(objid.id(), pk_cobj);
00241 }
00242 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00243 {
00244 if (Id == 0)
00245 {
00246 ER_ID erid = Stub::stub_acre_dtq(pk_cobj);
00247 if (erid > 0)
00248 {
00249 objid.attach(erid);
00250 erid = 0;
00251 }
00252 return static_cast<ER>(erid);
00253 }
00254 return Stub::stub_cre_dtq(objid.id(), pk_cobj);
00255 }
00256 static ER destroy(object_id<Id>& objid)
00257 {
00258 ER ercd = Stub::stub_del_dtq(objid.id());
00259 if (ercd == E_OK)
00260 objid.detach();
00261 return ercd;
00262 }
00263 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00264 {
00265 return Stub::stub_ref_dtq(objid.id(), pk_robj);
00266 }
00267 };
00268
00269 template <ID Id, class Stub>
00270 class object_controller<Id, obj_mailbox, Stub>
00271 {
00272 public:
00273 typedef t_cmbx creation;
00274 typedef t_rmbx reference;
00275
00276 static ER create(object_id<Id>& objid, creation* pk_cobj)
00277 {
00278 if (Id == 0)
00279 {
00280 ER_ID erid = Stub::stub_acre_mbx(pk_cobj);
00281 if (erid > 0)
00282 {
00283 objid.attach(erid);
00284 erid = 0;
00285 }
00286 return static_cast<ER>(erid);
00287 }
00288 return Stub::stub_cre_mbx(objid.id(), pk_cobj);
00289 }
00290 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00291 {
00292 if (Id == 0)
00293 {
00294 ER_ID erid = Stub::stub_acre_mbx(pk_cobj);
00295 if (erid > 0)
00296 {
00297 objid.attach(erid);
00298 erid = 0;
00299 }
00300 return static_cast<ER>(erid);
00301 }
00302 return Stub::stub_cre_mbx(objid.id(), pk_cobj);
00303 }
00304 static ER destroy(object_id<Id>& objid)
00305 {
00306 ER ercd = Stub::stub_del_mbx(objid.id());
00307 if (ercd == E_OK)
00308 objid.detach();
00309 return ercd;
00310 }
00311 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00312 {
00313 return Stub::stub_ref_mbx(objid.id(), pk_robj);
00314 }
00315 };
00316
00317 template <ID Id, class Stub>
00318 class object_controller<Id, obj_mutex, Stub>
00319 {
00320 public:
00321 typedef t_cmtx creation;
00322 typedef t_rmtx reference;
00323
00324 static ER create(object_id<Id>& objid, creation* pk_cobj)
00325 {
00326 if (Id == 0)
00327 {
00328 ER_ID erid = Stub::stub_acre_mtx(pk_cobj);
00329 if (erid > 0)
00330 {
00331 objid.attach(erid);
00332 erid = 0;
00333 }
00334 return static_cast<ER>(erid);
00335 }
00336 return Stub::stub_cre_mtx(objid.id(), pk_cobj);
00337 }
00338 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00339 {
00340 if (Id == 0)
00341 {
00342 ER_ID erid = Stub::stub_acre_mtx(pk_cobj);
00343 if (erid > 0)
00344 {
00345 objid.attach(erid);
00346 erid = 0;
00347 }
00348 return static_cast<ER>(erid);
00349 }
00350 return Stub::stub_cre_mtx(objid.id(), pk_cobj);
00351 }
00352 static ER destroy(object_id<Id>& objid)
00353 {
00354 ER ercd = Stub::stub_del_mtx(objid.id());
00355 if (ercd == E_OK)
00356 objid.detach();
00357 return ercd;
00358 }
00359 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00360 {
00361 return Stub::stub_ref_mtx(objid.id(), pk_robj);
00362 }
00363 };
00364
00365 template <ID Id, class Stub>
00366 class object_controller<Id, obj_messagebuffer, Stub>
00367 {
00368 public:
00369 typedef t_cmbf creation;
00370 typedef t_rmbf reference;
00371
00372 static ER create(object_id<Id>& objid, creation* pk_cobj)
00373 {
00374 if (Id == 0)
00375 {
00376 ER_ID erid = Stub::stub_acre_mbf(pk_cobj);
00377 if (erid > 0)
00378 {
00379 objid.attach(erid);
00380 erid = 0;
00381 }
00382 return static_cast<ER>(erid);
00383 }
00384 return Stub::stub_cre_mbf(objid.id(), pk_cobj);
00385 }
00386 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00387 {
00388 if (Id == 0)
00389 {
00390 ER_ID erid = Stub::stub_acre_mbf(pk_cobj);
00391 if (erid > 0)
00392 {
00393 objid.attach(erid);
00394 erid = 0;
00395 }
00396 return static_cast<ER>(erid);
00397 }
00398 return Stub::stub_cre_mbf(objid.id(), pk_cobj);
00399 }
00400 static ER destroy(object_id<Id>& objid)
00401 {
00402 ER ercd = Stub::stub_del_mbf(objid.id());
00403 if (ercd == E_OK)
00404 objid.detach();
00405 return ercd;
00406 }
00407 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00408 {
00409 return Stub::stub_ref_mbf(objid.id(), pk_robj);
00410 }
00411 };
00412
00413 template <ID Id, class Stub>
00414 class object_controller<Id, obj_rendezvousport, Stub>
00415 {
00416 public:
00417 typedef t_cpor creation;
00418 typedef t_rpor reference;
00419
00420 static ER create(object_id<Id>& objid, creation* pk_cobj)
00421 {
00422 if (Id == 0)
00423 {
00424 ER_ID erid = Stub::stub_acre_por(pk_cobj);
00425 if (erid > 0)
00426 {
00427 objid.attach(erid);
00428 erid = 0;
00429 }
00430 return static_cast<ER>(erid);
00431 }
00432 return Stub::stub_cre_por(objid.id(), pk_cobj);
00433 }
00434 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00435 {
00436 if (Id == 0)
00437 {
00438 ER_ID erid = Stub::stub_acre_por(pk_cobj);
00439 if (erid > 0)
00440 {
00441 objid.attach(erid);
00442 erid = 0;
00443 }
00444 return static_cast<ER>(erid);
00445 }
00446 return Stub::stub_cre_por(objid.id(), pk_cobj);
00447 }
00448 static ER destroy(object_id<Id>& objid)
00449 {
00450 ER ercd = Stub::stub_del_por(objid.id());
00451 if (ercd == E_OK)
00452 objid.detach();
00453 return ercd;
00454 }
00455 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00456 {
00457 return Stub::stub_ref_por(objid.id(), pk_robj);
00458 }
00459 };
00460
00461 template <ID Id, class Stub>
00462 class object_controller<Id, obj_fmempool, Stub>
00463 {
00464 public:
00465 typedef t_cmpf creation;
00466 typedef t_rmpf reference;
00467
00468 static ER create(object_id<Id>& objid, creation* pk_cobj)
00469 {
00470 if (Id == 0)
00471 {
00472 ER_ID erid = Stub::stub_acre_mpf(pk_cobj);
00473 if (erid > 0)
00474 {
00475 objid.attach(erid);
00476 erid = 0;
00477 }
00478 return static_cast<ER>(erid);
00479 }
00480 return Stub::stub_cre_mpf(objid.id(), pk_cobj);
00481 }
00482 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00483 {
00484 if (Id == 0)
00485 {
00486 ER_ID erid = Stub::stub_acre_mpf(pk_cobj);
00487 if (erid > 0)
00488 {
00489 objid.attach(erid);
00490 erid = 0;
00491 }
00492 return static_cast<ER>(erid);
00493 }
00494 return Stub::stub_cre_mpf(objid.id(), pk_cobj);
00495 }
00496 static ER destroy(object_id<Id>& objid)
00497 {
00498 ER ercd = Stub::stub_del_mpf(objid.id());
00499 if (ercd == E_OK)
00500 objid.detach();
00501 return ercd;
00502 }
00503 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00504 {
00505 return Stub::stub_ref_mpf(objid.id(), pk_robj);
00506 }
00507 };
00508
00509 template <ID Id, class Stub>
00510 class object_controller<Id, obj_vmempool, Stub>
00511 {
00512 public:
00513 typedef t_cmpl creation;
00514 typedef t_rmpl reference;
00515
00516 static ER create(object_id<Id>& objid, creation* pk_cobj)
00517 {
00518 if (Id == 0)
00519 {
00520 ER_ID erid = Stub::stub_acre_mpl(pk_cobj);
00521 if (erid > 0)
00522 {
00523 objid.attach(erid);
00524 erid = 0;
00525 }
00526 return static_cast<ER>(erid);
00527 }
00528 return Stub::stub_cre_mpl(objid.id(), pk_cobj);
00529 }
00530 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00531 {
00532 if (Id == 0)
00533 {
00534 ER_ID erid = Stub::stub_acre_mpl(pk_cobj);
00535 if (erid > 0)
00536 {
00537 objid.attach(erid);
00538 erid = 0;
00539 }
00540 return static_cast<ER>(erid);
00541 }
00542 return Stub::stub_cre_mpl(objid.id(), pk_cobj);
00543 }
00544 static ER destroy(object_id<Id>& objid)
00545 {
00546 ER ercd = Stub::stub_del_mpl(objid.id());
00547 if (ercd == E_OK)
00548 objid.detach();
00549 return ercd;
00550 }
00551 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00552 {
00553 return Stub::stub_ref_mpl(objid.id(), pk_robj);
00554 }
00555 };
00556
00557 template <ID Id, class Stub>
00558 class object_controller<Id, obj_task, Stub>
00559 {
00560 public:
00561 typedef t_ctsk creation;
00562 typedef t_rtsk reference;
00563
00564 static ER create(object_id<Id>& objid, creation* pk_cobj)
00565 {
00566 if (Id == 0)
00567 {
00568 ER_ID erid = Stub::stub_acre_tsk(pk_cobj);
00569 if (erid > 0)
00570 {
00571 objid.attach(erid);
00572 erid = 0;
00573 }
00574 return static_cast<ER>(erid);
00575 }
00576 return Stub::stub_cre_tsk(objid.id(), pk_cobj);
00577 }
00578 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00579 {
00580 if (Id == 0)
00581 {
00582 ER_ID erid = Stub::stub_acre_tsk(pk_cobj);
00583 if (erid > 0)
00584 {
00585 objid.attach(erid);
00586 erid = 0;
00587 }
00588 return static_cast<ER>(erid);
00589 }
00590 return Stub::stub_cre_tsk(objid.id(), pk_cobj);
00591 }
00592 static ER destroy(object_id<Id>& objid)
00593 {
00594 ER ercd = Stub::stub_del_tsk(objid.id());
00595 if (ercd == E_OK)
00596 objid.detach();
00597 return ercd;
00598 }
00599 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00600 {
00601 return Stub::stub_ref_tsk(objid.id(), pk_robj);
00602 }
00603 };
00604
00605 template <ID Id, class Stub>
00606 class object_controller<Id, obj_cyclichandler, Stub>
00607 {
00608 public:
00609 typedef t_ccyc creation;
00610 typedef t_rcyc reference;
00611
00612 static ER create(object_id<Id>& objid, creation* pk_cobj)
00613 {
00614 if (Id == 0)
00615 {
00616 ER_ID erid = Stub::stub_acre_cyc(pk_cobj);
00617 if (erid > 0)
00618 {
00619 objid.attach(erid);
00620 erid = 0;
00621 }
00622 return static_cast<ER>(erid);
00623 }
00624 return Stub::stub_cre_cyc(objid.id(), pk_cobj);
00625 }
00626 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00627 {
00628 if (Id == 0)
00629 {
00630 ER_ID erid = Stub::stub_acre_cyc(pk_cobj);
00631 if (erid > 0)
00632 {
00633 objid.attach(erid);
00634 erid = 0;
00635 }
00636 return static_cast<ER>(erid);
00637 }
00638 return Stub::stub_cre_cyc(objid.id(), pk_cobj);
00639 }
00640 static ER destroy(object_id<Id>& objid)
00641 {
00642 ER ercd = Stub::stub_del_cyc(objid.id());
00643 if (ercd == E_OK)
00644 objid.detach();
00645 return ercd;
00646 }
00647 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00648 {
00649 return Stub::stub_ref_cyc(objid.id(), pk_robj);
00650 }
00651 };
00652
00653 template <ID Id, class Stub>
00654 class object_controller<Id, obj_alarmhandler, Stub>
00655 {
00656 public:
00657 typedef t_calm creation;
00658 typedef t_ralm reference;
00659
00660 static ER create(object_id<Id>& objid, creation* pk_cobj)
00661 {
00662 if (Id == 0)
00663 {
00664 ER_ID erid = Stub::stub_acre_alm(pk_cobj);
00665 if (erid > 0)
00666 {
00667 objid.attach(erid);
00668 erid = 0;
00669 }
00670 return static_cast<ER>(erid);
00671 }
00672 return Stub::stub_cre_alm(objid.id(), pk_cobj);
00673 }
00674 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00675 {
00676 if (Id == 0)
00677 {
00678 ER_ID erid = Stub::stub_acre_alm(pk_cobj);
00679 if (erid > 0)
00680 {
00681 objid.attach(erid);
00682 erid = 0;
00683 }
00684 return static_cast<ER>(erid);
00685 }
00686 return Stub::stub_cre_alm(objid.id(), pk_cobj);
00687 }
00688 static ER destroy(object_id<Id>& objid)
00689 {
00690 ER ercd = Stub::stub_del_alm(objid.id());
00691 if (ercd == E_OK)
00692 objid.detach();
00693 return ercd;
00694 }
00695 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00696 {
00697 return Stub::stub_ref_alm(objid.id(), pk_robj);
00698 }
00699 };
00700
00701 template <ID Id, class Stub>
00702 class object_controller<Id, obj_isr, Stub>
00703 {
00704 public:
00705 typedef t_cisr creation;
00706 typedef t_risr reference;
00707
00708 static ER create(object_id<Id>& objid, creation* pk_cobj)
00709 {
00710 if (Id == 0)
00711 {
00712 ER_ID erid = Stub::stub_acre_isr(pk_cobj);
00713 if (erid > 0)
00714 {
00715 objid.attach(erid);
00716 erid = 0;
00717 }
00718 return static_cast<ER>(erid);
00719 }
00720 return Stub::stub_cre_isr(objid.id(), pk_cobj);
00721 }
00722 static ER create(object_id<Id>& objid, const creation* pk_cobj)
00723 {
00724 if (Id == 0)
00725 {
00726 ER_ID erid = Stub::stub_acre_isr(pk_cobj);
00727 if (erid > 0)
00728 {
00729 objid.attach(erid);
00730 erid = 0;
00731 }
00732 return static_cast<ER>(erid);
00733 }
00734 return Stub::stub_cre_isr(objid.id(), pk_cobj);
00735 }
00736 static ER destroy(object_id<Id>& objid)
00737 {
00738 ER ercd = Stub::stub_del_isr(objid.id());
00739 if (ercd == E_OK)
00740 objid.detach();
00741 return ercd;
00742 }
00743 static ER refer(const object_id<Id>& objid, reference* pk_robj)
00744 {
00745 return Stub::stub_ref_isr(objid.id(), pk_robj);
00746 }
00747 };
00748
00749 }
00750
00751 #endif // ! TOPPERS_OBJECT_HPP_