gForceSDK
Hub.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017, OYMotion Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in
14  * the documentation and/or other materials provided with the
15  * distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
24  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28  * DAMAGE.
29  *
30  */
38 #pragma once
39 
40 #include "gfTypes.h"
41 #include <vector>
42 #include <functional>
43 
44 namespace gf
45 {
46  class HubListener;
47 
55  class Hub
56  {
57  public:
66  virtual GF_RET_CODE init(GF_UINT8 comPort = 0) = 0;
67 
72  virtual GF_RET_CODE deinit() = 0;
73 
78  virtual WorkMode getWorkMode() const = 0;
79 
85  virtual void setWorkMode(WorkMode newMode) = 0;
86 
90  virtual HubState getState() = 0;
91 
95  virtual tstring getDescString() const = 0;
96 
101  virtual GF_RET_CODE registerListener(const gfwPtr<HubListener>& listener) = 0;
102 
107  virtual GF_RET_CODE unRegisterListener(const gfwPtr<HubListener>& listener) = 0;
108 
114  virtual GF_RET_CODE startScan(GF_UINT8 rssiThreshold = 200) = 0;
115 
119  virtual GF_RET_CODE stopScan() = 0;
120 
126  virtual GF_SIZE getNumOfDevices(bool bConnectedOnly = true) const = 0;
127 
135  virtual void enumDevices(std::function<bool(SPDEVICE)>& funEnum, bool bConnectedOnly = true) = 0;
136 
140  virtual SPDEVICE findDevice(GF_UINT8 addrType, tstring address) = 0;
141 
151  virtual GF_RET_CODE run(GF_UINT32 ms, bool once = false) = 0;
152 
153  protected:
154  Hub() {}
155  virtual ~Hub() {}
156  };
157 
158 } // namespace gf
virtual GF_RET_CODE startScan(GF_UINT8 rssiThreshold=200)=0
Start gForce scan.
virtual GF_RET_CODE deinit()=0
De-initialize the Hub instance.
gfsPtr< Device > SPDEVICE
the strong pointer to Device
Definition: gfTypes.h:119
virtual GF_RET_CODE init(GF_UINT8 comPort=0)=0
Initialize the Hub instance.
virtual GF_RET_CODE stopScan()=0
Stop gForce scan.
virtual HubState getState()=0
Get hub state.
virtual void setWorkMode(WorkMode newMode)=0
Set work mode.
virtual GF_RET_CODE run(GF_UINT32 ms, bool once=false)=0
run message polling
virtual tstring getDescString() const =0
A description text of the hub.
std::string tstring
std::string type definition for ANSI/UNICODE convenience
Definition: gfTypes.h:98
HubState
Possible Hub states.
Definition: gfTypes.h:195
unsigned int GF_UINT32
type definition
Definition: gfTypes.h:73
The namespace in which all of the gForceSDK project definitions are contained.
Definition: Device.h:42
size_t GF_SIZE
type definition
Definition: gfTypes.h:78
WorkMode
Defines how callbacks are called in threads.
Definition: gfTypes.h:123
virtual WorkMode getWorkMode() const =0
Get work mode.
GF_RET_CODE
Defines possible return values of methods.
Definition: gfTypes.h:138
virtual SPDEVICE findDevice(GF_UINT8 addrType, tstring address)=0
Find a gForce device.
virtual GF_SIZE getNumOfDevices(bool bConnectedOnly=true) const =0
Get the number of all devices found.
virtual void enumDevices(std::function< bool(SPDEVICE)> &funEnum, bool bConnectedOnly=true)=0
Enumurate devices.
virtual GF_RET_CODE registerListener(const gfwPtr< HubListener > &listener)=0
Register HubListener.
virtual GF_RET_CODE unRegisterListener(const gfwPtr< HubListener > &listener)=0
Un-register HubListener.
std::weak_ptr< T > gfwPtr
The weak pointer.
Definition: gfTypes.h:110
The abstract of a gForce Hub.
Definition: Hub.h:55
The basic type definitions using in gForceSDK.
unsigned char GF_UINT8
type definition
Definition: gfTypes.h:65