126 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			126 lines
		
	
	
		
			3.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
/*
 | 
						|
 * Copyright (c) 2023 Fancy Code.
 | 
						|
 * Licensed under the Apache License, Version 2.0 (the "License");
 | 
						|
 * you may not use this file except in compliance with the License.
 | 
						|
 * You may obtain a copy of the License at
 | 
						|
 *
 | 
						|
 *     http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
 *
 | 
						|
 * Unless required by applicable law or agreed to in writing, software
 | 
						|
 * distributed under the License is distributed on an "AS IS" BASIS,
 | 
						|
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 | 
						|
 * See the License for the specific language governing permissions and
 | 
						|
 * limitations under the License.
 | 
						|
 */
 | 
						|
#ifndef I_HAL_CPP_H
 | 
						|
#define I_HAL_CPP_H
 | 
						|
#include "StatusCode.h"
 | 
						|
#include <iostream>
 | 
						|
#include <map>
 | 
						|
#include <memory>
 | 
						|
#include <vector>
 | 
						|
using VirtualLedState = unsigned char;
 | 
						|
using VirtualKeyEvent = unsigned char;
 | 
						|
constexpr int INVALID_PERIOD = -1;
 | 
						|
constexpr int PERIPHERAL_CHECK_PERIOD_MS = 100;
 | 
						|
constexpr int IMEI_LEN = 15;
 | 
						|
enum class CameraType
 | 
						|
{
 | 
						|
    MAIN_CAMERA = 0,
 | 
						|
    END
 | 
						|
};
 | 
						|
enum class SdCardHalStatus
 | 
						|
{
 | 
						|
    MOUNTED = 0,
 | 
						|
    UNMOUNTED,
 | 
						|
    INSERTED,
 | 
						|
    PULL_OUT_DEVICE_NOT_EXIST,
 | 
						|
    PULL_OUT_OPEN_FAILED,
 | 
						|
    PULL_OUT_NOT_BLOCK_DEVICE,
 | 
						|
    ERROR,
 | 
						|
    END
 | 
						|
};
 | 
						|
typedef struct camera_report_event
 | 
						|
{
 | 
						|
    camera_report_event(const std::string &fileName, const CameraType &cameraType);
 | 
						|
    const std::string mFileName;
 | 
						|
    const CameraType mCameraType;
 | 
						|
} CameraReportEvent;
 | 
						|
void CreateHalCppModule(void);
 | 
						|
void DestroyHalCppModule(void);
 | 
						|
class VKeyHalMonitor
 | 
						|
{
 | 
						|
public:
 | 
						|
    VKeyHalMonitor() = default;
 | 
						|
    virtual ~VKeyHalMonitor() = default;
 | 
						|
    virtual void KeyEventHappened(const std::string &keyName, const VirtualKeyEvent &event, const unsigned int &timeMs);
 | 
						|
};
 | 
						|
class VKeyHal
 | 
						|
{
 | 
						|
public:
 | 
						|
    VKeyHal() = default;
 | 
						|
    virtual ~VKeyHal() = default;
 | 
						|
    virtual void CheckKeyStatus(void);
 | 
						|
    virtual void GetHoldPressingTimeMs(long int &holdTimeMs, VirtualKeyEvent &event);
 | 
						|
    virtual void SetKeyMonitor(std::shared_ptr<VKeyHalMonitor> &monitor);
 | 
						|
};
 | 
						|
class VLedHal
 | 
						|
{
 | 
						|
public:
 | 
						|
    VLedHal() = default;
 | 
						|
    virtual ~VLedHal() = default;
 | 
						|
};
 | 
						|
class VWifiHal
 | 
						|
{
 | 
						|
public:
 | 
						|
    VWifiHal() = default;
 | 
						|
    virtual ~VWifiHal() = default;
 | 
						|
    virtual StatusCode OpenApMode(void);
 | 
						|
    virtual StatusCode CloseApMode(void);
 | 
						|
};
 | 
						|
class VCameraHalMonitor
 | 
						|
{
 | 
						|
public:
 | 
						|
    VCameraHalMonitor() = default;
 | 
						|
    virtual ~VCameraHalMonitor() = default;
 | 
						|
    virtual void ReportEvent(const CameraReportEvent &event);
 | 
						|
};
 | 
						|
class VCameraHal
 | 
						|
{
 | 
						|
public:
 | 
						|
    VCameraHal() = default;
 | 
						|
    virtual ~VCameraHal() = default;
 | 
						|
    virtual void SetCameraMonitor(std::shared_ptr<VCameraHalMonitor> &monitor);
 | 
						|
};
 | 
						|
class VSdCardHalMonitor
 | 
						|
{
 | 
						|
public:
 | 
						|
    VSdCardHalMonitor() = default;
 | 
						|
    virtual ~VSdCardHalMonitor() = default;
 | 
						|
    virtual void ReportEvent(const SdCardHalStatus &status);
 | 
						|
};
 | 
						|
class VSdCardHal
 | 
						|
{
 | 
						|
public:
 | 
						|
    VSdCardHal() = default;
 | 
						|
    virtual ~VSdCardHal() = default;
 | 
						|
    virtual void SetSdCardMonitor(std::shared_ptr<VSdCardHalMonitor> &monitor);
 | 
						|
    virtual SdCardHalStatus GetSdCardStatus(void);
 | 
						|
    virtual StatusCode GetCapacity(unsigned long long &totalSizeMB, unsigned long long &freeSizeMB, unsigned long long &usedSizeMB);
 | 
						|
};
 | 
						|
class IHalCpp
 | 
						|
{
 | 
						|
public:
 | 
						|
    IHalCpp() = default;
 | 
						|
    virtual ~IHalCpp() = default;
 | 
						|
    static std::shared_ptr<IHalCpp> &GetInstance(std::shared_ptr<IHalCpp> *impl = nullptr);
 | 
						|
    virtual StatusCode Init(void);
 | 
						|
    virtual StatusCode UnInit(void);
 | 
						|
    virtual StatusCode GetAllLeds(std::map<std::string, std::shared_ptr<VLedHal>> &allLeds);
 | 
						|
    virtual StatusCode GetAllKeys(std::map<std::string, std::shared_ptr<VKeyHal>> &allKeys);
 | 
						|
    virtual StatusCode GetWifiHal(std::shared_ptr<VWifiHal> &wifi);
 | 
						|
    virtual StatusCode GetCameraHal(std::map<CameraType, std::shared_ptr<VCameraHal>> &allCameras);
 | 
						|
    virtual StatusCode GetSdCardHal(std::shared_ptr<VSdCardHal> &sdCard);
 | 
						|
};
 | 
						|
#endif
 |