LunaSysMgr
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
BannerMessageEventFactory.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef BANNERMESSAGEEVENTFACTORY_H
23 #define BANNERMESSAGEEVENTFACTORY_H
24 
25 #include "Common.h"
26 
27 #include <BannerMessageEvent.h>
28 #include <ActiveCallBannerEvent.h>
29 
30 #include <time.h>
31 #include <glib.h>
32 
33 #include <string>
34 #include <stdint.h>
35 
37 {
38 public:
39 
40  static BannerMessageEvent* createAddMessageEvent(const std::string& _appId,
41  const std::string& _msg,
42  const std::string& _launchParams,
43  const std::string& _icon,
44  const std::string& _soundClass,
45  const std::string& _soundFile,
46  int _duration,
47  bool _doNotSuppress) {
48  if (_appId.empty() || _msg.empty() || _launchParams.empty())
49  return 0;
50 
51  BannerMessageEvent* e = new BannerMessageEvent;
52  e->msgType = BannerMessageEvent::Add;
53  e->appId = _appId;
54  e->msg = _msg;
55  e->launchParams = _launchParams;
56  e->icon = _icon;
57  e->soundClass = _soundClass;
58  e->soundFile = _soundFile;
59  e->duration = _duration;
60  e->doNotSuppress = _doNotSuppress;
61 
62  // Create a "unique" ID for the msg
63  struct timespec time;
64  clock_gettime(CLOCK_MONOTONIC, &time);
65  double t = time.tv_sec * 1000.0 + time.tv_nsec / 1000000.0;
66 
67  gchar* id = g_strdup_printf("%lf", t);
68  e->msgId = id;
69  g_free(id);
70 
71  return e;
72  }
73 
74  static BannerMessageEvent* createRemoveMessageEvent(const std::string& _appId,
75  const std::string& _msgId) {
76 
77  if (_appId.empty() || _msgId.empty())
78  return 0;
79 
80  BannerMessageEvent* e = new BannerMessageEvent;
81  e->msgType = BannerMessageEvent::Remove;
82  e->appId = _appId;
83  e->msgId = _msgId;
84 
85  return e;
86  };
87 
88  static BannerMessageEvent* createClearMessagesEvent(const std::string& _appId) {
89 
90  if (_appId.empty())
91  return 0;
92 
93  BannerMessageEvent* e = new BannerMessageEvent;
94  e->msgType = BannerMessageEvent::Clear;
95  e->appId = _appId;
96 
97  return e;
98  };
99 
100  static BannerMessageEvent* createPlaySoundEvent(const std::string& _appId,
101  const std::string& _soundClass,
102  const std::string& _soundFile,
103  int _duration, bool _wakeupScreen=false) {
104  if (_appId.empty() || _soundClass.empty())
105  return 0;
106 
107  BannerMessageEvent* e = new BannerMessageEvent;
108  e->msgType = BannerMessageEvent::PlaySound;
109  e->appId = _appId;
110  e->soundClass = _soundClass;
111  e->soundFile = _soundFile;
112  e->duration = _duration;
113  e->wakeupScreen = _wakeupScreen;
114 
115  return e;
116  }
117 };
118 
120 {
121 public:
122 
123  static ActiveCallBannerEvent* createAddEvent(const std::string& _msg,
124  const std::string& _icon,
125  uint32_t _time) {
126  if (_msg.empty() || BannerActive)
127  return 0;
128 
129  ActiveCallBannerEvent* e = new ActiveCallBannerEvent;
130  e->type = ActiveCallBannerEvent::Add;
131  e->msg = _msg;
132  e->icon = _icon;
133  e->time = _time;
134 
135  BannerActive = true;
136 
137  return e;
138  }
139 
140  static ActiveCallBannerEvent* createRemoveEvent() {
141 
142  ActiveCallBannerEvent* e = new ActiveCallBannerEvent;
144 
145  BannerActive = false;
146 
147  return e;
148  };
149 
150  static ActiveCallBannerEvent* createUpdateEvent(const std::string& _msg,
151  const std::string& _icon,
152  uint32_t _time) {
153 
154  if (_msg.empty())
155  return 0;
156 
157  ActiveCallBannerEvent* e = new ActiveCallBannerEvent;
158  e->type = ActiveCallBannerEvent::Update;
159  e->msg = _msg;
160  e->icon = _icon;
161  e->time = _time;
162 
163  return e;
164  };
165 
166 private:
167 
168  // only allow a single active call banner to exist at any time
169  static bool BannerActive;
170 };
171 
172 #endif /* BANNERMESSAGEEVENTFACTORY_H */