trikRuntime
trikEventFile.h
Go to the documentation of this file.
1 /* Copyright 2015 Yurii Litvinov and CyberTech Labs Ltd.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License. */
14 
15 #pragma once
16 
17 #include <QtCore/QScopedPointer>
18 #include <QEventLoop>
19 #include <QSocketNotifier>
20 
21 #include "eventFileInterface.h"
22 
23 
24 namespace trikHal {
25 namespace trik {
26 
29 {
30  Q_OBJECT
31 
32 public:
36  TrikEventFile(const QString &fileName, QThread &thread);
37  ~TrikEventFile() override {}
38 
39  bool open() override;
40  bool close() override;
41  void cancelWaiting() override;
42  QString fileName() const override;
43  bool isOpened() const override;
44 
45 private slots:
47  void tryOpenEventFile();
48 
50  void readFile();
51 
52 private:
54  int mEventFileDescriptor = -1;
55 
57  const QString mFileName;
58 
60  QThread &mThread;
61 
64  QScopedPointer<QEventLoop> mInitWaitingLoop;
65 
67  QScopedPointer<QSocketNotifier> mSocketNotifier;
68 };
69 
70 }
71 }
Real implementation of event file.
Definition: trikEventFile.h:28
Event file abstraction. Can be opened or closed, when opened can emit signal containing event data...
Definition: eventFileInterface.h:27
bool open() override
Opens event file and starts listening for events.
Definition: trikEventFile.cpp:39
bool isOpened() const override
Returns true if a file is opened.
Definition: trikEventFile.cpp:133
TrikEventFile(const QString &fileName, QThread &thread)
Constructor.
Definition: trikEventFile.cpp:32
QString fileName() const override
Returns name of an event file.
Definition: trikEventFile.cpp:107
void cancelWaiting() override
Abort all pending synchronous event loops.
Definition: trikEventFile.cpp:102
~TrikEventFile() override
Definition: trikEventFile.h:37
bool close() override
Closes event file and stops listening for events.
Definition: trikEventFile.cpp:82
Definition: brickFactory.h:21