-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
deb9e93
commit e772130
Showing
7 changed files
with
474 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/********************************************************* | ||
Copyright(C): | ||
FileName:SensorManager.cpp | ||
Descripton:全局传感器管理类 | ||
Author:xiaowei.han | ||
Data:2017/09/11 | ||
Others: | ||
History: | ||
Version:1.0 | ||
*********************************************************/ | ||
#include "StdAfx.h" | ||
#include "SensorManager.h" | ||
#include <boost/thread/lock_factories.hpp> | ||
#include <algorithm> | ||
#include <string> | ||
|
||
CSensorManager::CSensorManager(void) | ||
{ | ||
m_SensorInfoArray.clear(); | ||
} | ||
|
||
|
||
CSensorManager::~CSensorManager(void) | ||
{ | ||
m_SensorInfoArray.clear(); | ||
} | ||
|
||
/********************************************************* | ||
FunctionName:RegisterSensor | ||
FunctionDesc:注册传感器 | ||
InputParam: | ||
OutputParam: | ||
ResultValue: | ||
Author:xiaowei.han | ||
*********************************************************/ | ||
bool CSensorManager::RegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement) | ||
{ | ||
auto Lock = boost::make_unique_lock(m_Lock); | ||
auto Iter = std::find(m_SensorInfoArray.begin(),m_SensorInfoArray.end(),SensorElement); | ||
//如果找到 | ||
if (Iter != m_SensorInfoArray.end()) | ||
{ | ||
return false; | ||
} | ||
m_SensorInfoArray.push_back(SensorElement); | ||
return true; | ||
} | ||
|
||
/********************************************************* | ||
FunctionName:RegisterSensor | ||
FunctionDesc:注册传感器 | ||
InputParam: | ||
OutputParam: | ||
ResultValue: | ||
Author:xiaowei.han | ||
*********************************************************/ | ||
bool CSensorManager::RegisterSensor(int nSensorTypeID,int nSensorSerialID) | ||
{ | ||
using namespace std; | ||
//根据传感器类型的ID查询传感器的名称 | ||
string strSensorName; | ||
return RegisterSensor(SENSOR_TYPE_INFO_ELEMENT(strSensorName,nSensorTypeID,nSensorSerialID)); | ||
} | ||
|
||
/********************************************************* | ||
FunctionName:RegisterSensor | ||
FunctionDesc:注册传感器 | ||
InputParam: | ||
OutputParam: | ||
ResultValue: | ||
Author:xiaowei.han | ||
*********************************************************/ | ||
bool CSensorManager::UnRegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement) | ||
{ | ||
auto Lock = boost::make_unique_lock(m_Lock); | ||
auto Iter = std::find(m_SensorInfoArray.begin(),m_SensorInfoArray.end(),SensorElement); | ||
|
||
//找到对应的元素 | ||
if (Iter != m_SensorInfoArray.end()) | ||
{ | ||
m_SensorInfoArray.erase(Iter); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/********************************************************* | ||
FunctionName:RegisterSensor | ||
FunctionDesc:注册传感器 | ||
InputParam: | ||
OutputParam: | ||
ResultValue: | ||
Author:xiaowei.han | ||
*********************************************************/ | ||
bool CSensorManager::UnRegisterSensor(int nSensorTypeID,int nSensorSerialID) | ||
{ | ||
return UnRegisterSensor(SENSOR_TYPE_INFO_ELEMENT("",nSensorTypeID,nSensorSerialID)); | ||
} | ||
|
||
CSensorManager& CSensorManager::CreateInstance(void) | ||
{ | ||
return s_obj; | ||
} | ||
|
||
CSensorManager CSensorManager::s_obj; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/********************************************************* | ||
Copyright(C): | ||
FileName:SensorManager.h | ||
Descripton:全局传感器管理类 | ||
Author:xiaowei.han | ||
Data:2017/09/11 | ||
Others: | ||
History: | ||
Version:1.0 | ||
*********************************************************/ | ||
#pragma once | ||
#include <vector> | ||
#include <boost/thread/mutex.hpp> | ||
#include "Type.h" | ||
class CSensorManager | ||
{ | ||
|
||
public: | ||
static CSensorManager& CreateInstance(void); | ||
private: | ||
CSensorManager(void); | ||
virtual ~CSensorManager(void); | ||
|
||
//开始注册一个传感器 | ||
bool RegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement); | ||
//重载 | ||
bool RegisterSensor(int nSensorTypeID,int nSensorSerialID); | ||
//反注册一个传感器 | ||
bool UnRegisterSensor(const SENSOR_TYPE_INFO_ELEMENT& SensorElement); | ||
//重载 | ||
bool UnRegisterSensor(int nSensorTypeID,int nSensorSerialID); | ||
|
||
private: | ||
//传感器信息列表 | ||
std::vector<SENSOR_TYPE_INFO_ELEMENT> m_SensorInfoArray; | ||
//锁 | ||
boost::mutex m_Lock; | ||
//全局唯一实例 | ||
static CSensorManager s_obj; | ||
}; | ||
|
Oops, something went wrong.