Add:MediaManager module.
This commit is contained in:
		
							parent
							
								
									818aea1417
								
							
						
					
					
						commit
						8a66f07266
					
				| 
						 | 
				
			
			@ -647,7 +647,7 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
 | 
			
		|||
| 命令字 | CPU | MCU | 数据段 | 协议解析 | 备注 |
 | 
			
		||||
|----|----|----|----|----|----|
 | 
			
		||||
| 0x8101 | ask | - | - | 获取启动模式 | - |
 | 
			
		||||
| 0x0101 | - | reply | Data[0]:启动模式<br>0x01:PIR启动<br>0x02:TEST启动<br>0x03:连拍启动<br>0x04:PIR延时启动<br>0x05:定时(间隔一定时间)启动 | 回复启动模式 | - |
 | 
			
		||||
| 0x0101 | - | reply | Data[0]:启动模式<br>0x01:PIR启动<br>0x02:TEST启动<br>0x03:连拍启动<br>0x04:PIR延时启动<br>0x05:定时(间隔一定时间)启动<br>0x06:关机<br>0x07:低电关机 | 回复启动模式 | - |
 | 
			
		||||
| 0x8102 | ask | - | - | 断电关机 | - |
 | 
			
		||||
| 0x8103 | ask | - | - | 喂狗 | - |
 | 
			
		||||
| 0x8104 | ask | - | Data[0]:Hour<br>0-23<br>Data[1]:Min<br>0-59<br>Data[2]:Sec<br>0-59 | 开启狗/设置喂狗周期 | - |
 | 
			
		||||
