DataDirector API
InjectedEventHandlerComponent.h
Go to the documentation of this file.
1 /*! \file InjectedEventHandlerComponent.h
2  \brief The InjectedEventHandlerComponent interface.
3 
4  \par Copyright Information
5 
6  Copyright (c) 2012 The DiSTI Corporation.<br>
7  11301 Corporate Blvd; Suite 100<br>
8  Orlando, Florida 32817<br>
9  USA<br>
10  <br>
11  All rights reserved.<br>
12 
13  This Software contains proprietary trade secrets of DiSTI and may not be
14 reproduced, in whole or part, in any form, or by any means of electronic,
15 mechanical, or otherwise, without the written permission of DiSTI. Said
16 permission may be derived through the purchase of applicable DiSTI product
17 licenses which detail the distribution rights of this content and any
18 Derivative Works based on this or other copyrighted DiSTI Software.
19 
20  NO WARRANTY. THE SOFTWARE IS PROVIDED "AS-IS," WITHOUT WARRANTY OF ANY KIND,
21 AND ANY USE OF THIS SOFTWARE PRODUCT IS AT YOUR OWN RISK. TO THE MAXIMUM EXTENT
22 PERMITTED BY APPLICABLE LAW, DISTI AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES
23 AND CONDITIONS, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
24 IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY AND/OR FITNESS FOR A
25 PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT, WITH REGARD TO THE SOFTWARE.
26 
27  LIMITATION OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW,
28 IN NO EVENT SHALL DISTI OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
29 INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION,
30 DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS
31 INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR
32 INABILITY TO USE THE SOFTWARE, EVEN IF DISTI HAS BEEN ADVISED OF THE POSSIBLITY
33 OF SUCH DAMAGES. DISTI'S ENTIRE LIABILITY AND YOUR EXCLUSIVE REMEDY SHALL NOT
34 EXCEED FIVE DOLLARS (US$5.00).
35 
36  The aforementioned terms and restrictions are governed by the laws of the
37 State of Florida and the United States of America.
38 
39 */
40 
41 #ifndef _EVENT_EMITTING_COMPONENT_H_
42 #define _EVENT_EMITTING_COMPONENT_H_
43 
44 #include "component_base.h"
45 
46 namespace disti
47 {
48 class InjectedObjectEvent : public ObjectEvent
49 {
50 public:
51  InjectedObjectEvent(DisplayObject* initiator,
52  const char * initiatorName,
53  const char * name,
54  const char * data = NULL) :
55  ObjectEvent(initiator, name, data)
56  {
57  _initiatorName = initiatorName;
58  }
59 
60  const char * InitiatorName()
61  {
62  return _initiatorName.c_str();
63  }
64 
65  void InitiatorName(const char * name)
66  {
67  _initiatorName = name;
68  }
69 
70  bool Matches(const char * initiatorName, const char * eventName)
71  {
72  if (strcmp(this->InitiatorName(), initiatorName) == 0 &&
73  strcmp(this->EventName(), eventName) == 0 )
74  {
75  return true;
76  }
77 
78  return false;
79  }
80 
81 private:
82  std::string _initiatorName;
83 };
84 
85 class InjectedEventHandlerComponent : public ComponentBase
86 {
87 public:
88  /** Default constructor
89  */
90  InjectedEventHandlerComponent(int generateInstance = FALSE) : ComponentBase(generateInstance)
91  {
92  _eventAtt = new char[1];
93  _eventAtt[0] = '\0';
94  }
95 
96  /** Default destructor
97  */
99  {
100  if (_eventAtt != NULL) delete [] _eventAtt;
101  }
102 
103  /** override for the SetAvailableAttributes function that includes the behavior of
104  * of ComponentBase plus adds routing for the InjectedEventHandler attribute
105  */
106  virtual void SetAvailableAttributes(unsigned int availableAttributes)
107  {
108  static AttributeName MetaEventAttribute("InjectedEventHandler");
109  // For now we only allow one call
110  if(_attributesAdded)
111  { return; }
112 
113  ComponentBase::SetAvailableAttributes(availableAttributes);
114 
115  typedef void (InjectedEventHandlerComponent::*void_method_void)(void);
116 
117  CallbackMethodCallerTemplate<InjectedEventHandlerComponent> updateEventAttrCb(
118  (void_method_void)&disti::InjectedEventHandlerComponent::UpdateEventAttr
119  , this);
120 
121  Attributes().Add( new DistiAttributeString(&updateEventAttrCb,MetaEventAttribute, &_eventAtt));
122  }
123 
124  /* This function gets called whenever the InjectedEventHandler is modified. It takes care
125  * of converting the incoming data into an InjectedObjectEvent instance
126  */
127  void UpdateEventAttr()
128  {
129 
130  std::string eventAtt(_eventAtt);
131 
132  std::string::size_type split = eventAtt.find_first_of("|", 0);
133 
134  // get the originator name
135  std::string originator = eventAtt.substr(0, ((split >= eventAtt.size())?eventAtt.size()-1:split) );
136 
137  // get the rest of the string
138  std::string tempStr = (( (split+1) >= eventAtt.size() || split >= eventAtt.size() )?"":eventAtt.substr(split+1));
139  split = tempStr.find_first_of("|", 0);
140 
141  // now split the name and data parts
142  std::string name = tempStr.substr(0, ((split >= tempStr.size())?tempStr.size()-1:split) );
143  std::string data = (( (split+1) >= tempStr.size() || split >= tempStr.size() )?"":tempStr.substr(split+1));
144 
145  printf("we got an updated eventAttr value\n originator: [%s]\n name: [%s]\n data: [%s]\n\n", originator.c_str(), name.c_str(), data.c_str());
146 
147  InjectedObjectEvent temp(this, originator.c_str(), name.c_str(), data.c_str());
148 
149  HandleInjectedEvent(&temp);
150  }
151 
152  /** This function gets called when a new InjectedObjectEvent is ready for consumption and it must
153  * be implemented by the child class
154  */
155  virtual void HandleInjectedEvent(InjectedObjectEvent * ev) = 0;
156 
157 
158 private:
159  char * _eventAtt;
160 };
161 }
162 
163 #endif // _EVENT_EMITTING_COMPONENT_H_
Definition: InjectedEventHandlerComponent.h:85
virtual void HandleInjectedEvent(InjectedObjectEvent *ev)=0
Definition: InjectedEventHandlerComponent.h:48
virtual void SetAvailableAttributes(unsigned int availableAttributes)
Definition: InjectedEventHandlerComponent.h:106
~InjectedEventHandlerComponent()
Definition: InjectedEventHandlerComponent.h:98
Definition: AttributeChangedEmitter.h:46
InjectedEventHandlerComponent(int generateInstance=FALSE)
Definition: InjectedEventHandlerComponent.h:90