LCOV - code coverage report
Current view: top level - xenolith/application - XLEvent.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 82 82 100.0 %
Date: 2024-05-12 00:16:13 Functions: 24 24 100.0 %

          Line data    Source code
       1             : /**
       2             : Copyright (c) 2020 Roman Katuntsev <sbkarr@stappler.org>
       3             : Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       4             : 
       5             : Permission is hereby granted, free of charge, to any person obtaining a copy
       6             : of this software and associated documentation files (the "Software"), to deal
       7             : in the Software without restriction, including without limitation the rights
       8             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       9             : copies of the Software, and to permit persons to whom the Software is
      10             : furnished to do so, subject to the following conditions:
      11             : 
      12             : The above copyright notice and this permission notice shall be included in
      13             : all copies or substantial portions of the Software.
      14             : 
      15             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      16             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      17             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      18             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      19             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      20             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      21             : THE SOFTWARE.
      22             : **/
      23             : 
      24             : #include "XLEvent.h"
      25             : #include "XLApplication.h"
      26             : 
      27             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      28             : 
      29        2497 : void Event::dispatch() const {
      30        2497 :         Application::getInstance()->dispatchEvent(*this);
      31        2497 : }
      32             : 
      33          90 : Ref *Event::getObject() const {
      34          90 :         return _object;
      35             : }
      36             : 
      37        2467 : const EventHeader &Event::getHeader() const {
      38        2467 :         return _header;
      39             : }
      40             : 
      41          11 : EventHeader::Category Event::getCategory() const {
      42          11 :         return _header.getCategory();
      43             : }
      44         101 : EventHeader::EventID Event::getEventID() const {
      45         101 :         return _header.getEventID();
      46             : }
      47             : 
      48          22 : bool Event::is(const EventHeader &eventHeader) const {
      49          22 :         return _header.getEventID() == eventHeader.getEventID();
      50             : }
      51             : 
      52          11 : bool Event::operator == (const EventHeader &eventHeader) const {
      53          11 :         return is(eventHeader);
      54             : }
      55             : 
      56          60 : Event::Event(const EventHeader &header, Ref *object)
      57          60 : : _header(header), _object(object) { _value.intValue = 0; }
      58             : 
      59        2437 : Event::Event(const EventHeader &header, Ref *object, EventValue val, Type type)
      60        2437 : : _header(header), _type(type), _object(object), _value(val) { }
      61             : 
      62        2249 : void Event::send(const EventHeader &header, Ref *object, int64_t value) {
      63        2249 :         EventValue val; val.intValue = value;
      64        2249 :         send(header, object, val, Type::Int);
      65        2249 : }
      66          11 : void Event::send(const EventHeader &header, Ref *object, double value) {
      67          11 :         EventValue val; val.floatValue = value;
      68          11 :         send(header, object, val, Type::Float);
      69          11 : }
      70         123 : void Event::send(const EventHeader &header, Ref *object, bool value) {
      71         123 :         EventValue val; val.boolValue = value;
      72         123 :         send(header, object, val, Type::Bool);
      73         123 : }
      74          11 : void Event::send(const EventHeader &header, Ref *object, Ref *value) {
      75          11 :         EventValue val; val.objValue = value;
      76          11 :         send(header, object, val, Type::Object);
      77          11 : }
      78          10 : void Event::send(const EventHeader &header, Ref *object, const char *value) {
      79          10 :         String str = value;
      80          10 :         send(header, object, str);
      81          10 : }
      82          36 : void Event::send(const EventHeader &header, Ref *object, const String &value) {
      83          36 :         auto app = Application::getInstance();
      84          36 :         if (app) {
      85          21 :                 app->performOnMainThread([header, object, value] () {
      86          21 :                         EventValue val; val.strValue = &value;
      87          21 :                         Event event(header, object, val, Type::String);
      88          21 :                         event.dispatch();
      89          21 :                 });
      90             :         }
      91          36 : }
      92          11 : void Event::send(const EventHeader &header, Ref *object, const StringView &value) {
      93          11 :         auto app = Application::getInstance();
      94          11 :         if (app) {
      95          11 :                 app->performOnMainThread([header, object, value = value.str<Interface>()] () {
      96          11 :                         EventValue val; val.strValue = &value;
      97          11 :                         Event event(header, object, val, Type::String);
      98          11 :                         event.dispatch();
      99          11 :                 });
     100             :         }
     101          11 : }
     102          11 : void Event::send(const EventHeader &header, Ref *object, const Value &value) {
     103          11 :         auto app = Application::getInstance();
     104          11 :         if (app) {
     105          11 :                 app->performOnMainThread([header, object, value] () {
     106          11 :                         EventValue val; val.dataValue = &value;
     107          11 :                         Event event(header, object, val, Type::Data);
     108          11 :                         event.dispatch();
     109          11 :                 });
     110             :         }
     111          11 : }
     112        2394 : void Event::send(const EventHeader &header, Ref *object, EventValue val, Type type) {
     113        2394 :         auto app = Application::getInstance();
     114        2394 :         if (app) {
     115        2394 :                 app->performOnMainThread([header, object, val, type] () {
     116        2394 :                         Event event(header, object, val, type);
     117        2394 :                         event.dispatch();
     118        2394 :                 });
     119             :         }
     120        2394 : }
     121          60 : void Event::send(const EventHeader &header, Ref *object) {
     122          60 :         auto app = Application::getInstance();
     123          60 :         if (app) {
     124          60 :                 app->performOnMainThread([header, object] () {
     125          60 :                         Event event(header, object);
     126          60 :                         event.dispatch();
     127          60 :                 });
     128             :         }
     129          60 : }
     130             : 
     131             : }

Generated by: LCOV version 1.14