2
* Copyright (c) 2009 Steve Gribble (gribble [at] cs.washington.edu) and
3
* Mark Liversedge (liversedge@gmail.com)
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)
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
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
21
#ifndef _GC_SimpleNetworkController_h
22
#define _GC_SimpleNetworkController_h 1
27
#include "RealtimeController.h"
28
#include "RealtimeData.h"
29
#include "SimpleNetworkClient.h"
30
#include "DeviceTypes.h"
31
#include "DeviceConfiguration.h"
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.
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).
42
class SimpleNetworkController : public RealtimeController
46
RealtimeWindow *parent;
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() { }
54
// Connect to the server; blocks until connection finishes or fails.
56
// Returns 0 on success, non-zero on failure.
59
// Disconnect from the server; blocks until disconnect finishes or
62
// Returns 0 on successful disconnection, non-zero if the controller
63
// wasn't disconnected to begin with.
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.
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
75
// If the controller is connected and paused, this method causes the
76
// controller to unpause and resume processing updates from the server.
78
// Returns 0 if the restart succeeds, non-zero otherwise.
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; }
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; }
91
// When called, this method will fill in rtData with the latest
92
// realtime data from the remote peer.
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);
98
// When called, this method will push the realtime data in
99
// rtData to the server.
100
void pushRealtimeData(RealtimeData &rtData);
103
SimpleNetworkClient client;
104
enum {DISCONNECTED, RUNNING, PAUSED} state;
105
RealtimeData data_cache;
109
#endif // _GC_SimpleNetworkController_h