HarmattanSyncApplications
USBConnection.h
1/*
2* This file is part of buteo-sync-plugins package
3*
4* Copyright (C) 2013 Jolla Ltd. and/or its subsidiary(-ies).
5*
6* Author: Sateesh Kavuri <sateesh.kavuri@gmail.com>
7*
8* This library is free software; you can redistribute it and/or
9* modify it under the terms of the GNU Lesser General Public License
10* version 2.1 as published by the Free Software Foundation.
11*
12* This library 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* Lesser General Public License for more details.
16*
17* You should have received a copy of the GNU Lesser General Public
18* License along with this library; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20* 02110-1301 USA
21*/
22#ifndef USBCONNECTION_H
23#define USBCONNECTION_H
24
25#include <QObject>
26#include <QMutex>
27
28#ifdef GLIB_FD_WATCH
29#include <glib.h>
30#else
31#include <QSocketNotifier>
32#endif
33
34#include <buteosyncml5/OBEXConnection.h>
35
40class USBConnection : public QObject, public DataSync::OBEXConnection
41{
42 Q_OBJECT
43
44public:
45
47
48 virtual ~USBConnection ();
49
53 virtual int connect ();
54
58 virtual bool isConnected () const;
59
63 virtual void disconnect ();
64
65 void handleSyncFinished (bool isSyncInError);
66
67signals:
68
69 void usbConnected (int fd);
70
71#ifndef GLIB_FD_WATCH
72protected slots:
73
74 void handleUSBActivated (int fd);
75
76 void handleUSBError (int fd);
77#endif
78
79private:
80 // Functions
81
82 int openUSBDevice ();
83
84 void closeUSBDevice ();
85
86 void addFdListener ();
87
88 void removeFdListener ();
89
90 void signalNewSession ();
91
92#ifdef GLIB_FD_WATCH
93 void setFdWatchEventSource (guint = 0);
94
95 void setIdleEventSource (guint = 0);
96
97 guint fdWatchEventSource ();
98
99 guint idleEventSource ();
100
101 static gboolean handleIncomingUSBEvent (GIOChannel* ioChannel,
102 GIOCondition condition,
103 gpointer user_data);
104
105 void removeEventSource ();
106
107 static gboolean reopenUSB (gpointer data);
108
109#endif
110private:
111
112 int mFd;
113
114 QMutex mMutex;
115
116 bool mDisconnected;
117
118 bool mFdWatching;
119
120#ifdef GLIB_FD_WATCH
121 GIOChannel *mIOChannel;
122
123 guint mIdleEventSource;
124
125 guint mFdWatchEventSource;
126#else
127 QSocketNotifier *mReadNotifier;
128
129 QSocketNotifier *mWriteNotifier;
130
131 QSocketNotifier *mExceptionNotifier;
132#endif
133};
134
135#endif // USBCONNECTION_H
Class for creating connection to a PC that acts as a USB host for synchronization of data using buteo...
Definition USBConnection.h:41
virtual bool isConnected() const
virtual void disconnect()
virtual int connect()