~ubuntu-branches/ubuntu/saucy/goldencheetah/saucy

« back to all changes in this revision

Viewing changes to src/SimpleNetworkController.h

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-08-18 07:02:45 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130818070245-zgdvb47e1k3mtgil
Tags: 3.0-3
debian/control: remove needless dependency. (Closes: #719571)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (c) 2009 Steve Gribble (gribble [at] cs.washington.edu) and
3
 
 *                    Mark Liversedge (liversedge@gmail.com)
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify it
6
 
 * under the terms of the GNU General Public License as published by the Free
7
 
 * Software Foundation; either version 2 of the License, or (at your option)
8
 
 * any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful, but WITHOUT
11
 
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13
 
 * more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License along
16
 
 * with this program; if not, write to the Free Software Foundation, Inc., 51
17
 
 * Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18
 
 */
19
 
 
20
 
 
21
 
#ifndef _GC_SimpleNetworkController_h
22
 
#define _GC_SimpleNetworkController_h 1
23
 
 
24
 
#include <QString>
25
 
#include <QDebug>
26
 
 
27
 
#include "RealtimeController.h"
28
 
#include "RealtimeData.h"
29
 
#include "SimpleNetworkClient.h"
30
 
#include "DeviceTypes.h"
31
 
#include "DeviceConfiguration.h"
32
 
 
33
 
// This class serves as our first simple cut as a realtime
34
 
// network device controller.  This class opens up a TCP connection
35
 
// to a server, and then starts pulling telemetry updates from a single
36
 
// peer via the server.
37
 
 
38
 
// This class currently uses a pull model.  As well, GC should push
39
 
// realtime data drawn from a local bike into this class, causing that
40
 
// data to be relayed to the server (and from there to the peer).
41
 
 
42
 
class SimpleNetworkController : public RealtimeController
43
 
{
44
 
 public:
45
 
 
46
 
  RealtimeWindow *parent;
47
 
 
48
 
  // hostname and port are the hostname/port of the server to which
49
 
  // this SimpleNetworkControlller should connect.
50
 
  SimpleNetworkController(RealtimeWindow *parent,
51
 
                          DeviceConfiguration *dc);
52
 
  ~SimpleNetworkController() { }
53
 
 
54
 
  // Connect to the server; blocks until connection finishes or fails.
55
 
  //
56
 
  // Returns 0 on success, non-zero on failure.
57
 
  int start();
58
 
 
59
 
  // Disconnect from the server; blocks until disconnect finishes or
60
 
  // fails.
61
 
  //
62
 
  // Returns 0 on successful disconnection, non-zero if the controller
63
 
  // wasn't disconnected to begin with.
64
 
  int stop();
65
 
 
66
 
  // If the controller is connected to the server and running, this
67
 
  // method causes the controller to "pause", i.e., to ignore updates
68
 
  // flowing from the server locally.
69
 
  //
70
 
  // Returns 0 if the pause took effect, non-zero if the pause isn't
71
 
  // meaningful (i.e., the controller isn't connected, or it's already
72
 
  // paused).
73
 
  int pause();
74
 
 
75
 
  // If the controller is connected and paused, this method causes the
76
 
  // controller to unpause and resume processing updates from the server.
77
 
  //
78
 
  // Returns 0 if the restart succeeds, non-zero otherwise.
79
 
  int restart();
80
 
 
81
 
  // XXX -- NOT SURE WHAT THIS METHOD IS FOR.  I'VE CURRENTLY STUBBED
82
 
  // IT OUT TO RETURN TRUE.
83
 
  bool discover(char *) {  return true;  }
84
 
 
85
 
  // The SimpleNetworkController is currently a pull mode controller.
86
 
  bool doesPush() {  return false; }
87
 
  bool doesPull() {  return true; }
88
 
  bool doesLoad() {  return false; }
89
 
  void setLoad(double) { return; }
90
 
 
91
 
  // When called, this method will fill in rtData with the latest
92
 
  // realtime data from the remote peer.
93
 
  //
94
 
  // XXX -- should probably have a return value so that the caller
95
 
  // can learn when the data source has unexpectedly disconnected.
96
 
  void getRealtimeData(RealtimeData &rtData);
97
 
 
98
 
  // When called, this method will push the realtime data in
99
 
  // rtData to the server.
100
 
  void pushRealtimeData(RealtimeData &rtData);
101
 
 
102
 
 private:
103
 
  SimpleNetworkClient client;
104
 
  enum {DISCONNECTED, RUNNING, PAUSED} state;
105
 
  RealtimeData data_cache;
106
 
};
107
 
 
108
 
 
109
 
#endif // _GC_SimpleNetworkController_h