~chasedouglas/frame/ubuntu-upstream-xi

« back to all changes in this revision

Viewing changes to src/v2/event.cpp

  • Committer: Chase Douglas
  • Date: 2011-12-09 01:36:45 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: chase.douglas@ubuntu.com-20111209013645-n24l4myiumblzsfu
* New upstream release.
  - Version 2 adds a new API built on top of XInput multitouch

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 *
 
3
 * utouch-frame - Touch Frame Library
 
4
 *
 
5
 * Copyright (C) 2011 Canonical Ltd.
 
6
 *
 
7
 * This program is free software: you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License as published by the
 
9
 * Free Software Foundation, either version 3 of the License, or (at your
 
10
 * option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful, but
 
13
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * General Public License for more details.
 
16
 *
 
17
 * You should have received a copy of the GNU General Public License along
 
18
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 *
 
20
 ****************************************************************************/
 
21
 
 
22
#include <assert.h>
 
23
 
 
24
#include "v2/event.h"
 
25
#include "v2/frame.h"
 
26
 
 
27
namespace utouch {
 
28
namespace frame {
 
29
 
 
30
UFEvent::UFEvent(UFEventType type, const Value* data, uint64_t time)
 
31
    : ref_count_(1) {
 
32
  const Value* value;
 
33
 
 
34
  value = new Value(type);
 
35
  InsertProperty(UFEventPropertyType, value);
 
36
 
 
37
  switch (type) {
 
38
    case UFEventTypeDeviceAdded:
 
39
    case UFEventTypeDeviceRemoved:
 
40
      InsertProperty(UFEventPropertyDevice, data);
 
41
      break;
 
42
 
 
43
    case UFEventTypeFrame:
 
44
      InsertProperty(UFEventPropertyFrame, data);
 
45
      break;
 
46
  }
 
47
 
 
48
  value = new Value(time);
 
49
  InsertProperty(UFEventPropertyTime, value);
 
50
}
 
51
 
 
52
void UFEvent::Ref() {
 
53
  ++ref_count_;
 
54
}
 
55
 
 
56
void UFEvent::Unref() {
 
57
  --ref_count_;
 
58
  if (ref_count_ == 0)
 
59
    delete this;
 
60
}
 
61
 
 
62
UFEvent::~UFEvent() {
 
63
  ::UFFrame frame;
 
64
 
 
65
  if (GetProperty(UFEventPropertyFrame, &frame) == UFStatusSuccess)
 
66
    static_cast<utouch::frame::UFFrame*>(frame)->ReleasePreviousFrame();
 
67
}
 
68
 
 
69
} // namespace frame
 
70
} // namespace utouch
 
71
 
 
72
extern "C" {
 
73
 
 
74
void frame_event_ref(UFEvent event) {
 
75
  static_cast<utouch::frame::UFEvent*>(event)->Ref();
 
76
}
 
77
 
 
78
void frame_event_unref(UFEvent event) {
 
79
  static_cast<utouch::frame::UFEvent*>(event)->Unref();
 
80
}
 
81
 
 
82
UFStatus frame_event_get_property(UFEvent event, UFEventProperty property,
 
83
                                  void *data) {
 
84
  return static_cast<const utouch::frame::UFEvent*>(event)->GetProperty(property,
 
85
                                                                  data);
 
86
}
 
87
 
 
88
UFEventType frame_event_get_type(UFEvent event) {
 
89
  UFEventType type;
 
90
  const utouch::frame::UFEvent* ufevent =
 
91
      static_cast<const utouch::frame::UFEvent*>(event);
 
92
  UFStatus status = ufevent->GetProperty(UFEventPropertyType, &type);
 
93
  assert(status == UFStatusSuccess);
 
94
  return type;
 
95
}
 
96
 
 
97
uint64_t frame_event_get_time(UFEvent event) {
 
98
  uint64_t time;
 
99
  const utouch::frame::UFEvent* ufevent =
 
100
      static_cast<const utouch::frame::UFEvent*>(event);
 
101
  UFStatus status = ufevent->GetProperty(UFEventPropertyTime, &time);
 
102
  assert(status == UFStatusSuccess);
 
103
  return time;
 
104
}
 
105
 
 
106
} // extern "C"