webappmanager
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NewContentIndicatorEventFactory.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2009-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 NEWCONTENTINDICATOREVENTFACTORY_H
23 #define NEWCONTENTINDICATOREVENTFACTORY_H
24 
25 #include "Common.h"
26 
27 #include <NewContentIndicatorEvent.h>
28 
29 #include <glib.h>
30 #include <time.h>
31 
32 #include <string>
33 
35 {
36 public:
37 
38  static NewContentIndicatorEvent* createAddEvent(const std::string& _appId) {
39 
40  if (_appId.empty())
41  return 0;
42 
43  NewContentIndicatorEvent* e = new NewContentIndicatorEvent;
44  e->eventType = NewContentIndicatorEvent::Add;
45  e->appId = _appId;
46 
47  // Create a "unique" ID for the msg
48  struct timespec time;
49  clock_gettime(CLOCK_MONOTONIC, &time);
50  double t = time.tv_sec * 1000.0 + time.tv_nsec / 1000000.0;
51 
52  char* id = g_strdup_printf("%lf", t);
53  e->requestId = id;
54  g_free(id);
55 
56  return e;
57  }
58 
59  static NewContentIndicatorEvent* createRemoveEvent(const std::string& _appId, const std::string& _requestId) {
60 
61  if (_appId.empty() || _requestId.empty())
62  return 0;
63 
64  NewContentIndicatorEvent* e = new NewContentIndicatorEvent;
65  e->eventType = NewContentIndicatorEvent::Remove;
66  e->appId = _appId;
67  e->requestId = _requestId;
68 
69  return e;
70  }
71 
72  static NewContentIndicatorEvent* createClearEvent(const std::string& _appId) {
73 
74  if (_appId.empty())
75  return 0;
76 
77  NewContentIndicatorEvent* e = new NewContentIndicatorEvent;
78  e->eventType = NewContentIndicatorEvent::Clear;
79  e->appId = _appId;
80 
81  return e;
82  }
83 };
84 
85 #endif /* NEWCONTENTINDICATOREVENTFACTORY_H */