| 
						 | 
				
			
			@ -668,7 +668,7 @@ unsigned short calculate_check_sum(const unsigned char* pData, unsigned short le
 | 
			
		|||
| 0x010B | - | reply | Data[0]:结果<br>0-100 | 获取光敏值回复 | - |
 | 
			
		||||
| ====== | === | ====== | ============================ | ==================== | ======= |
 | 
			
		||||
| 0xC101 | reply | - | Data[0]:结果<br>0x01:成功<br>0x02:失败 | 发送启动模式回复 | - |
 | 
			
		||||
| 0x4101 | - | ask | Data[0]:启动模式<br>0x01:PIR启动<br>0x02:TEST启动<br>0x03:连拍启动<br>0x04:PIR延时启动<br>0x05:定时(间隔一定时间)启动 | 发送启动模式 | - |
 | 
			
		||||
| 0x4101 | - | ask | Data[0]:启动模式<br>0x01:PIR启动<br>0x02:TEST启动<br>0x03:连拍启动<br>0x04:PIR延时启动<br>0x05:定时(间隔一定时间)启动<br>0x06:关机<br>0x07:低电关机 | 发送启动模式 | - |
 | 
			
		||||
 | 
			
		||||
##### 1.4.3.2.6. IPC配置库
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2,4 +2,5 @@ add_subdirectory(StateMachine)
 | 
			
		|||
add_subdirectory(IpcConfig)
 | 
			
		||||
add_subdirectory(DeviceManager)
 | 
			
		||||
add_subdirectory(McuManager)
 | 
			
		||||
add_subdirectory(McuAskBase)
 | 
			
		||||
add_subdirectory(McuAskBase)
 | 
			
		||||
add_subdirectory(MediaManager)
 | 
			
		||||
| 
						 | 
				
			
			@ -15,9 +15,6 @@ include_directories(
 | 
			
		|||
#do not rely on any other library
 | 
			
		||||
#link_directories(
 | 
			
		||||
#)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
if (DEFINED MCU_UART_DEVICE)
 | 
			
		||||
    add_definitions(-DMCU_UART_DEVICE=\"${MCU_UART_DEVICE}\")
 | 
			
		||||
else()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -36,7 +36,13 @@ std::shared_ptr<McuManagerMakePtr> &McuManagerMakePtr::GetInstance(std::shared_p
 | 
			
		|||
{
 | 
			
		||||
    static auto instance = std::make_shared<McuManagerMakePtr>();
 | 
			
		||||
    if (impl) {
 | 
			
		||||
        instance = *impl;
 | 
			
		||||
        if (instance.use_count() == 1) {
 | 
			
		||||
            LogInfo("Instance changed succeed.\n");
 | 
			
		||||
            instance = *impl;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            LogError("Can't changing the instance becase of using by some one.\n");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return instance;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -12,8 +12,8 @@
 | 
			
		|||
 * See the License for the specific language governing permissions and
 | 
			
		||||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef MCUMANAGER_MAKE_PTR_H
 | 
			
		||||
#define MCUMANAGER_MAKE_PTR_H
 | 
			
		||||
#ifndef MCU_MANAGER_MAKE_PTR_H
 | 
			
		||||
#define MCU_MANAGER_MAKE_PTR_H
 | 
			
		||||
#include "IMcuManager.h"
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#include <memory>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,37 +0,0 @@
 | 
			
		|||
# 1. 媒体适配
 | 
			
		||||
 | 
			
		||||
   基于IPC项目芯片大部分都支持双核(低功耗),媒体接口对接需要考虑Linux和RTOS双系统的兼容支持。
 | 
			
		||||
 | 
			
		||||
## 1.1. 软件设计
 | 
			
		||||
 | 
			
		||||
### 1.1.1. 媒体适配模块UML类图
 | 
			
		||||
```mermaid
 | 
			
		||||
classDiagram
 | 
			
		||||
class IMediaManager{
 | 
			
		||||
<<媒体管理模块抽象接口>>
 | 
			
		||||
+初始化()
 | 
			
		||||
+解初始化()
 | 
			
		||||
+音频编码()
 | 
			
		||||
+音频解码()
 | 
			
		||||
+视频编码()
 | 
			
		||||
+视频解码()
 | 
			
		||||
+抓怕()
 | 
			
		||||
+录像()
 | 
			
		||||
+录影()
 | 
			
		||||
}
 | 
			
		||||
class MediaManager{
 | 
			
		||||
<<媒体管理模块实例>>
 | 
			
		||||
}
 | 
			
		||||
class LightSensor{
 | 
			
		||||
<<光传感器类型枚举>>
 | 
			
		||||
SENSOR_MAIN = 0,
 | 
			
		||||
SENSOR_MINOR,
 | 
			
		||||
END
 | 
			
		||||
}
 | 
			
		||||
class AudioHandle{
 | 
			
		||||
<<音频处理>>
 | 
			
		||||
}
 | 
			
		||||
class VideoHandle{
 | 
			
		||||
<<视频处理>>
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
							
								
								
									
										66
									
								
								middleware/MediaManager/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								middleware/MediaManager/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,66 @@
 | 
			
		|||
 | 
			
		||||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
 | 
			
		||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
 | 
			
		||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
 | 
			
		||||
 | 
			
		||||
include_directories(
 | 
			
		||||
    ./src
 | 
			
		||||
    ./include
 | 
			
		||||
    ${MIDDLEWARE_SOURCE_PATH}/McuAskBase/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/StatusCode/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/Log/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/McuProtocol/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/UartDevice/include
 | 
			
		||||
)
 | 
			
		||||
#do not rely on any other library
 | 
			
		||||
#link_directories(
 | 
			
		||||
#)
 | 
			
		||||
if (DEFINED MCU_UART_DEVICE)
 | 
			
		||||
    add_definitions(-DMCU_UART_DEVICE=\"${MCU_UART_DEVICE}\")
 | 
			
		||||
else()
 | 
			
		||||
    message(FATAL_ERROR "You set define MCU_UART_DEVICE in toolchan .cmake file to tell what uart device to contrl.")
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
aux_source_directory(./src SRC_FILES)
 | 
			
		||||
 | 
			
		||||
set(TARGET_NAME MediaManager)
 | 
			
		||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
 | 
			
		||||
 | 
			
		||||
target_link_libraries(${TARGET_NAME} StatusCode Log)
 | 
			
		||||
 | 
			
		||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
 | 
			
		||||
add_custom_target(
 | 
			
		||||
    MediaManager_code_check
 | 
			
		||||
    COMMAND ${CLANG_TIDY_EXE}
 | 
			
		||||
    -checks='${CLANG_TIDY_CHECKS}'
 | 
			
		||||
    --header-filter=.*
 | 
			
		||||
    --system-headers=false
 | 
			
		||||
    ${SRC_FILES}
 | 
			
		||||
    ${CLANG_TIDY_CONFIG}
 | 
			
		||||
    -p ${PLATFORM_PATH}/cmake-shell
 | 
			
		||||
    WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/MediaManager
 | 
			
		||||
)
 | 
			
		||||
add_custom_command(
 | 
			
		||||
    TARGET ${TARGET_NAME}
 | 
			
		||||
    PRE_BUILD
 | 
			
		||||
    COMMAND make MediaManager_code_check
 | 
			
		||||
    WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
 | 
			
		||||
)
 | 
			
		||||
file(GLOB_RECURSE HEADER_FILES *.h)
 | 
			
		||||
add_custom_target(
 | 
			
		||||
    MediaManager_code_format
 | 
			
		||||
    COMMAND ${CLANG_FORMAT_EXE}
 | 
			
		||||
    -style=file
 | 
			
		||||
    -i ${SRC_FILES}  ${HEADER_FILES}
 | 
			
		||||
    WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/MediaManager
 | 
			
		||||
)
 | 
			
		||||
add_custom_command(
 | 
			
		||||
    TARGET ${TARGET_NAME}
 | 
			
		||||
    PRE_BUILD
 | 
			
		||||
    COMMAND make MediaManager_code_check
 | 
			
		||||
    COMMAND make MediaManager_code_format
 | 
			
		||||
    WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
 | 
			
		||||
)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
define_file_name(${TARGET_NAME})
 | 
			
		||||
							
								
								
									
										11
									
								
								middleware/MediaManager/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								middleware/MediaManager/README.md
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,11 @@
 | 
			
		|||
# 1. 媒体管理模块
 | 
			
		||||
 | 
			
		||||
   媒体管理模块,负责媒体相关的管理功能,包含抓拍,录像,文件管理(增/删/查)。
 | 
			
		||||
 | 
			
		||||
## 1.1. 双摄管理
 | 
			
		||||
 | 
			
		||||
   以sensor为单位,对sensor创建实例对象进行管理。
 | 
			
		||||
 | 
			
		||||
## 1.2. 文件管理
 | 
			
		||||
 | 
			
		||||
   对抓拍的图片/视频文件的管理。
 | 
			
		||||
							
								
								
									
										66
									
								
								middleware/MediaManager/include/IMediaManager.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								middleware/MediaManager/include/IMediaManager.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,66 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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_MEDIA_MANAGER_H
 | 
			
		||||
#define I_MEDIA_MANAGER_H
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#include <memory>
 | 
			
		||||
#include <vector>
 | 
			
		||||
bool CreateMediaManager(void);
 | 
			
		||||
bool DestroyMediaManager(void);
 | 
			
		||||
enum class SensorNum
 | 
			
		||||
{
 | 
			
		||||
    SENSOR_1 = 1,
 | 
			
		||||
    SENSOR_2,
 | 
			
		||||
    END
 | 
			
		||||
};
 | 
			
		||||
enum class SensorTaskType
 | 
			
		||||
{
 | 
			
		||||
    TAKE_PICTURE = 0,
 | 
			
		||||
    TAKE_VIDEO,
 | 
			
		||||
    TAKE_PICTURE_AND_VIDEO,
 | 
			
		||||
    MONITOR,
 | 
			
		||||
    END
 | 
			
		||||
};
 | 
			
		||||
class SensorTaskResponse
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    SensorTaskResponse() {}
 | 
			
		||||
    ~SensorTaskResponse() {}
 | 
			
		||||
};
 | 
			
		||||
class VSensorTask
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    VSensorTask() = default;
 | 
			
		||||
    virtual ~VSensorTask() = default;
 | 
			
		||||
    virtual const SensorTaskType GetTaskType(void) { return SensorTaskType::END; }
 | 
			
		||||
    virtual void Response(const std::vector<SensorTaskResponse> &response) {}
 | 
			
		||||
    virtual bool IsTaskFinished(void) { return false; }
 | 
			
		||||
    virtual const signed int GetIsNight(void) { return 0; }
 | 
			
		||||
    virtual const unsigned int GetIsMultShot(void) { return false; }
 | 
			
		||||
};
 | 
			
		||||
class VSensorHandle
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    VSensorHandle() = default;
 | 
			
		||||
    virtual ~VSensorHandle() = default;
 | 
			
		||||
};
 | 
			
		||||
class IMediaManager
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    IMediaManager() = default;
 | 
			
		||||
    virtual ~IMediaManager() = default;
 | 
			
		||||
    static std::shared_ptr<IMediaManager> &GetInstance(std::shared_ptr<IMediaManager> *impl = nullptr);
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										30
									
								
								middleware/MediaManager/src/IMediaManager.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								middleware/MediaManager/src/IMediaManager.cpp
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,30 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
#include "IMediaManager.h"
 | 
			
		||||
#include "ILog.h"
 | 
			
		||||
std::shared_ptr<IMediaManager> &IMediaManager::GetInstance(std::shared_ptr<IMediaManager> *impl)
 | 
			
		||||
{
 | 
			
		||||
    static auto instance = std::make_shared<IMediaManager>();
 | 
			
		||||
    if (impl) {
 | 
			
		||||
        if (instance.use_count() == 1) {
 | 
			
		||||
            LogInfo("Instance changed succeed.\n");
 | 
			
		||||
            instance = *impl;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            LogError("Can't changing the instance becase of using by some one.\n");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return instance;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										15
									
								
								middleware/MediaManager/src/MediaManagerImpl.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								middleware/MediaManager/src/MediaManagerImpl.cpp
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,15 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
#include "MediaManagerImpl.h"
 | 
			
		||||
							
								
								
									
										24
									
								
								middleware/MediaManager/src/MediaManagerImpl.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								middleware/MediaManager/src/MediaManagerImpl.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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 MEDIA_MANAGER_IMPL_H
 | 
			
		||||
#define MEDIA_MANAGER_IMPL_H
 | 
			
		||||
#include "IMediaManager.h"
 | 
			
		||||
class MediaManagerImpl : public IMediaManager
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    MediaManagerImpl() = default;
 | 
			
		||||
    virtual ~MediaManagerImpl() = default;
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										54
									
								
								middleware/MediaManager/src/MediaManagerMakePtr.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								middleware/MediaManager/src/MediaManagerMakePtr.cpp
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
#include "MediaManagerMakePtr.h"
 | 
			
		||||
#include "ILog.h"
 | 
			
		||||
#include "MediaManagerImpl.h"
 | 
			
		||||
bool CreateMediaManager(void)
 | 
			
		||||
{
 | 
			
		||||
    auto instance = std::make_shared<IMediaManager>();
 | 
			
		||||
    StatusCode code = MediaManagerMakePtr::GetInstance()->CreateMediaManager(instance);
 | 
			
		||||
    if (IsCodeOK(code)) {
 | 
			
		||||
        LogInfo("CreateMediaManager is ok.\n");
 | 
			
		||||
        IMediaManager::GetInstance(&instance);
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
bool DestroyMediaManager(void)
 | 
			
		||||
{
 | 
			
		||||
    auto instance = std::make_shared<IMediaManager>();
 | 
			
		||||
    IMediaManager::GetInstance(&instance);
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
std::shared_ptr<MediaManagerMakePtr> &MediaManagerMakePtr::GetInstance(std::shared_ptr<MediaManagerMakePtr> *impl)
 | 
			
		||||
{
 | 
			
		||||
    static auto instance = std::make_shared<MediaManagerMakePtr>();
 | 
			
		||||
    if (impl) {
 | 
			
		||||
        if (instance.use_count() == 1) {
 | 
			
		||||
            LogInfo("Instance changed succeed.\n");
 | 
			
		||||
            instance = *impl;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            LogError("Can't changing the instance becase of using by some one.\n");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return instance;
 | 
			
		||||
}
 | 
			
		||||
const StatusCode MediaManagerMakePtr::CreateMediaManager(std::shared_ptr<IMediaManager> &impl)
 | 
			
		||||
{
 | 
			
		||||
    auto tmp = std::make_shared<MediaManagerImpl>();
 | 
			
		||||
    impl = tmp;
 | 
			
		||||
    return CreateStatusCode(STATUS_CODE_OK);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										28
									
								
								middleware/MediaManager/src/MediaManagerMakePtr.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								middleware/MediaManager/src/MediaManagerMakePtr.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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 MEDIA_MANAGER_MAKE_PTR_H
 | 
			
		||||
#define MEDIA_MANAGER_MAKE_PTR_H
 | 
			
		||||
#include "IMediaManager.h"
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#include <memory>
 | 
			
		||||
class MediaManagerMakePtr
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    MediaManagerMakePtr() = default;
 | 
			
		||||
    virtual ~MediaManagerMakePtr() = default;
 | 
			
		||||
    static std::shared_ptr<MediaManagerMakePtr> &GetInstance(std::shared_ptr<MediaManagerMakePtr> *impl = nullptr);
 | 
			
		||||
    virtual const StatusCode CreateMediaManager(std::shared_ptr<IMediaManager> &impl);
 | 
			
		||||
};
 | 
			
		||||
#endif // !IPC_CONFIG_MAKE_PTR_H
 | 
			
		||||
| 
						 | 
				
			
			@ -11,4 +11,5 @@ add_subdirectory(WebServer)
 | 
			
		|||
add_subdirectory(McuProtocol)
 | 
			
		||||
add_subdirectory(ModBusCRC16)
 | 
			
		||||
add_subdirectory(LedControl)
 | 
			
		||||
add_subdirectory(KeyControl)
 | 
			
		||||
add_subdirectory(KeyControl)
 | 
			
		||||
add_subdirectory(MediaAdapter)
 | 
			
		||||
| 
						 | 
				
			
			@ -20,7 +20,13 @@ std::shared_ptr<McuProtocolMakePtr> &McuProtocolMakePtr::GetInstance(std::shared
 | 
			
		|||
{
 | 
			
		||||
    static auto instance = std::make_shared<McuProtocolMakePtr>();
 | 
			
		||||
    if (impl) {
 | 
			
		||||
        instance = *impl;
 | 
			
		||||
        if (instance.use_count() == 1) {
 | 
			
		||||
            LogInfo("Instance changed succeed.\n");
 | 
			
		||||
            instance = *impl;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            LogError("Can't changing the instance becase of using by some one.\n");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return instance;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										54
									
								
								utils/MediaAdapter/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								utils/MediaAdapter/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake)
 | 
			
		||||
set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH})
 | 
			
		||||
set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH})
 | 
			
		||||
 | 
			
		||||
include_directories(
 | 
			
		||||
    ./src
 | 
			
		||||
    ./include
 | 
			
		||||
    # ${UTILS_SOURCE_PATH}/LinuxApi/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/StatusCode/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/ModBusCRC16/include
 | 
			
		||||
    ${UTILS_SOURCE_PATH}/Log/include
 | 
			
		||||
)
 | 
			
		||||
# link_directories(
 | 
			
		||||
#     ${EXTERNAL_SOURCE_PATH}/libconfig/libconfig-1.7.3/lib/.libs
 | 
			
		||||
# )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
aux_source_directory(./src SRC_FILES)
 | 
			
		||||
 | 
			
		||||
set(TARGET_NAME MediaAdapter)
 | 
			
		||||
add_library(${TARGET_NAME} STATIC ${SRC_FILES})
 | 
			
		||||
target_link_libraries(${TARGET_NAME} StatusCode Log)
 | 
			
		||||
 | 
			
		||||
if ("${CLANG_TIDY_SUPPORT}" MATCHES "true")
 | 
			
		||||
add_custom_target(
 | 
			
		||||
    MediaAdapter_code_check
 | 
			
		||||
    COMMAND ${CLANG_TIDY_EXE}
 | 
			
		||||
    -checks='${CLANG_TIDY_CHECKS}'
 | 
			
		||||
    --header-filter=.*
 | 
			
		||||
    --system-headers=false
 | 
			
		||||
    ${SRC_FILES}
 | 
			
		||||
    ${CLANG_TIDY_CONFIG}
 | 
			
		||||
    -p ${PLATFORM_PATH}/cmake-shell
 | 
			
		||||
    WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MediaAdapter
 | 
			
		||||
)
 | 
			
		||||
file(GLOB_RECURSE HEADER_FILES *.h)
 | 
			
		||||
add_custom_target(
 | 
			
		||||
    MediaAdapter_code_format
 | 
			
		||||
    COMMAND ${CLANG_FORMAT_EXE}
 | 
			
		||||
    -style=file
 | 
			
		||||
    -i ${SRC_FILES} ${HEADER_FILES}
 | 
			
		||||
    WORKING_DIRECTORY ${UTILS_SOURCE_PATH}/MediaAdapter
 | 
			
		||||
)
 | 
			
		||||
add_custom_command(
 | 
			
		||||
    TARGET ${TARGET_NAME}
 | 
			
		||||
    PRE_BUILD
 | 
			
		||||
    COMMAND make MediaAdapter_code_check
 | 
			
		||||
    COMMAND make MediaAdapter_code_format
 | 
			
		||||
    WORKING_DIRECTORY ${PLATFORM_PATH}/cmake-shell/
 | 
			
		||||
)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
define_file_name(${TARGET_NAME})
 | 
			
		||||
							
								
								
									
										27
									
								
								utils/MediaAdapter/include/MediaAdapter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								utils/MediaAdapter/include/MediaAdapter.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,27 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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 MEDIA_ADAPTER_H
 | 
			
		||||
#define MEDIA_ADAPTER_H
 | 
			
		||||
#include "StatusCode.h"
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
void *CreateMediaAdapter(void);
 | 
			
		||||
void TestApi(void *object);
 | 
			
		||||
void IMediaAdapterFree(void *object);
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										29
									
								
								utils/MediaAdapter/src/IMediaAdapter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								utils/MediaAdapter/src/IMediaAdapter.cpp
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
#include "IMediaAdapter.h"
 | 
			
		||||
#include "ILog.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
static const char *MEDIA_ADAPTER_NAME = "media_adapter";
 | 
			
		||||
const char inline *GetMediaAdapterModuleName(void) { return MEDIA_ADAPTER_NAME; }
 | 
			
		||||
std::shared_ptr<IMediaAdapter> *NewIMediaAdapter(void)
 | 
			
		||||
{
 | 
			
		||||
    LogInfo("Create the uart device object.\n");
 | 
			
		||||
    MeidaAdapter *impl = (MeidaAdapter *)malloc(sizeof(MeidaAdapter));
 | 
			
		||||
    MeidaAdapter tmp;
 | 
			
		||||
    memcpy((void *)impl, (void *)&tmp, sizeof(MeidaAdapter));
 | 
			
		||||
    impl->mHeader.mCheckName = MEDIA_ADAPTER_NAME;
 | 
			
		||||
    impl->mIMediaAdapter = std::make_shared<IMediaAdapter>();
 | 
			
		||||
    return (std::shared_ptr<IMediaAdapter> *)(((char *)impl) + sizeof(MediaAdapterHeader));
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										36
									
								
								utils/MediaAdapter/src/IMediaAdapter.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								utils/MediaAdapter/src/IMediaAdapter.h
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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_MEDIA_ADAPTER_H
 | 
			
		||||
#define I_MEDIA_ADAPTER_H
 | 
			
		||||
#include <memory>
 | 
			
		||||
class IMediaAdapter
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    IMediaAdapter() = default;
 | 
			
		||||
    virtual ~IMediaAdapter() = default;
 | 
			
		||||
    virtual void TestApi(void) {}
 | 
			
		||||
};
 | 
			
		||||
typedef struct media_adapter_header
 | 
			
		||||
{
 | 
			
		||||
    const char *mCheckName;
 | 
			
		||||
} MediaAdapterHeader;
 | 
			
		||||
typedef struct media_adapter
 | 
			
		||||
{
 | 
			
		||||
    MediaAdapterHeader mHeader;
 | 
			
		||||
    std::shared_ptr<IMediaAdapter> mIMediaAdapter;
 | 
			
		||||
} MeidaAdapter;
 | 
			
		||||
const char *GetMediaAdapterModuleName(void);
 | 
			
		||||
std::shared_ptr<IMediaAdapter> *NewIMediaAdapter(void);
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										49
									
								
								utils/MediaAdapter/src/MediaAdapter.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								utils/MediaAdapter/src/MediaAdapter.cpp
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,49 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
#include "MediaAdapter.h"
 | 
			
		||||
#include "ILog.h"
 | 
			
		||||
#include "IMediaAdapter.h"
 | 
			
		||||
void *CreateMediaAdapter(void) { return NewIMediaAdapter(); }
 | 
			
		||||
static bool ObjectCheck(void *object)
 | 
			
		||||
{
 | 
			
		||||
    if (nullptr == object) {
 | 
			
		||||
        LogError("nullptr object!\n");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    if (*((const char **)(((char *)object) - sizeof(IMediaAdapter))) != GetMediaAdapterModuleName()) {
 | 
			
		||||
        LogError("Illegal object!\n");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
void TestApi(void *object)
 | 
			
		||||
{
 | 
			
		||||
    if (nullptr == object) {
 | 
			
		||||
        LogError("nullptr object!\n");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (*((const char **)(((char *)object) - sizeof(IMediaAdapter))) != GetMediaAdapterModuleName()) {
 | 
			
		||||
        LogError("Illegal object!\n");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    (*(std::shared_ptr<IMediaAdapter> *)object)->TestApi();
 | 
			
		||||
}
 | 
			
		||||
void IMediaAdapterFree(void *object)
 | 
			
		||||
{
 | 
			
		||||
    if (ObjectCheck(object) == true) {
 | 
			
		||||
        (*(std::shared_ptr<IMediaAdapter> *)object).reset();
 | 
			
		||||
        free(((char *)object) - sizeof(IMediaAdapter));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -50,6 +50,7 @@ typedef struct uart_device
 | 
			
		|||
    void (*mTcflush)(UartDevice *);
 | 
			
		||||
    void (*mFree)(void *);
 | 
			
		||||
} UartDevice;
 | 
			
		||||
// TODO: There may be a CPU byte alignment bug.
 | 
			
		||||
typedef struct uart_device_impl UartDeviceImpl_S;
 | 
			
		||||
typedef struct uart_device_impl
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user