embedded-framework/test/utils/LinuxApiMock/src/LinuxTestImpl.h

49 lines
1.5 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 LINUX_TEST_IMPL_H
#define LINUX_TEST_IMPL_H
#include "HandleManager.h"
#include "LinuxApiMock.h"
#include "WrapApi.h"
#include <mutex>
#include <thread>
/**
* @brief The simulated interface will be locked by default to ensure that the return value of the interface can be
* correctly obtained by the application in the default state. This is not very reasonable and should be optimized.
* This is the blocking time after locking, during which it is necessary to ensure that the application can obtain a
* global return value.
*/
constexpr int API_LOCK_TIME_MS = 5;
class LinuxTestImpl : public HandleManager
{
public:
LinuxTestImpl() = default;
virtual ~LinuxTestImpl() = default;
void Init() override;
void UnInit() override;
void ApiLock(void);
void ApiUnlock(void);
private:
void ApiUnlockThread(void);
public:
static void ApiInit(std::shared_ptr<LinuxTest> &mock);
private:
std::mutex mApiMutex;
std::thread mApiThread;
};
#endif