trikRuntime
mailbox.h
Go to the documentation of this file.
1 /* Copyright 2014 - 2015 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 <QtCore/QThread>
19 #include <QtXml/QDomElement>
20 
21 #include "mailboxInterface.h"
22 
23 namespace trikKernel {
24 class Configurer;
25 }
26 
27 namespace trikNetwork {
28 
29 class MailboxServer;
30 
32 class Mailbox : public MailboxInterface
33 {
34  Q_OBJECT
35 
36 public:
39  Mailbox(int port);
40 
43  Mailbox(const trikKernel::Configurer &configurer);
44 
45  ~Mailbox() override;
46 
47  bool isConnected() const override;
48 
49  void setHullNumber(int myHullNumber) override;
50 
51  QHostAddress serverIp() const override;
52 
53  QHostAddress myIp() const override;
54 
55  void clearQueue() override;
56 
57  bool isEnabled() override;
58 
59  void stopWaiting() override;
60 
61 public slots:
62  void connect(const QString &ip, int port) override;
63 
64  void connect(const QString &ip) override;
65 
66  void send(int hullNumber, const QString &message) override;
67 
68  void send(const QString &message) override;
69 
70  bool hasMessages() override;
71 
72  QString receive(bool wait = true) override;
73 
74  int myHullNumber() const override;
75 
76  void renewIp() override;
77 
78 signals:
80  void stopWaitingSignal();
81 
82 private slots:
83  void updateConnectionStatus();
84 
85 private:
87  void init(int port);
88 
90  QScopedPointer<MailboxServer> mWorker;
91 
93  QThread mWorkerThread;
94 };
95 
96 }
Definition: analogSensor.h:23
Generic configuration helper, parses configuration XML files and presents configuration as a set of a...
Definition: configurer.h:28
Implementation of mailboxes system.
Definition: mailbox.h:32
static const int port
Definition: trikCommunicatorTest.cpp:24
Definition: trikCommunicator.h:31
Allows communication between robots.
Definition: mailboxInterface.h:31