提交 f0f0d8cc 编写于 作者: L libb

add rtmp01

Change-Id: I110e6a54c519eac1b0f2e1444b1fbfabd2cd8d85
上级 bf6c367f
cmake_minimum_required(VERSION 3.4.1)
PROJECT(FFL)
#SET(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/install)
INCLUDE(./cmakemode/FFLv2Utils.cmake)
###############################################################################################################################
#生成日志等级宏
# dubug:4 , info:3, warning:2,error:1,crit:0
SET(FFLIB_COMPILE_LOG_LEVEL "3" CACHE PATH "Log Level")
#系统级错误
IF(FFLIB_COMPILE_LOG_LEVEL GREATER 0 OR FFLIB_COMPILE_LOG_LEVEL EQUAL "0")
SET(FFL_LOG_CRIT
"#define FFL_LOG_CRIT(format,...) FFL_LogPrint(FFL_LOG_LEVEL_CRIT,format,##__VA_ARGS__)\n#define FFL_LOG_CRIT_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_CRIT,tag,format,##__VA_ARGS__)")
ELSE()
SET(FFL_LOG_CRIT
"#define FFL_LOG_CRIT(format,...)\n#define FFL_LOG_CRIT_TAG(tag,format,...) ")
ENDIF()
#错误等级
IF(FFLIB_COMPILE_LOG_LEVEL GREATER "1" OR FFLIB_COMPILE_LOG_LEVEL EQUAL "1")
SET(FFL_LOG_ERROR
"#define FFL_LOG_ERROR(format,...) FFL_LogPrint(FFL_LOG_LEVEL_ERROR,format,##__VA_ARGS__)\n#define FFL_LOG_ERROR_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_ERROR,tag,format,##__VA_ARGS__)")
ELSE()
SET(FFL_LOG_ERROR
"#define FFL_LOG_ERROR(format,...)\n#define FFL_LOG_ERROR_TAG(tag,format,...) ")
ENDIF()
#警告级别
IF(FFLIB_COMPILE_LOG_LEVEL GREATER "2" OR FFLIB_COMPILE_LOG_LEVEL EQUAL "2")
SET(FFL_LOG_WARING
"#define FFL_LOG_WARNING(format,...) FFL_LogPrint(FFL_LOG_LEVEL_WARNING,format,##__VA_ARGS__)\n#define FFL_LOG_WARNING_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_WARNING,tag,format,##__VA_ARGS__)")
ELSE()
SET(FFL_LOG_WARING
"#define FFL_LOG_WARNING(format,...)\n#define FFL_LOG_WARNING_TAG(tag,format,...) ")
ENDIF()
#运行信息
IF(FFLIB_COMPILE_LOG_LEVEL GREATER "3" OR FFLIB_COMPILE_LOG_LEVEL EQUAL "3")
SET(FFL_LOG_INFO
"#define FFL_LOG_INFO(format,...) FFL_LogPrint(FFL_LOG_LEVEL_INFO,format,##__VA_ARGS__) \n#define FFL_LOG_INFO_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_INFO,tag,format,##__VA_ARGS__)")
ELSE()
SET(FFL_LOG_INFO
"#define FFL_LOG_INFO(format,...)\n#define FFL_LOG_INFO_TAG(tag,format,...) ")
ENDIF()
#调试级别
IF(FFLIB_COMPILE_LOG_LEVEL GREATER "4" OR FFLIB_COMPILE_LOG_LEVEL EQUAL "4" )
SET(FFL_LOG_DEBUG
"#define FFL_LOG_DEBUG(format,...) FFL_LogPrint(FFL_LOG_LEVEL_DEBUG,format,##__VA_ARGS__)\n#define FFL_LOG_DEBUG_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_DEBUG,tag,format,##__VA_ARGS__)")
ELSE()
SET(FFL_LOG_DEBUG
"#define FFL_LOG_DEBUG(format,...) \n#define FFL_LOG_DEBUG_TAG(tag,format,...) ")
ENDIF()
# 生成日志等级宏FFL_LogConfig.h
CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/include/FFL_LogConfig.h.in" "${PROJECT_BINARY_DIR}/FFL_LogConfig.h")
###############################################################################################################################
IF(APPLE)
SET(FFLIB_COMPILE_STATIC ON CACHE BOOL "build static library")
# ios仅仅支持静态库,需要修改CMAKE_SYSROOT路径指向ios sdk路径上
ELSE()
# static lib
SET(FFLIB_COMPILE_STATIC ON CACHE BOOL "build static library")
ENDIF()
#是否生成example
SET(FFLIB_COMPILE_EXAMPLE OFF CACHE BOOL "build static example")
# 编译静态库还是动态库
IF (FFLIB_COMPILE_STATIC)
set(FFLIB_IMPORT "")
set(FFLIB_EXPORT "")
ELSE(FFLIB_COMPILE_STATIC)
if (NOT MSVC)
set(FFLIB_IMPORT "")
set(FFLIB_EXPORT "__attribute__((visibility(\"default\")))")
else ()
set(FFLIB_IMPORT "__declspec(dllimport)")
set(FFLIB_EXPORT "__declspec(dllexport)")
endif ()
ENDIF (FFLIB_COMPILE_STATIC )
#使用哪一个线程库
IF(WIN32)
OPTION(FFLIB_USING_THREAD_WIN32 "using win32 system thread" ON )
OPTION(FFLIB_USING_THREAD_STD "using std thread" OFF )
ELSE()
OPTION(FFLIB_USING_THREAD_PTHREAD "using pthread" ON )
OPTION(FFLIB_USING_THREAD_STD "using std thread" OFF )
ENDIF()
if(FFLIB_USING_THREAD_WIN32)
SET(HAVE_THREAD_WIN "#define FFL_THREAD_WINDOWS 1")
SET(FFLIB_USING_THREAD_STD OFF)
else()
SET(HAVE_THREAD_WIN "#define FFL_THREAD_WINDOWS 0")
endif()
if(FFLIB_USING_THREAD_PTHREAD)
SET(HAVE_THREAD_PTHREAD "#define FFL_THREAD_PTHREAD 1")
else()
SET(HAVE_THREAD_PTHREAD "#define FFL_THREAD_PTHREAD 0")
endif()
if(FFLIB_USING_THREAD_STD)
SET(HAVE_THREAD_STDCPP "#define FFL_THREAD_STDCPP 1")
else()
SET(HAVE_THREAD_STDCPP "#define FFL_THREAD_STDCPP 0")
endif()
#生成配置文件 FFL_Config.h
CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/include/FFL_Config.h.in" "${PROJECT_BINARY_DIR}/FFL_Config.h")
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR};include;source)
IF(WIN32)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 ")
SET(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
ELSE()
#默认的函数隐藏,不导出
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fvisibility=hidden")
SET(CMAKE_CXX_FLAGS "-std=c++11 -fvisibility=hidden ${CMAKE_CXX_FLAGS}")
ENDIF()
SET(HEADER_FILES
./include/FFL_lib.h
./include/FFL_lib.hpp
./include/FFL_Netlib.h
./include/FFL_Netlib.hpp
#最基础的功能
./include/FFL_Version.h
./include/FFL_Platform.h
./include/FFL_Stdint.h
./include/FFL_Error.h
./include/FFL_Assert.h
./include/FFL_Memory.h
./include/FFL_String.h
./include/FFL_Time.h
./include/FFL_Atomic.h
./include/FFL_Core.h
./include/FFL_Log.h
./include/FFL_Path.h
./include/FFL_Console.h
./include/FFL_Console.hpp
./include/FFL_Thread.h
./include/FFL_ThreadConstant.h
./include/FFL_Threadpool.h
./include/FFL_Mutex.h
./include/FFL_Thread.hpp
./include/FFL_Mutex.hpp
./include/FFL_BlockList.hpp
./include/FFL_ByteBuffer.hpp
./include/FFL_ByteReader.hpp
./include/FFL_ByteStream.hpp
./include/FFL_ByteWriter.hpp
./include/FFL_Dictionary.hpp
./include/FFL_Flags.hpp
./include/FFL_Io.hpp
./include/FFL_Module.hpp
./include/FFL_Serializable.hpp
./include/FFL_String.hpp
./include/FFL_Utils.hpp
./include/FFL_SharedBuffer.hpp
./include/FFL_File.hpp
./include/FFL_Ref.hpp
./include/FFL_RefAtomic.hpp
./include/FFL_RefBase.hpp
./include/FFL_RefCount.hpp
./include/FFL_RefSp.hpp
./include/FFL_RefWeakimpl.hpp
./include/FFL_RefWp.hpp
)
SET(HEADER_NET_FILES
#网络部分
./include/net/FFL_Net.h
./include/net/FFL_NetConst.h
./include/net/FFL_NetEventLoop.hpp
./include/net/FFL_NetSocket.hpp
./include/net/FFL_NetStream.hpp
./include/net/FFL_NetUtils.hpp
./include/net/FFL_TcpClient.hpp
./include/net/FFL_TcpListener.hpp
./include/net/FFL_TcpServer.hpp
./include/net/FFL_UdpClient.hpp
./include/net/FFL_UdpServer.hpp
)
SET(HEADER_HTTP_FILES
#http
./include/net/http/FFL_Http.hpp
./include/net/http/FFL_HttpClient.hpp
./include/net/http/FFL_HttpClientAccess.hpp
./include/net/http/FFL_HttpHeader.hpp
./include/net/http/FFL_HttpParser.hpp
./include/net/http/FFL_HttpRequest.hpp
./include/net/http/FFL_HttpResponse.hpp
./include/net/http/FFL_HttpTransportBase.hpp
./include/net/http/FFL_HttpFile.hpp
./include/net/http/FFL_HttpServer.hpp
./include/net/http/FFL_HttpUrl.hpp
)
SET(HEADER_WEBSOCKET_FILES
#websocket
./include/net/websocket/FFL_WebSocketClient.hpp
./include/net/websocket/FFL_WebSocketServer.hpp
)
SET(SOURCE_FILES
./source/FFL_Version.c
./source/FFL_Error.c
./source/FFL_Memory.c
./source/FFL_String.c
./source/FFL_Time.c
./source/FFL_Atomic.c
./source/FFL_Core.c
./source/FFL_Core.cpp
./source/FFL_Log.c
./source/FFL_Path.c
./source/FFL_Console.c
./source/FFL_Console.cpp
./source/getopt/getopt.h
./source/getopt/getopt.c
./source/getopt/getopt_int.h
./source/getopt/getopt_int.c
./source/atomic/atomic.h
./source/atomic/atomic.cpp
./source/thread/FFL_thread.c
./source/thread/FFL_threadpool.c
./source/thread/threadpool/threadpool.h
./source/thread/threadpool/threadpool.c
./source/thread/threadpool/threadpool_job.h
./source/thread/threadpool/threadpool_job.c
./source/thread/FFL_Mutex.cpp
./source/thread/FFL_Thread.cpp
./source/FFL_ByteBuffer.cpp
./source/FFL_ByteStream.cpp
./source/FFL_Dictionary.cpp
./source/FFL_File.cpp
./source/FFL_Flags.cpp
./source/FFL_Module.cpp
./source/FFL_Serializable.cpp
./source/FFL_String.cpp
./source/FFL_SharedBuffer.cpp
./source/FFL_RefBase.cpp
./source/FFL_RefWakeimpl.cpp
./source/FFL_Sha1.hpp
./source/FFL_Sha1.cpp
./source/FFL_Base64.hpp
./source/FFL_Base64.cpp
)
IF(FFLIB_USING_THREAD_WIN32)
SET(SOURCE_FILES ${SOURCE_FILES}
./source/thread/windows/sysmutex.c
./source/thread/windows/systhread.c
./source/thread/windows/syssem.c
./source/thread/windows/syscond.c
)
ENDIF()
IF(FFLIB_USING_THREAD_STD)
SET(SOURCE_FILES ${SOURCE_FILES}
./source/thread/stdcpp/syscond.cpp
./source/thread/stdcpp/sysmutex.cpp
./source/thread/stdcpp/systhread.cpp
./source/thread/stdcpp/syssem.c
)
ENDIF()
IF(FFLIB_USING_THREAD_PTHREAD)
SET(SOURCE_FILES ${SOURCE_FILES}
./source/thread/pthread/syscond.c
./source/thread/pthread/sysmutex.c
./source/thread/pthread/systhread.c
./source/thread/pthread/syssem.c
./source/thread/pthread/systls.c
)
ENDIF()
#网络部分
AUX_SOURCE_DIRECTORY(./source/net/base/ DIR_SRCS)
SET(SOURCE_FILES ${DIR_SRCS} ${SOURCE_FILES})
AUX_SOURCE_DIRECTORY(./source/net/ DIR_SRCS)
SET(SOURCE_FILES ${DIR_SRCS} ${SOURCE_FILES})
AUX_SOURCE_DIRECTORY(./source/net/http DIR_SRCS)
SET(SOURCE_FILES ${DIR_SRCS} ${SOURCE_FILES})
AUX_SOURCE_DIRECTORY(./source/net/http/http-parser-2.1 DIR_SRCS)
SET(SOURCE_FILES ${DIR_SRCS} ${SOURCE_FILES})
AUX_SOURCE_DIRECTORY(./source/net/websocket DIR_SRCS)
SET(SOURCE_FILES ${DIR_SRCS} ${SOURCE_FILES})
SET(LOCAL_SRC_FILES
${SOURCE_FILES}
${HEADER_FILES}
${HEADER_NET_FILES}
${HEADER_HTTP_FILES}
${HEADER_WEBSOCKET_FILES})
group_by_dir(${CMAKE_SOURCE_DIR} ${LOCAL_SRC_FILES})
if (MSVC)
add_definitions("/wd4819 /wd4996")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif(MSVC)
#编译对应库文件
if (FFLIB_COMPILE_STATIC)
ADD_LIBRARY( FFL STATIC ${LOCAL_SRC_FILES})
else()
ADD_LIBRARY( FFL SHARED ${LOCAL_SRC_FILES})
endif()
SET_TARGET_PROPERTIES(FFL PROPERTIES CLEAN_DIRECT_OUTPUT 1)
if(FFLIB_COMPILE_EXAMPLE)
ADD_SUBDIRECTORY(example)
endif()
#安装脚本
# 安装${HEADERS}文件到include目录
# 安装生成文件到lib目录
SET(HEADERS
${HEADER_FILES}
${PROJECT_BINARY_DIR}/FFL_Config.h
${PROJECT_BINARY_DIR}/FFL_LogConfig.h
)
install(FILES ${HEADERS} DESTINATION include/)
install(FILES ${HEADER_NET_FILES} DESTINATION include/net/)
install(FILES ${HEADER_HTTP_FILES} DESTINATION include/net/http/)
install(FILES ${HEADER_WEBSOCKET_FILES} DESTINATION include/net/websocket/)
install(TARGETS FFL DESTINATION lib/)
#分组源文件
FUNCTION(group_by_dir src_dir)
foreach(FILE ${ARGN})
# 获取文件绝对路径
get_filename_component(FULL_NAME "${FILE}" ABSOLUTE)
# 获取文件父路径
get_filename_component(PARENT_DIR "${FULL_NAME}" PATH)
# 移除父路径中的源码根路径
string(REPLACE "${ARGV0}" "" GROUP "${PARENT_DIR}")
# 确保路径使用windows路径符号
string(REPLACE "/" "\\" GROUP "${GROUP}")
# 将文件归组到 "Source Files" 和 "Header Files"
if("${FILE}" MATCHES ".*\\.h")
set(GROUP "Header Files${GROUP}")
else()
set(GROUP "Source Files${GROUP}")
endif()
source_group("${GROUP}" FILES "${FILE}")
endforeach()
endfunction(group_by_dir)
#打印参数
FUNCTION(printf arg)
message("message:" ${ARGV0})
ENDFUNCTION()
# mt编译
FUNCTION(MSVC_mt)
if (MSVC)
add_definitions("/wd4819")
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif(MSVC)
ENDFUNCTION()
#group_by_dir("${CMAKE_CURRENT_SOURCE_DIR}" ${INC_LIST})
#group_by_dir("${CMAKE_CURRENT_SOURCE_DIR}" ${SRC_LIST})
\ No newline at end of file
#指定FFLv2库源码位置
SET( FFLV2_SOURCE_DIR ${CMAKE_MODULE_PATH}/../FFLv2-lib)
#message(message ${CMAKE_MODULE_PATH})
#message(message ${FFLV2_SOURCE_DIR})
if( IS_DIRECTORY ${FFLV2_SOURCE_DIR} )
#关闭example的编译
SET( BUILD_FFLV2_EXAMPLE "OFF")
#include目录指向源文件
SET (FFLV2_LIB_INCLUDE_PATH ${FFLV2_SOURCE_DIR}/include)
SET (FFLV2_LIB_LIB_PATH "")
# 第二个cassdk.out参数用于指定外部文件夹在输出文件夹中的位置
add_subdirectory( ${FFLV2_SOURCE_DIR} FFLv2.out )
else()
# 目录指向安装目录
SET (FFLV2_LIB_INCLUDE_PATH ${CMAKE_SOURCE_DIR}/../install/FFLv2-lib/include)
SET (FFLV2_LIB_LIB_PATH ${CMAKE_SOURCE_DIR}/../install/FFLv2-lib/include)
endif()
function(group_by_dir src_dir)
foreach(FILE ${ARGN})
# 获取文件绝对路径
get_filename_component(FULL_NAME "${FILE}" ABSOLUTE)
# 获取文件父路径
get_filename_component(PARENT_DIR "${FULL_NAME}" PATH)
# 移除父路径中的源码根路径
string(REPLACE "${ARGV0}" "" GROUP "${PARENT_DIR}")
# 确保路径使用windows路径符号
string(REPLACE "/" "\\" GROUP "${GROUP}")
# 将文件归组到 "Source Files" 和 "Header Files"
if("${FILE}" MATCHES ".*\\.h")
set(GROUP "Header Files${GROUP}")
else()
set(GROUP "Source Files${GROUP}")
endif()
source_group("${GROUP}" FILES "${FILE}")
endforeach()
endfunction(group_by_dir)
group_by_dir("${CMAKE_CURRENT_SOURCE_DIR}" ${INC_LIST})
group_by_dir("${CMAKE_CURRENT_SOURCE_DIR}" ${SRC_LIST})
\ No newline at end of file
# This file is based off of the Platform/Darwin.cmake and Platform/UnixPaths.cmake
# files which are included with CMake 2.8.4
# It has been altered for iOS development
# Options:
#
# IOS_PLATFORM = OS (default) or SIMULATOR or SIMULATOR64
# This decides if SDKS will be selected from the iPhoneOS.platform or iPhoneSimulator.platform folders
# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
#
# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
# By default this location is automatcially chosen based on the IOS_PLATFORM value above.
# If set manually, it will override the default location and force the user of a particular Developer Platform
#
# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
# If set manually, this will force the use of a specific SDK version
# Macros:
#
# set_xcode_property (TARGET XCODE_PROPERTY XCODE_VALUE)
# A convenience macro for setting xcode specific properties on targets
# example: set_xcode_property (myioslib IPHONEOS_DEPLOYMENT_TARGET "3.1")
#
# find_host_package (PROGRAM ARGS)
# A macro used to find executable programs on the host system, not within the iOS environment.
# Thanks to the android-cmake project for providing the command
# Standard settings
set (CMAKE_SYSTEM_NAME Darwin)
set (CMAKE_SYSTEM_VERSION 1)
set (UNIX True)
set (APPLE True)
set (IOS True)
# Required as of cmake 2.8.10
set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
# Determine the cmake host system version so we know where to find the iOS SDKs
find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
if (CMAKE_UNAME)
exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
endif (CMAKE_UNAME)
# Force the compilers to gcc for iOS
#include (CMakeForceCompiler)
#CMAKE_FORCE_C_COMPILER (/usr/bin/gcc Apple)
#CMAKE_FORCE_CXX_COMPILER (/usr/bin/g++ Apple)
#set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
# Skip the platform compiler checks for cross compiling
set (CMAKE_CXX_COMPILER_WORKS TRUE)
set (CMAKE_C_COMPILER_WORKS TRUE)
# All iOS/Darwin specific settings - some may be redundant
set (CMAKE_SHARED_LIBRARY_PREFIX "lib")
set (CMAKE_SHARED_LIBRARY_SUFFIX ".dylib")
set (CMAKE_SHARED_MODULE_PREFIX "lib")
set (CMAKE_SHARED_MODULE_SUFFIX ".so")
set (CMAKE_MODULE_EXISTS 1)
set (CMAKE_DL_LIBS "")
set (CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG "-compatibility_version ")
set (CMAKE_C_OSX_CURRENT_VERSION_FLAG "-current_version ")
set (CMAKE_CXX_OSX_COMPATIBILITY_VERSION_FLAG "${CMAKE_C_OSX_COMPATIBILITY_VERSION_FLAG}")
set (CMAKE_CXX_OSX_CURRENT_VERSION_FLAG "${CMAKE_C_OSX_CURRENT_VERSION_FLAG}")
# Hidden visibilty is required for cxx on iOS
set (CMAKE_C_FLAGS_INIT "")
set (CMAKE_CXX_FLAGS_INIT "-fvisibility=hidden -fvisibility-inlines-hidden")
set (CMAKE_C_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
set (CMAKE_CXX_LINK_FLAGS "-Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
set (CMAKE_PLATFORM_HAS_INSTALLNAME 1)
set (CMAKE_SHARED_LIBRARY_CREATE_C_FLAGS "-dynamiclib -headerpad_max_install_names")
set (CMAKE_SHARED_MODULE_CREATE_C_FLAGS "-bundle -headerpad_max_install_names")
set (CMAKE_SHARED_MODULE_LOADER_C_FLAG "-Wl,-bundle_loader,")
set (CMAKE_SHARED_MODULE_LOADER_CXX_FLAG "-Wl,-bundle_loader,")
set (CMAKE_FIND_LIBRARY_SUFFIXES ".dylib" ".so" ".a")
# hack: if a new cmake (which uses CMAKE_INSTALL_NAME_TOOL) runs on an old build tree
# (where install_name_tool was hardcoded) and where CMAKE_INSTALL_NAME_TOOL isn't in the cache
# and still cmake didn't fail in CMakeFindBinUtils.cmake (because it isn't rerun)
# hardcode CMAKE_INSTALL_NAME_TOOL here to install_name_tool, so it behaves as it did before, Alex
if (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
find_program(CMAKE_INSTALL_NAME_TOOL install_name_tool)
endif (NOT DEFINED CMAKE_INSTALL_NAME_TOOL)
# Setup iOS platform unless specified manually with IOS_PLATFORM
if (NOT DEFINED IOS_PLATFORM)
set (IOS_PLATFORM "OS")
endif (NOT DEFINED IOS_PLATFORM)
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
# Setup building for arm64 or not
if (NOT DEFINED BUILD_ARM64)
set (BUILD_ARM64 true)
endif (NOT DEFINED BUILD_ARM64)
set (BUILD_ARM64 ${BUILD_ARM64} CACHE STRING "Build arm64 arch or not")
# Check the platform selection and setup for developer root
if (${IOS_PLATFORM} STREQUAL "OS")
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
set (SIMULATOR true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
set (SIMULATOR true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
else (${IOS_PLATFORM} STREQUAL "OS")
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS or SIMULATOR")
endif (${IOS_PLATFORM} STREQUAL "OS")
# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
# Note Xcode 4.3 changed the installation location, choose the most recent one available
exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
if (EXISTS ${XCODE_POST_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
elseif(EXISTS ${XCODE_PRE_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
endif (EXISTS ${XCODE_POST_43_ROOT})
endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
set (CMAKE_IOS_DEVELOPER_ROOT ${CMAKE_IOS_DEVELOPER_ROOT} CACHE PATH "Location of iOS Platform")
# Find and use the most recent iOS sdk unless specified manually with CMAKE_IOS_SDK_ROOT
if (NOT DEFINED CMAKE_IOS_SDK_ROOT)
file (GLOB _CMAKE_IOS_SDKS "${CMAKE_IOS_DEVELOPER_ROOT}/SDKs/*")
if (_CMAKE_IOS_SDKS)
list (SORT _CMAKE_IOS_SDKS)
list (REVERSE _CMAKE_IOS_SDKS)
list (GET _CMAKE_IOS_SDKS 0 CMAKE_IOS_SDK_ROOT)
else (_CMAKE_IOS_SDKS)
message (FATAL_ERROR "No iOS SDK's found in default search path ${CMAKE_IOS_DEVELOPER_ROOT}. Manually set CMAKE_IOS_SDK_ROOT or install the iOS SDK.")
endif (_CMAKE_IOS_SDKS)
message (STATUS "Toolchain using default iOS SDK: ${CMAKE_IOS_SDK_ROOT}")
endif (NOT DEFINED CMAKE_IOS_SDK_ROOT)
set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the selected iOS SDK")
# Set the sysroot default to the most recent SDK
set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
# set the architecture for iOS armv7 armv7s
if (${IOS_PLATFORM} STREQUAL "OS")
set (IOS_ARCH arm64)
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
set (IOS_ARCH i386)
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR64")
set (IOS_ARCH x86_64)
endif (${IOS_PLATFORM} STREQUAL "OS")
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE string "Build architecture for iOS")
# Set the find root to the iOS developer roots and to user defined paths
set (CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string "iOS find search path root")
# default to searching for frameworks first
set (CMAKE_FIND_FRAMEWORK FIRST)
# set up the default search directories for frameworks
set (CMAKE_SYSTEM_FRAMEWORK_PATH
${CMAKE_IOS_SDK_ROOT}/System/Library/Frameworks
${CMAKE_IOS_SDK_ROOT}/System/Library/PrivateFrameworks
${CMAKE_IOS_SDK_ROOT}/Developer/Library/Frameworks
)
# only search the iOS sdks, not the remainder of the host filesystem
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# This little macro lets you set any XCode specific property
macro (set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE)
set_property (TARGET ${TARGET} PROPERTY XCODE_ATTRIBUTE_${XCODE_PROPERTY} ${XCODE_VALUE})
endmacro (set_xcode_property)
# This macro lets you find executable programs on the host system
macro (find_host_package)
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY NEVER)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE NEVER)
set (IOS FALSE)
find_package(${ARGN})
set (IOS TRUE)
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endmacro (find_host_package)
cmake_minimum_required(VERSION 3.4.1)
PROJECT(httpServer)
INCLUDE_DIRECTORIES(
./
../ffl/include/)
SET(LOCAL_SRC_FILES
main.cpp;httpServer.cpp
)
if (MSVC)
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif(MSVC)
ADD_EXECUTABLE(httpServer main.cpp;httpServer.cpp)
TARGET_LINK_LIBRARIES(httpServer FFL)
ADD_EXECUTABLE(httpClient main.cpp;httpClient.cpp)
TARGET_LINK_LIBRARIES(httpClient FFL)
ADD_EXECUTABLE(websocketClient main.cpp;websocketClient.cpp)
TARGET_LINK_LIBRARIES(websocketClient FFL)
ADD_EXECUTABLE(websocketServer main.cpp;websocketServer.cpp)
TARGET_LINK_LIBRARIES(websocketServer FFL)
#ADD_EXECUTABLE(memoryLeak main.cpp;memoryLeak.cpp)
#TARGET_LINK_LIBRARIES(memoryLeak FFL)
#include <FFL_Netlib.hpp>
class HttpCallback : public FFL::HttpClientAccessManager::Callback {
public:
//
// ����Ӧ��
// errorNo :������
//
virtual void onResponse(FFL::sp<FFL::HttpResponse> response, int32_t errorNo) {
if (!response.isEmpty()) {
FFL::HttpHeader header;
response->getHeader(header);
FFL_LOG_DEBUG("response: %d contentLen=%d", response->getStatusCode(), header.getContentLength());
}
else {
FFL_LOG_DEBUG("response: failed errorNo=%d", errorNo);
}
}
};
int FFL_main() {
char exePath[1024] = {};
char exeName[1024] = {};
FFL_getCurrentProcessPath(exePath, 1023, exeName);
FFL_socketInit();
FFL::HttpClientAccessManager clientMgr;
clientMgr.start();
FFL_LOG_DEBUG("saddsad");
FFL_LOG_DEBUG("saddsad %d",1);
{
FFL::sp<FFL::HttpRequest> request = new FFL::HttpRequest(NULL);
FFL::HttpUrl url;
url.parse(FFL::String("http://127.0.0.1:5000/FFLv2?login"));
request->setUrl(url);
clientMgr.post(request, new HttpCallback());
}
{
FFL::sp<FFL::HttpRequest> request = new FFL::HttpRequest(NULL);
FFL::HttpUrl url;
url.parse(FFL::String("http://127.0.0.1:5000/FFLv2?login&asdasd=asd"));
request->setUrl(url);
clientMgr.post(request, new HttpCallback());
}
while (1) {
FFL_sleep(2000);
}
return 0;
}
#include <FFL_Netlib.hpp>
#include <FFL_Console.h>
volatile int gQuitFlag = 0;
static void stop(const char* args, void* userdata) {
FFL::HttpServer* httpServer = (FFL::HttpServer*) userdata;
httpServer->stop();
gQuitFlag = 1;
}
static CmdOption myCmdOption[] = {
{ "stop",0,stop,"stop server " },
{ 0,0,0,0 }
};
int QuitFlag(void* userdata) {
return gQuitFlag;
}
FFL::String gLastLog;
class HttGetLogListHandelr : public FFL::HttpServer::Callback {
public:
virtual bool onHttpQuery(FFL::HttpRequest* request) {
FFL::HttpUrl url;
request->getUrl(url);
if (0) {
FFL::sp<FFL::HttpResponse> response = request->makeResponse();
response->setContent((uint8_t*)(gLastLog.string()), gLastLog.size());
response->setStatusCode(200);
response->send();
response->finish();
}
else {
FFL::sp<FFL::HttpResponseFile> response =
new FFL::HttpResponseFile(request->getHttpClient());
response->setStatusCode(200);
response->writeFile("d://test.jpg");
response->finish();
}
return false;
};
};
class HttpApiLoginHandelr : public FFL::HttpServer::Callback {
public:
virtual bool onHttpQuery(FFL::HttpRequest* request) {
FFL::HttpUrl url;
request->getUrl(url);
FFL::HttpHeader header;
request->getHeader(header);
FFL::sp<FFL::HttpContent> content =request->readContent();
uint8_t buffer[4096] = {};
size_t bufSize = 4096;
size_t readed = 0;
int32_t requestSize = header.getContentLength();
FFL_ASSERT((size_t)requestSize <= bufSize);
if ((readed=content->read(buffer, requestSize,NULL))>0) {
buffer[readed] = 0;
FFL_LOG_WARNING_TAG("http:", " requestSize=%d readed=%d", requestSize,readed);
FFL_LOG_WARNING_TAG("http:", " %s", ((const char*)buffer));
gLastLog.setTo((const char*)buffer, readed);
}
else {
FFL_LOG_WARNING_TAG("http", "read fail");
}
FFL::sp<FFL::HttpResponse> response=request->makeResponse();
response->setStatusCode(200);
response->send();
response->finish();
//FFL::HttpResponseBuilder builder;
//FFL::sp<FFL::HttpResponseFile> response =builder.createResponseFile(request);
//FFL::File file;
//file.open(FFL::String("d://test.txt"));
//FFL::HttpHeader header;
//header.setContentLength(file.getSize());
//response->setHeader(header);
//response->guessFileType("test.txt");
//response->setReader(&file);
//response->send();
return false;
};
};
class TcpHandler : public FFL::TcpServer::Callback {
public:
//
// aliveTimeUs:保活时长,如果超过这么长时间还没有数据则干掉这个client
// <0 一直存活,
//
virtual bool onClientCreate(FFL::TcpClient* client, int64_t* aliveTimeUs) {
FFL_LOG_DEBUG("TcpHandler:onClientCreate (%p) ", client);
return true;
}
virtual void onClientDestroy(FFL::TcpClient* client, FFL::TcpServer::Callback::FD_OPTMODE reason) {
FFL_LOG_DEBUG("TcpHandler:onClientDestroy (%p) %s ", client);
}
virtual FFL::TcpServer::Callback::FD_OPTMODE onClientReceived(FFL::TcpClient* client) {
size_t readed = 0;
char buf[4096] = {};
if (client->read((uint8_t*)buf, 4095, &readed)!=FFL_OK) {
return FFL::TcpServer::Callback::FD_DESTROY;
}
FFL_LOG_DEBUG("TcpHandler:onClientReceived (%p) (len=%d) %s ",client,readed,buf);
return FFL::TcpServer::Callback::FD_CONTINUE;
}
};
int FFL_main() {
char exePath[1024] = {};
char exeName[1024] = {};
FFL_getCurrentProcessPath(exePath, 1023, exeName);
gLastLog = "hi:";
gLastLog += exePath;
//if (0) {
// TcpHandler handler;
// FFL::TcpServer tcpServer("127.0.0.1",5000,&handler);
// tcpServer.start(NULL);
// int32_t waitMs = 5000;
// while (tcpServer.eventLoop(&waitMs)) {
// }
//}
//else {
FFL::sp<HttpApiLoginHandelr> handler = new HttpApiLoginHandelr();
FFL::HttpServer httpServer("127.0.0.1", 5000);
//
// 上传日志接口
//
FFL::HttpServer::HttpApiKey key;
key.mPath = "/fflog";
httpServer.registerApi(key,handler);
//
// 下载日志接口
//
FFL::sp<HttGetLogListHandelr> getListHandler = new HttGetLogListHandelr();
key.mPath = "/FFLv2";
key.mQuery = "getLogList";
httpServer.registerApi(key, getListHandler);
httpServer.start(new FFL::ModuleThread("httpd"));
//
// 启动命令行
//
FFL_consoleEvenLoop(myCmdOption, &httpServer, QuitFlag);
return 0;
}
#include <FFL_lib.h>
extern int FFL_main();
extern "C" int main(int argc ,const char* argv[]) {
FFL_LogSetLevel(FFL_LOG_LEVEL_ALL);
FFL_main();
FFL_dumpMemoryLeak();
printf("press any key to quit");
getchar();
return 0;
}
#include <FFL_Lib.h>
class LeakObject {
public:
LeakObject() {
mId = 0;
}
int mId;
};
static void testLeak2() {
FFL_mallocz(10);
}
static void testLeak() {
new LeakObject();
testLeak2();
}
//
// 编译FFL库的时候需要打开宏
// FFL_config.h
// #define CHECK_FOR_MEMORY_LEAKS 1
//
int FFL_main() {
char exePath[1024] = {};
char exeName[1024] = {};
FFL_getCurrentProcessPath(exePath, 1023, exeName);
FFL::String path(exePath);
//path = exePath;
path += "memoryLeank.log";
if (0) {
//
// 需要需要检测,则开启这个函数,当有上次标记的泄漏的时候会触发assert中断
//
FFL_checkMemoryLeak(path.string());
}
testLeak();
FFL_dumpMemoryLeakFile(path.string());
return 0;
}
#include <FFL_Netlib.hpp>
#include <net/websocket/FFL_WebSocketClient.hpp>
class ClientReader : public FFL::NetEventLoop::Callback {
public:
//
// 返回是否还继续读写
// priv:透传数据
//
virtual bool onNetEvent(NetFD fd, bool readable, bool writeable, bool exception, void* priv) {
uint8_t buffer[1024] = {};
uint32_t size = 1024;
if (mClient->recvFrame(buffer, &size)) {
printf("recv: %s", buffer);
return true;
}
return false;
}
FFL::sp<FFL::WebSocketClient> mClient;
};
int FFL_main() {
char exePath[1024] = {};
char exeName[1024] = {};
FFL_getCurrentProcessPath(exePath, 1023, exeName);
FFL_socketInit();
FFL::sp<FFL::WebSocketClient> client=new FFL::WebSocketClient();
if (!client->connect("127.0.0.1", 8800)) {
printf("connect failed");
return 0;
}
if (!client->handshark("/")) {
printf("handshark failed");
return 0;
}
ClientReader reader;
reader.mClient = client;
FFL::NetEventLoop eventLoop(5000);
eventLoop.addFd(client->getFd(),&reader,NULL,NULL);
eventLoop.start(new FFL::ModuleThread("readThread"));
while (1) {
char ch = getchar();
if (ch == 10 || ch == 13) {
continue;
}
if (ch == 'q') {
eventLoop.stop();
break;
}
if (ch == 'a') {
client->sendText("12234565");
}
}
FFL_sleep(1000);
return 0;
}
#include <FFL_Netlib.hpp>
#include <net/websocket/FFL_WebSocketServer.hpp>
static void myExit(const char* args, void* userdata) {
printf("cmd:myExit\n");
FFL::ConsoleLoop* console =(FFL::ConsoleLoop*) userdata;
FFL::WebSocketServer* webServer=(FFL::WebSocketServer*)console->getUserdata();
webServer->stop();
console->stop();
}
static CmdOption myCmdOption[] = {
{ "exit",0,myExit,"exit process" },
{ "quit",0,myExit,"exit process" },
{ 0,0,0,0 }
};
int FFL_main() {
FFL_socketInit();
FFL::WebSocketServer webServer("127.0.0.1",8800,NULL);
webServer.start(new FFL::ModuleThread("websocket"));
FFL::ConsoleLoop console;
console.setUserdata(&webServer);
console.registeCommand(myCmdOption, 2);
console.start(NULL);
console.dumpUsage();
console.eventLoop(NULL);
return 0;
}
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Assert
* Created by zhufeifei(34008081@qq.com) on 2017/7/12.
* https://github.com/zhenfei2016/FFLv2-lib.git
*
*/
#ifndef _FFL_ASSERT_H_
#define _FFL_ASSERT_H_
#include <assert.h>
#include <FFL_Core.h>
#include <FFL_Log.h>
#ifdef __cplusplus
extern "C" {
#endif
#define FFL_ASSERT(expr) assert((expr))
#define FFL_ASSERT_LOG(expr,format,...)\
do { if (!(expr)){\
FFL_LOG_WARNING_TAG("assert","Assertion %s failed at %s:%d",FFL_TOSTRING(expr),__FILE__, __LINE__); \
abort(); \
}\
}while(0)
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Atomic.h
* Created by zhufeifei(34008081@qq.com) on 2017/7/12.
* https://github.com/zhenfei2016/FFLv2-lib.git
*
*/
#ifndef _FFL_ATOMIC_H_
#define _FFL_ATOMIC_H_
#include <FFL_Core.h>
#ifdef WIN32
#else
#define FFL_ATOMIC_STDCPP
#endif
#ifdef FFL_ATOMIC_STDCPP
typedef void* AtomicInt;
#else
typedef volatile long AtomicInt;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* 初始化 atomicVal 值为 initValue,
*/
void FFL_atomicInit(AtomicInt* atomicVal, int initValue);
/*
* 反初始化 atomicVal,调用以后这个值就不要再使用了
*/
void FFL_atomicUninit(AtomicInt* atomicVal);
/*
* 自增
*/
int FFL_atomicInc(AtomicInt* dest);
/*
* 自减
*/
int FFL_atomicDec(AtomicInt* dest);
/*
* 增加那么多
*/
int FFL_atomicAdd(AtomicInt* dest, int add);
/*
* cmp与*dest比较如果相同则把exchange赋值给dest
* 返回0表示成功
*/
int FFL_atomicCmpxchg(AtomicInt *dest, int cmp, int exchange);
/*
* 设置新的数值
*/
void FFL_atomicSet(AtomicInt* atomicVal, int value);
/*
* 比较 atomicval更一个整形的值 ,
* 返回0:表示不成功
* 1: 成功
*/
int FFL_atomicValueEqual(AtomicInt* atomicVal, int value);
/*
* 获取这个atomic变量的整形值
*/
int FFL_atomicValueGet(const AtomicInt* atomicVal);
/*
* 获取这个atomic变量与 value 的and值的整形值
* (*atomicVal & value)
*/
int FFL_atomicValueAnd(const AtomicInt* atomicVal, int value);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_BlockList.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/12/15
* https://github.com/zhenfei2016/FFL-v2.git
*
* 一个锁同步的List,方便多线程操作列表
* typedef struct Data {
* } Data;
*
* BlockingList<Data*> dataList;
* dataList.start();
*
* thread1Loop(){
* dataList.incoming(data);
* }
* thread2Loop(){
* data=dataList.next();
* }
*
*
*/
#ifndef _FFL_BLOCKING_LIST_HPP_
#define _FFL_BLOCKING_LIST_HPP_
#include <list>
#include <FFL_Mutex.hpp>
#include <FFL_Ref.hpp>
#include <FFL_String.hpp>
namespace FFL {
template < class T >
class BlockingList {
typename std::list<T>::iterator ListIt;
public:
BlockingList(const char* name) :mIsStarted(false), mMaxSize(0) {
}
//
// name:list的名称,
// maxSize : 最多保存几个元素
//
BlockingList(const char* name, uint32_t maxSize) :mIsStarted(false), mMaxSize(maxSize) {
}
~BlockingList() {
clear();
stop();
}
public:
//
// 启动,停止多线程的list
//
void start() {
FFL::CMutex::Autolock l(mMutex);
mIsStarted = true;
}
void stop() {
FFL::CMutex::Autolock l(mMutex);
if (mIsStarted) {
mIsStarted = false;
mCond.signal();
}
}
//
// 插入一条数据
//
bool incoming(T& element) {
FFL::CMutex::Autolock l(mMutex);
if (!mIsStarted) {
//FFL_LOG_WARNING("BlockingList(%s) not start. incoming",mName.string());
return false;
}
//
// 等待缓冲区少一点
//
size_t size = 0;
while (mMaxSize > 0 && mIsStarted) {
size = mDataList.size();
if (size >= mMaxSize) {
//FFL_LOG_DEBUG("BlockingList(%s) full. incoming element maxSize=%u ,size=%u ",
// mName.string(), mMaxSize, mDataList.size());
mCond.wait(mMutex);
}
else {
break;
}
}
if (!mIsStarted) {
return false;
}
//
// 添加数据
//
bool sign = (size == 0);
mDataList.push_back(element);
if (sign) {
mCond.signal();
}
return true;
}
//
// 获取最先插入的数据,没有数据则等待,一直到插入或者stop
// errNo:如果设置了就返回错误码,正常为0
//
T next(int32_t* errNo) {
T elm;
FFL::CMutex::Autolock l(mMutex);
while (true && mIsStarted) {
if (mDataList.size() > 0) {
elm = mDataList.front();
mDataList.pop_front();
return elm;
}
//FFL_LOG_DEBUG("BlockingList(%s) is empty.", mName.string());
mCond.wait(mMutex);
}
if (*errNo) {
*errNo = -1;
}
return elm;
}
//
// 清空数据list
//
void clear() {
FFL::CMutex::Autolock l(mMutex);
mDataList.clear();
}
//
// 清空数据list
//
void clear(std::list< T >& tmp) {
FFL::CMutex::Autolock l(mMutex);
typename std::list<T> it = mDataList.begin();
for (; it != mDataList.end(); it++) {
tmp.push_back(*it);
}
mDataList.clear();
}
//
// 获取数据大小
//
uint32_t getSize() {
FFL::CMutex::Autolock l(mMutex);
return mDataList.size();
}
private:
FFL::CMutex mMutex;
volatile bool mIsStarted;
uint32_t mMaxSize;
FFL::CCondition mCond;
std::list< T > mDataList;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_ByteBuffer
* Created by zhufeifei(34008081@qq.com) on 2018/05/06
* https://github.com/zhenfei2016/FFLv2-lib.git
* 内存管理类
*
*/
#ifndef _FFL_BYTE_BUFFER_HPP_
#define _FFL_BYTE_BUFFER_HPP_
#include <FFL_Core.h>
namespace FFL{
class ByteStream;
class FFLIB_API_IMPORT_EXPORT ByteBuffer {
public:
ByteBuffer();
ByteBuffer(uint32_t size);
ByteBuffer(const uint8_t* data,uint32_t size);
~ByteBuffer();
//
// 重新申请一下空间
//
uint32_t alloc(uint32_t size);
//
// 扩大一下内存空间,如果size小于已经申请的则返回以前的大小
//
uint32_t realloc(uint32_t size);
//
// buffer指针
//
uint8_t* data() const;
//
// buffer大小
//
uint32_t size() const;
private:
uint8_t* mData;
uint32_t mSize;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_ByteReader
* Created by zhufeifei(34008081@qq.com) on 2018/05/01
* https://github.com/zhenfei2016/FFLv2-lib.git
* 字节流读接口
*/
#ifndef _FFL_BYTE_READER_HPP_
#define _FFL_BYTE_READER_HPP_
#include <FFL_Core.h>
#include <FFL_String.hpp>
namespace FFL{
class ByteReader {
public:
//
// 字节流读接口
//
virtual int8_t read1Bytes(bool* suc )=0;
virtual int16_t read2Bytes(bool* suc) = 0;
virtual int32_t read3Bytes(bool* suc) = 0;
virtual int32_t read4Bytes(bool* suc) = 0;
virtual int64_t read8Bytes(bool* suc) = 0;
virtual bool readString(String& val, uint32_t len) = 0;
virtual bool readBytes(int8_t* data, uint32_t size) = 0;
//
// 跳过多少个字节
//
virtual void skipRead(int32_t step) = 0;
//
// 是否还有这么多可以读的数据
//
virtual bool haveData(uint32_t size) = 0;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_ByteStream
* Created by zhufeifei(34008081@qq.com) on 2018/05/1
* https://github.com/zhenfei2016/FFLv2-lib.git
* 字节流操作,读写
*/
#ifndef _FFL_BYTE_STREAM_HPP_
#define _FFL_BYTE_STREAM_HPP_
#include <FFL_Core.h>
#include <FFL_ByteReader.hpp>
#include <FFL_ByteWriter.hpp>
namespace FFL{
class FFLIB_API_IMPORT_EXPORT ByteStreamBase {
public:
ByteStreamBase();
virtual ~ByteStreamBase();
//
// 原始指针,指针指向的缓冲容量
//
inline uint8_t* getData() const { return mData; }
//
// 缓存容量
//
inline uint32_t getCapacity() const { return mDataCapacity; }
//
// 缓存中当前的有效数据
//
inline uint32_t getSize() const { return mDataSize; }
public:
//
// 设置数据,bytestream将在这个数据集上进行操作
// data :缓冲起始位置,在这个指针位置开始读写的,内部不会拷贝数据的
// validSize: 缓冲中当前有效数据大小,可以进行读的数据,也就是写指针当前的位置
// capacity:缓冲容量
// memEndian:默认本系统字节序
//
virtual void setData(uint8_t* data, uint32_t validSize, uint32_t capacity);
virtual void setData(uint8_t* data, uint32_t validSize, uint32_t capacity, int memEndian);
protected:
//
// 是否buffer指向的数据跟系统的字节序一致
//
bool isSameEndian();
protected:
//
// 数据内存
//
uint8_t* mData;
uint32_t mDataCapacity;
uint32_t mDataSize;
//
// 当前mData存储的数据字节序
//
uint32_t mMemEndian;
};
//
// 可以进行读写的字节流
//
class FFLIB_API_IMPORT_EXPORT ByteStream :public ByteStreamBase ,public ByteWriter,public ByteReader {
public:
ByteStream();
~ByteStream();
//
// 重置读写指针
//
void reset();
//
// ByteReader 读
//
int8_t read1Bytes(bool* suc = NULL);
int16_t read2Bytes(bool* suc = NULL);
int32_t read3Bytes(bool* suc = NULL);
int32_t read4Bytes(bool* suc = NULL);
int64_t read8Bytes(bool* suc = NULL);
bool readString(String& val, uint32_t len);
bool readBytes(int8_t* val, uint32_t size);
//
// 跳过多少个字节
//
void skipRead(int32_t step);
//
// 是否还有这么多可以读的数据
//
bool haveData(uint32_t size);
//
// ByteWriter 写
//
bool write1Bytes(int8_t val);
bool write2Bytes(int16_t val);
bool write3Bytes(int32_t val);
bool write4Bytes(int32_t val);
bool write8Bytes(int64_t val);
bool writeString(const String& val, uint32_t len);
bool writeString(const char* val, uint32_t len);
bool writeBytes(const int8_t* val, uint32_t size);
//
// 跳过多少个空位置
//
void skipWrite(int32_t step);
//
// 是否还有这么多空间可以使用
//
bool haveSpace(uint32_t size);
protected:
//
// 读写指定的字节
//
void readBuffer(uint8_t* dst, uint32_t size, bool reversal);
void writeBuffer(uint8_t* dst, uint32_t size, bool reversal);
private:
//
// 读写位置
//
uint32_t mReadPos;
uint32_t mWritePos;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_ByteWriter
* Created by zhufeifei(34008081@qq.com) on 2018/05/01
* https://github.com/zhenfei2016/FFLv2-lib.git
*
字节流写接口
*
*/
#ifndef _FFL_BYTE_WRITER_HPP_
#define _FFL_BYTE_WRITER_HPP_
#include <FFL_Core.h>
#include <FFL_String.hpp>
namespace FFL{
class ByteWriter {
public:
//
// 字节流写接口
//
virtual bool write1Bytes(int8_t val)=0;
virtual bool write2Bytes(int16_t val) = 0;
virtual bool write3Bytes(int32_t val) = 0;
virtual bool write4Bytes(int32_t val) = 0;
virtual bool write8Bytes(int64_t val) = 0;
virtual bool writeString(const String& val, uint32_t len) = 0;
virtual bool writeString(const char* val, uint32_t len) = 0;
virtual bool writeBytes(const int8_t* data, uint32_t size) = 0;
//
// 写的时候跳过几个字节
//
virtual void skipWrite(int32_t step) = 0;
//
// 是否还有这么多空间可以使用
//
virtual bool haveSpace(uint32_t size) = 0;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Config
* Created by zhufeifei(34008081@qq.com) on 2017/07/10
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 编译前生成的配置文件 ,不依赖其他文件的,
*/
#ifndef _FFL_CONFIG_H_
#define _FFL_CONFIG_H_
#define FFLIB_API_IMPORT
#define FFLIB_API_EXPORT
//
// 如果脚本定义了编译动态库
#if defined(FFL_EXPORTS)
#define FFLIB_API_IMPORT_EXPORT FFLIB_API_EXPORT
#else
#define FFLIB_API_IMPORT_EXPORT FFLIB_API_IMPORT
#endif
/*
* 是否检测内存泄露
*/
#define CHECK_FOR_MEMORY_LEAKS 0
/* 线程相关 */
//#define FFL_THREAD_WINDOWS 0
#define FFL_THREAD_WINDOWS 0
//#define FFL_THREAD_STDCPP 0
#define FFL_THREAD_STDCPP 0
//#define FFL_THREAD_PTHREAD 0
#define FFL_THREAD_PTHREAD 1
#if FFL_THREAD_PTHREAD
#define HAVE_PTHREADS 1
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Config
* Created by zhufeifei(34008081@qq.com) on 2017/07/10
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 编译前生成的配置文件 ,不依赖其他文件的,
*/
#ifndef _FFL_CONFIG_H_
#define _FFL_CONFIG_H_
#define FFLIB_API_IMPORT ${FFLIB_IMPORT}
#define FFLIB_API_EXPORT ${FFLIB_EXPORT}
//
// 如果脚本定义了编译动态库
#if defined(FFL_EXPORTS)
#define FFLIB_API_IMPORT_EXPORT FFLIB_API_EXPORT
#else
#define FFLIB_API_IMPORT_EXPORT FFLIB_API_IMPORT
#endif
/*
* 是否检测内存泄露
*/
#define CHECK_FOR_MEMORY_LEAKS 0
/* 线程相关 */
//#define FFL_THREAD_WINDOWS 0
${HAVE_THREAD_WIN}
//#define FFL_THREAD_STDCPP 0
${HAVE_THREAD_STDCPP}
//#define FFL_THREAD_PTHREAD 0
${HAVE_THREAD_PTHREAD}
#if FFL_THREAD_PTHREAD
#define HAVE_PTHREADS 1
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Console.h
* Created by zhufeifei(34008081@qq.com) on 2018/07/21
* https://github.com/zhenfei2016/FFL-v2.git
* 命令行处理的帮助类
*
* static void play(const char* args, void* userdata) {
* }
*
*
* static void stop(const char* args, void* userdata) {
* }
* static CmdOption myCmdOption[] = {
* { "play",0,play,"play video " },
* { "stop",0,stop,"stop video " },
* { 0,0,0,0 }
* };
*
* int QuitFlag(void* userdata){
* return 0;
* }
*
* main(){
* FFL_inputLooper(myCmdOption,0,QuitFlag);
* }
*
*
*/
#ifndef _FFL_COMMANDHELPER_H_
#define _FFL_COMMANDHELPER_H_
#include <FFL_Core.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* 命令行参数选项
*/
typedef struct CmdOption {
/*
* 命令名称
*/
const char* mName;
/*
* 是否存在参数 0 , 1
*/
int32_t mHaveAargument;
/*
* 这个命令需要执行的函数
*/
void(*fun)(const char* value, void* userdata);
/*
* 帮助信息
*/
const char* nHelp;
}CmdOption;
/*
* 分析命令行
* argc:参数个数
* argv:参数数组
* opts:支持的命令数组,以null结尾
* size:opts数组的大少
* userdata: 透传到CmdOption中的函数回调中
* 命令行格式 --cmd=12344
* 返回命令在opts中的位置,没找到返回-1
*/
FFLIB_API_IMPORT_EXPORT int FFL_parseCommnadline(int argc, const char** argv, CmdOption* opts, int size, void* userdata);
/*
* fnQuitFlag 返回非0则退出循环
*/
FFLIB_API_IMPORT_EXPORT void FFL_consoleEvenLoop(CmdOption* opts, void* userdata,
int(*fnQuitFlag)(void* userdata) );
/*
* 打印帮助
*/
FFLIB_API_IMPORT_EXPORT void FFL_printUsage(CmdOption* opts );
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Console.hpp
* Created by zhufeifei(34008081@qq.com) on 2019/03/11
* https://github.com/zhenfei2016/FFL-v2.git
* 命令行处理的帮助类
*
*/
#ifndef _FFL_CONSOLE_HPP_
#define _FFL_CONSOLE_HPP_
#include <FFL_Console.h>
#include <FFL_Module.hpp>
namespace FFL {
class FFLIB_API_IMPORT_EXPORT ConsoleLoop : public Module {
public:
ConsoleLoop();
virtual ~ConsoleLoop();
//
// 注册处理命令,必须在start前进行注册的
// cmdTable:命令数组
// size :命令个数
// 最多支持100个命令
//
bool registeCommand(CmdOption* cmdTable,uint32_t size);
//
// 打印用法
//
void dumpUsage();
//
// 用于透传的用户数据
//
void setUserdata(void* userdata);
void* getUserdata() const;
public:
//
// 阻塞的线程中执行的eventloop,返回是否继续进行eventLoop
// waitTime:输出参数,下一次执行eventLoop等待的时长
// true : 继续进行下一次的eventLoop
// false : 不需要继续执行eventloop
//
virtual bool eventLoop(int32_t* waitTime);
private:
CmdOption* mRegistedCommand;
void* mUserData;
};
}
#endif
\ No newline at end of file
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Core
* Created by zhufeifei(34008081@qq.com) on 2017/07/10
* https://github.com/zhenfei2016/FFLv2-lib.git
*
*
*/
#ifndef _FFL_CORE_H_
#define _FFL_CORE_H_
/* 字符串操作 */
#include <string.h>
#include <FFL_Config.h>
#include <FFL_Platform.h>
#include <FFL_Stdint.h>
#include <FFL_Error.h>
#include <FFL_Assert.h>
#include <FFL_Memory.h>
#include <FFL_String.h>
#include <FFL_Time.h>
#include <FFL_Log.h>
#include <FFL_LogConfig.h>
/*
* 函数调用方式
*/
#ifndef FFL_CALL
#if (defined(WIN32))
#define FFL_CALL __cdecl
#elif (defined(MACOSX))
#define FFL_CALL
#else
#define FFL_CALL
#endif
#endif
/*
* 内联函数
*/
#define FFL_INLINE
/* 最大值 */
#ifndef FFL_MAX
#define FFL_MAX(a, b) ((a) > (b) ? (a) : (b))
#endif
/* 最小值 */
#ifndef FFL_MIN
#define FFL_MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/* align字节对齐 */
#ifndef FFL_ALIGN
#define FFL_ALIGN(x, align) ((( x ) + (align) - 1) / (align) * (align))
#endif
/* 数组元素个数 */
#ifndef FFL_ARRAY_ELEMS
#define FFL_ARRAY_ELEMS(x) ((int) (sizeof(x) / sizeof((x)[0])))
#endif
/* 交换2个数值 */
#ifndef FFL_SWAP
#define FFL_SWAP(type,a,b) do{type tmp= b; b= a; a= tmp;}while(0)
#endif
/*
* 转换到字符串类型
*/
#ifndef FFL_TOSTRING
#define FFL_TOSTRING(s) #s
#endif
#ifndef FFL_INT32_HIGHT_16
#define FFL_INT32_HIGHT_16(a) ((((int)(a))>>16) & 0xFFFF)
#endif
#ifndef FFL_INT32_LOW_16
#define FFL_INT32_LOW_16(a) ((((int)(a))) & 0xFFFF)
#endif
#ifndef FFL_MAKE_INT32
#define FFL_MAKE_INT32(high,low) (((low)& 0xFFFF) | (((high)& 0xFFFF)<<16))
#endif
#ifndef FFL_INT64_HIGHT_32
#define FFL_INT64_HIGHT_32(a) ((int32_t)( ((a) >> 32) & 0xFFFFFFFF))
#endif
#ifndef FFL_INT64_LOW_32
#define FFL_INT64_LOW_32(a) ((int32_t)( (a) & 0xFFFFFFFF ))
#endif
#ifndef FFL_MAKE_INT64
#define FFL_MAKE_INT64(high,low) (((int64_t)(low)& 0xFFFFFFFF) | (((int64_t)(high)& 0xFFFFFFFF)<<32))
#endif
/*
*打印64位整形
* print("hi%"lld64, 123445 );
*/
#if defined(WIN32)
#define lld64 "I64d"
#else
#define lld64 "lld"
#endif
/*
* socket句柄
*/
typedef int NetFD;
#define INVALID_NetFD 0
#ifdef __cplusplus
extern "C"{
#endif
/*
* 初始化函数
*
* */
FFLIB_API_IMPORT_EXPORT void FFL_CALL FFL_initialize();
/*
* 结束FFL库的使用,调用后就不要再使用FFL的函数了
*
* */
FFLIB_API_IMPORT_EXPORT void FFL_CALL FFL_terminate();
#ifdef __cplusplus
}
#endif
#endif
#ifdef __cplusplus
#ifndef _FFL_CORE_HPP_
#define _FFL_CORE_HPP_
#include <FFL_Utils.hpp>
#endif
#endif
\ No newline at end of file
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Dictionary.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/06/24
* https://github.com/zhenfei2016/FFLv2-lib.git
*
*
*/
#ifndef _FFL_DICTIONARY_HPP_
#define _FFL_DICTIONARY_HPP_
#include <FFL_String.hpp>
#include <map>
namespace FFL {
class DictionaryImpl;
class FFLIB_API_IMPORT_EXPORT Dictionary {
public:
Dictionary();
~Dictionary();
//
// 写一条key/value
//
void setKey(const String& key, const String& value);
void setKey(const char* key, const char* value);
//
// 移除一条
//
bool removeKey(const char* key);
//
// 通过key获取值,返回是否找到了这个key
//
bool getKey(const String& key, String& value);
bool getKey(const char* key, String& value);
//
// 获取多小组数据
int32_t getCount();
//
//获取数据到数组中
struct Pair {
String key;
String value;
};
bool getAll(Pair* pairArray,int32_t* bufSize);
//
// 设置获取值
void setKeyInt64(const String& key,int64_t value);
void setKeyInt64(const char* key,int64_t value);
bool getKeyInt64(const String& key, int64_t& value,int64_t def);
bool getKeyInt64(const char* key, int64_t& value, int64_t def);
void setKeyInt32(const String& key, int32_t value);
void setKeyInt32(const char* key, int32_t value);
bool getKeyInt32(const String& key, int32_t& value, int32_t def);
bool getKeyInt32(const char* key, int32_t& value, int32_t def);
Dictionary(const Dictionary & r);
Dictionary &operator=(const Dictionary & r);
private:
mutable DictionaryImpl* mImpl;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Error
* Created by zhufeifei(34008081@qq.com) on 2017/07/12
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 错误,返回返回值定义
*/
#ifndef _FFL_ERROR_H_
#define _FFL_ERROR_H_
#include <FFL_Config.h>
#include <FFL_Stdint.h>
typedef enum ERROR_NO
{
/* 返回成功 */
FFL_OK = 0,
FFL_NO_ERROR = FFL_OK,
FFL_ERROR_SUCCESS = FFL_OK,
/* 无效参数 */
ERROR_INVALID_PARAMS = -1,
/* 发生错误了 */
FFL_ERROR_FAIL = -1,
FFL_ERROR_FAILED = -1,
FFL_FAILED = -1,
/*
* 无效操作
*/
FFL_INVALID_OPERATION = -2,
FFL_INVALID_PARAMS = -3,
/*
* 没实现
*/
FFL_NOT_IMPLEMENT = -4,
/*
* 函数执行错误,不能block
*/
FFL_WOULD_BLOCK = -5,
/*
* 未初始化
*/
FFL_NOT_INITIALIZE = -6,
FFL_ERROR_EOF = -200,
/* 超时 */
ERROR_TIME_OUT = -100,
FFL_MUTEX_TIMEDOUT = -100,
FFL_MUTEX_MAXWAIT = ~0,
/* pipeline 已经填充了一个buffer */
PIPELINE_FILL_BUFFER = 1000,
/*
* 跳过这个buffer
* */
PIPELINE_SKIP_BUFFER,
/*
* 文件已经打开了
*/
FFL_FILE_ALREADY_OPENED,
/*
* 文件打开失败了
*/
FFL_FILE_OPEN_FAILED,
FFL_FILE_CLOSE_FAILED,
FFL_FILE_WRITE_FAILED,
FFL_FILE_READ_FAILED,
}ERROR_NO;
/*
* 函数返回值,表示函数的执行状态
*/
typedef int status_t;
#ifdef __cplusplus
extern "C" {
#endif
/* 设置获取错误 */
int FFL_set_error(const char* format, ...);
const char* FFL_get_error();
int FFL_set_error_no(int errorno, const char* s);
const int FFL_get_error_no();
FFLIB_API_IMPORT_EXPORT int FFL_outofmemory();
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_File.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/06/20
* https://github.com/zhenfei2016/FFLv2-lib.git
* 文件操作类
*
*/
#ifndef _FFL_FILE_HPP_
#define _FFL_FILE_HPP_
#include "FFL_Io.hpp"
#include "FFL_String.hpp"
namespace FFL {
class FFLIB_API_IMPORT_EXPORT File : public IOReader ,public IOWriter {
public:
File();
virtual ~File();
public:
//
// 打开文件,FFL_OK成功
// path:文件绝对路径
//
status_t open(const String& path);
//
// 追加模式打开文件,FFL_OK成功
// path:文件绝对路径
//
status_t openAppend(const String& path);
//
// 创建文件,文件已经存在的情况下覆盖原文件
//
status_t create(const String& path);
//
// 关闭文件
//
void close();
bool isOpened() const;
//
// 文件大小
//
size_t getSize();
private:
//
// 打开文件,FFL_OK成功
// path:文件绝对路径
//
status_t open(const char* path,int mode);
public:
//
// 写数据到文件中
// buf:缓冲区地址
// count:缓冲区大小
// pWrite:实质上写了多少数据
// 返回错误码 : FFL_OK表示成功
//
virtual status_t write(const void* buf, size_t count, size_t* pWrite);
//
// 写数据到文件中
// bufVec:缓冲区地址,数组
// count:数组大小
// pWrite:实质上写了多少数据
// 返回错误码 : FFL_OK表示成功
//
virtual status_t writeVec(const BufferVec* bufVec, int count, size_t* pWrite);
//
// 读数据到缓冲区
// buf:缓冲区地址
// count:需要读的大小
// pReaded:实质上读了多少数据
// 返回错误码 : FFL_OK表示成功
//
virtual status_t read(uint8_t* buf, size_t count, size_t* pReaded);
private:
//
// 文件路径,文件句柄
//
String mPath;
void* mFd;
};
//
// 文件是否创建了
//
bool fileIsExist(const char* path);
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Flags
* Created by zhufeifei(34008081@qq.com) on 2018/03/06
* https://github.com/zhenfei2016/FFLv2-lib.git
*
标志位存取
*
*/
#ifndef _FFL_PIPELINE_FALGS_HPP_
#define _FFL_PIPELINE_FALGS_HPP_
#include <FFL_Core.h>
namespace FFL{
class Flags32b{
public:
inline Flags32b():mFlags(0)
{}
//
// add:添加的标志
// remove :移除的标志
// 注意是先添加后移除
//
uint32_t modifyFlags(uint32_t add, uint32_t remove);
//
// 是否存在一个标志
//
bool hasFlags(uint32_t flags) const;
//
// 修改状态标志
//
inline uint32_t resetFlags(uint32_t flag)
{
mFlags = flag;
return mFlags;
}
//
// 获取标志值
//
inline uint32_t getFlags() const
{
return mFlags;
};
protected:
uint32_t mFlags;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Io.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/06/20
* https://github.com/zhenfei2016/FFLv2-lib.git
* io读写接口
*
*/
#ifndef _FFL_IO_HPP_
#define _FFL_IO_HPP_
#include <FFL_Core.h>
namespace FFL {
//
// 缓冲区buffer
//
struct BufferVec {
void *data;
size_t size;
};
class IOReader {
public:
//
// 读数据到缓冲区
// buf:缓冲区地址
// count:需要读的大小
// pReaded:实质上读了多少数据
// 返回错误码 : FFL_OK表示成功
//
virtual status_t read(uint8_t* buf, size_t count, size_t* pReaded)=0;
};
class IOWriter {
public:
//
// 写数据到文件中
// buf:缓冲区地址
// count:缓冲区大小
// pWrite:实质上写了多少数据
// 返回错误码 : FFL_OK表示成功
//
virtual status_t write(const void* buf, size_t count, size_t* pWrite)=0;
//
// 写数据到文件中
// bufVec:缓冲区地址,数组
// count:数组大小
// pWrite:实质上写了多少数据
// 返回错误码 : FFL_OK表示成功
//
virtual status_t writeVec(const BufferVec* bufVec, int count, size_t* pWrite)=0;
};
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Log
* Created by zhufeifei(34008081@qq.com) on 2017/7/12
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 打印日志帮助类,
* 增加支持的编译日志等级 2017/12/22
* FFLIB_COMPILE_LOG_LEVEL = 3 对应FFL_LogLevel的值
*
*/
#ifndef __FFL_LOG_H__
#define __FFL_LOG_H__
#include <stdio.h>
#include <stdarg.h>
#include <FFL_Config.h>
#ifdef __cplusplus
extern "C" {
#endif
/************************************************************************
* 支持的日志等级
***********************************************************************/
typedef enum
{
FFL_LOG_LEVEL_CRIT = 0,
FFL_LOG_LEVEL_ERROR,
FFL_LOG_LEVEL_WARNING,
FFL_LOG_LEVEL_INFO,
FFL_LOG_LEVEL_DEBUG,
FFL_LOG_LEVEL_ALL
} FFL_LogLevel;
/************************************************************************
* 设置日志等级
***********************************************************************/
FFLIB_API_IMPORT_EXPORT void FFL_LogSetLevel(FFL_LogLevel level);
FFLIB_API_IMPORT_EXPORT FFL_LogLevel FFL_LogGetLevel();
FFLIB_API_IMPORT_EXPORT const char* FFL_LogGetLevelString(int level);
/************************************************************************
* 设置日志输出到哪里去,外部接管,还是指定文件中
***********************************************************************/
/*
* 接管日志输出函数
* 根据返回值表示是否需要继续默认的日志输出
* 1 : 已经把日志处理了,不需要默认日志系统了
* 0 : 用默认日志处理函数
* userdata :透传数据
*/
typedef int (*FFL_LogHookFun)(int level,const char* tag,const char *format, va_list args,void* userdata);
FFLIB_API_IMPORT_EXPORT void FFL_LogHook(FFL_LogHookFun callback, void* userdata);
/************************************************************************
通用输出,特定等级输出,特定等级并且带tag的输出
返回0表示成功
默认的情况下一条日志的最大长度为4k
************************************************************************/
FFLIB_API_IMPORT_EXPORT int FFL_LogPrint(int level, const char *format, ...);
FFLIB_API_IMPORT_EXPORT int FFL_LogPrintTag(int level, const char *tag, const char *format, ...);
FFLIB_API_IMPORT_EXPORT int FFL_LogPrintV(int level, const char *format, va_list args);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_LogConfig.h
* Created by zhufeifei(34008081@qq.com) on 2019/1/4
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* cmake生成的日志宏
*
*/
#ifndef __FFL_LOG_CONFIG_H__
#define __FFL_LOG_CONFIG_H__
#define FFL_LOG_CRIT(format,...) FFL_LogPrint(FFL_LOG_LEVEL_CRIT,format,##__VA_ARGS__)
#define FFL_LOG_CRIT_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_CRIT,tag,format,##__VA_ARGS__)
#define FFL_LOG_ERROR(format,...) FFL_LogPrint(FFL_LOG_LEVEL_ERROR,format,##__VA_ARGS__)
#define FFL_LOG_ERROR_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_ERROR,tag,format,##__VA_ARGS__)
#define FFL_LOG_WARNING(format,...) FFL_LogPrint(FFL_LOG_LEVEL_WARNING,format,##__VA_ARGS__)
#define FFL_LOG_WARNING_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_WARNING,tag,format,##__VA_ARGS__)
#define FFL_LOG_INFO(format,...) FFL_LogPrint(FFL_LOG_LEVEL_INFO,format,##__VA_ARGS__)
#define FFL_LOG_INFO_TAG(tag,format,...) FFL_LogPrintTag(FFL_LOG_LEVEL_INFO,tag,format,##__VA_ARGS__)
#define FFL_LOG_DEBUG(format,...)
#define FFL_LOG_DEBUG_TAG(tag,format,...)
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_LogConfig.h
* Created by zhufeifei(34008081@qq.com) on 2019/1/4
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* cmake生成的日志宏
*
*/
#ifndef __FFL_LOG_CONFIG_H__
#define __FFL_LOG_CONFIG_H__
${FFL_LOG_CRIT}
${FFL_LOG_ERROR}
${FFL_LOG_WARING}
${FFL_LOG_INFO}
${FFL_LOG_DEBUG}
#endif
#ifndef _FFL_MAP_HPP_
#define _FFL_MAP_HPP_
namespace FFL {
}
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Memory
* Created by zhufeifei(34008081@qq.com) on 2017/7/12.
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 内存的申请,释放,大小端控制 , 内存泄漏检测
*/
#ifndef _FFL_MEMORY_H_
#define _FFL_MEMORY_H_
#include <stdlib.h>
#include <memory.h>
#include <FFL_Config.h>
#include <FFL_Stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* 内存申请,释放
*/
FFLIB_API_IMPORT_EXPORT void* FFL_malloc(size_t size);
FFLIB_API_IMPORT_EXPORT void FFL_free(void *mem);
/*
* 申请内存并且清零
*/
FFLIB_API_IMPORT_EXPORT void* FFL_mallocz(size_t size);
#define FFL_freep(pp) while(pp&&*pp){ FFL_free(*pp); *pp = 0; break;}
/*
* memory清零
*/
#define FFL_Zerop(x) do{memset((x), 0, sizeof(*(x)));} while(0)
#define FFL_ZeroArray(x,c) do{memset((x), 0, (sizeof(*(x))*(c)));} while(0)
/*
* 内存字节序
*大端模式,数据的低位保存在内存的高地址中
* 网络字节序
*/
#define FFL_BIG_ENDIAN 1
/*
*小端模式,数据的低位保存在内存的低地址中
*/
#define FFL_LITTLE_ENDIAN 2
/*
* 检测系统的大小端
*/
FFLIB_API_IMPORT_EXPORT int FFL_isLittleEndian();
/*
order: 1:顺序的,0:还是反序的 拷贝数据
*/
FFLIB_API_IMPORT_EXPORT void FFL_copyBytes(uint8_t* s, uint8_t* d, uint32_t size, int order);
/************************memoryleak相关*********************************************************************/
/*
* 打印一下当前还没有释放的内存
*/
FFLIB_API_IMPORT_EXPORT void FFL_dumpMemoryLeak();
/*
* 打印当前未释放的内存,到文件中
*/
FFLIB_API_IMPORT_EXPORT void FFL_dumpMemoryLeakFile(const char* path);
/*
* 参考上一次释放的内存文件,打印对应的堆栈
*/
FFLIB_API_IMPORT_EXPORT void FFL_checkMemoryLeak(const char* path);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Module.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/04/29
* https://github.com/zhenfei2016/FFLv2-lib.git
*
*/
#ifndef _FFL_MODULE_HPP_
#define _FFL_MODULE_HPP_
#include <FFL_Mutex.hpp>
#include <FFL_Thread.hpp>
namespace FFL {
class Module;
////////////////////////////////////////////////////////////////////////////////////////////////////
// 跑module循环的线程
////////////////////////////////////////////////////////////////////////////////////////////////////
class FFLIB_API_IMPORT_EXPORT ModuleThread :public RefBase{
friend class Module;
public:
ModuleThread(const char* name);
~ModuleThread();
//
// 设置关联到哪一个module上
//
void setModule(Module* module);
//
// 获取线程名称
//
const char* getName() const;
//
// 启动,停止线程
//
virtual status_t run();
virtual void requestExit();
virtual status_t requestExitAndWait();
protected:
virtual bool threadLoop();
private:
const char* mName;
Module* mModule;
int32_t mModuleWaitMs;
CMutex mMutex;
CCondition mCond;
class ThreadImpl;
friend class ThreadImpl;
FFL::sp<Thread> mThread;
};
template class FFLIB_API_IMPORT_EXPORT FFL::sp<FFL::ModuleThread>;
////////////////////////////////////////////////////////////////////////////////////////////////////////
class FFLIB_API_IMPORT_EXPORT Module {
public:
public:
Module();
virtual ~Module();
//
// 启动,
// thread: 使用使用这个线程进行eventloop
// =NULL , 需要外部调用eventLoop
// !=NULL , 在这个thread中执行eventloop
// 返回是否启动成功
//
bool start(FFL::sp<ModuleThread> thread) ;
//
// 如果start使用了EventloopThread,则stop会阻塞到线程退出
// 如果在自己线程中等待退出则不会阻塞的
// 否则则仅仅置一下标志
// 如果在自己线程中调用了stop,则返回false,可以在其他线程调用waitStop
//
bool stop() ;
//
// 等待线程退出
//
void waitStop();
public:
//
// 调用。start,stop会触发onStart,onStop的执行
// onStart :表示准备开始了 ,可以做一些初始化工作
// onStop :表示准备停止了 ,可以做停止前的准备,想置一下信号让eventloop别卡住啊
// 在这些函数中,不要再调用自己的函数,例如:start,stop, isStarted等
//
virtual bool onStart();
virtual void onStop();
//
// 阻塞的线程中执行的eventloop,返回是否继续进行eventLoop
// waitTime:输出参数,下一次执行eventLoop等待的时长
// true : 继续进行下一次的eventLoop
// false : 不需要继续执行eventloop
//
virtual bool eventLoop(int32_t* waitTime) = 0;
//
// 是否启动状态
//
bool isStarted() const;
protected:
volatile bool mStarted;
mutable CMutex mLock;
FFL::sp<ModuleThread> mModuleThread;
};
}
#endif
/*
* FFL_mutex.h
* FFL
*
* Created by zhufeifei on 2017/8/12.
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
* 基于sdl库代码修改的
*/
#ifndef _FFL_MUTEX_H_
#define _FFL_MUTEX_H_
#include <FFL_Core.h>
#ifdef __cplusplus
extern "C" {
#endif
struct FFL_semaphore_sys;
typedef struct FFL_semaphore_sys FFL_sem;
FFLIB_API_IMPORT_EXPORT FFL_sem *FFL_CALL FFL_CreateSemaphore(uint32_t initial_value);
FFLIB_API_IMPORT_EXPORT void FFL_CALL FFL_DestroySemaphore(FFL_sem * sem);
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_SemWait(FFL_sem * sem);
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_SemTryWait(FFL_sem * sem);
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_SemWaitTimeout(FFL_sem * sem, uint32_t ms);
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_SemPost(FFL_sem * sem);
FFLIB_API_IMPORT_EXPORT int32_t FFL_CALL FFL_SemValue(FFL_sem * sem);
struct FFL_mutex_sys;
typedef struct FFL_mutex_sys FFL_mutex;
FFLIB_API_IMPORT_EXPORT FFL_mutex* FFL_CreateMutex(void);
FFLIB_API_IMPORT_EXPORT void FFL_DestroyMutex(FFL_mutex *mutex);
FFLIB_API_IMPORT_EXPORT int FFL_LockMutex(FFL_mutex *mutex);
FFLIB_API_IMPORT_EXPORT int FFL_TryLockMutex(FFL_mutex * mutex);
FFLIB_API_IMPORT_EXPORT int FFL_UnlockMutex(FFL_mutex *mutex);
struct FFL_cond_sys;
typedef struct FFL_cond_sys FFL_cond;
FFLIB_API_IMPORT_EXPORT FFL_cond *FFL_CreateCond(void);
FFLIB_API_IMPORT_EXPORT void FFL_DestroyCond(FFL_cond *cond);
FFLIB_API_IMPORT_EXPORT void FFL_DestroyCondP(FFL_cond **cond);
FFLIB_API_IMPORT_EXPORT int FFL_CondSignal(FFL_cond *cond);
FFLIB_API_IMPORT_EXPORT int FFL_CondBroadcast(FFL_cond *cond);
FFLIB_API_IMPORT_EXPORT int FFL_CondWaitTimeout(FFL_cond *cond, FFL_mutex *mutex, uint32_t ms);
FFLIB_API_IMPORT_EXPORT int FFL_CondWait(FFL_cond *cond, FFL_mutex *mutex);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Mutex
* Created by zhufeifei(34008081@qq.com) on 2017/11/25
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 锁,条件变量包装
*/
#ifndef _FFL_MUTEX_HPP_
#define _FFL_MUTEX_HPP_
#include <FFL_Core.h>
#include <FFL_Mutex.h>
namespace FFL {
class CCondition;
class FFLIB_API_IMPORT_EXPORT CMutex
{
public:
CMutex();
~CMutex();
status_t lock();
void unlock();
status_t tryLock();
public:
class Autolock
{
public:
inline Autolock(CMutex& mutex) : mLock(mutex) { mLock.lock(); }
inline Autolock(CMutex* mutex) : mLock(*mutex) { mLock.lock(); }
inline ~Autolock() { mLock.unlock(); }
private:
CMutex& mLock;
};
private:
friend class CCondition;
FFL_mutex* m_mutex;
DISABLE_COPY_CONSTRUCTORS(CMutex);
};
class FFLIB_API_IMPORT_EXPORT CCondition
{
public:
CCondition();
~CCondition();
status_t wait(CMutex& mutex);
status_t waitRelative(CMutex& mutex, uint32_t ms);
void signal();
void broadcast();
private:
FFL_cond* m_cond;
DISABLE_COPY_CONSTRUCTORS(CCondition);
};
};
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_NetLib.h
* Created by zhufeifei(34008081@qq.com) on 2018/12/08
* https://github.com/zhenfei2016/FFLv2-lib.git
* 包含网络文件 c风格
*
*/
#ifndef _FFLIB_FFLv2_NET_H_
#define _FFLIB_FFLv2_NET_H_
#include <net/FFL_Net.h>
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_NetLib.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/12/08
* https://github.com/zhenfei2016/FFLv2-lib.git
* 包含网络文件 c++风格
*
*/
#ifndef _FFLIB_FFLv2_NET_HPP_
#define _FFLIB_FFLv2_NET_HPP_
#include <FFL_lib.hpp>
#include <FFL_Netlib.h>
#include <FFL_lib.hpp>
#include <net/FFL_TcpServer.hpp>
#include <net/FFL_UdpServer.hpp>
#include <net/http/FFL_Http.hpp>
#include <net/http/FFL_HttpServer.hpp>
#include <net/http/FFL_HttpClientAccess.hpp>
#include <net/http/FFL_HttpHeader.hpp>
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Path.h
* Created by zhufeifei(34008081@qq.com) on 2018/07/25
* https://github.com/zhenfei2016/FFL-v2.git
*
* 路径相关的处理类
*/
#ifndef __FFL_PATH_H__
#define __FFL_PATH_H__
#include <FFL_Core.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* 获取当前进程的路径,名称
* processdir : 返回进程路径,必需不是空的
* len :buf的大小
* processname : 如果非空,则返回进程名称
*/
FFLIB_API_IMPORT_EXPORT status_t FFL_getCurrentProcessPath(char* processdir, size_t len, char* processname);
/*
* 获取工作目录
*/
FFLIB_API_IMPORT_EXPORT status_t FFL_getWorkPath(char* workPath, size_t len);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Platform
* Created by zhufeifei(34008081@qq.com) on 2017/07/12
* https://github.com/zhenfei2016/FFLv2-lib.git
* 根据编译器定义的编译变量,确定编译的目标平台
*
*/
#ifndef _FFL_PLATFORM_H_
#define _FFL_PLATFORM_H_
#ifdef __cplusplus
extern "C" {
#endif
/*
* win32 平台
*/
#ifndef WIN32
#if defined( _MSC_VER) || defined(_WIN32) || defined(__WIN32__)
#define WIN32
#endif
#endif
/*
* macos平台
*/
#ifndef MACOSX
#if defined(__MACOSX__) || defined(__APPLE__)
#define MACOSX 1
#endif
#endif
/*
*apple ios平台
*/
#ifndef IOS
#if defined(__APPLE__)
#define IOS 1
#endif
#endif
/*
*android 平台下
*/
#ifndef ANDROID
#if defined(__ANDROID__)
#define ANDROID
#endif
#endif
/*
* 打印一下在那个平台下编译的
*
*/
#define FFL_COMPILER_LOG(f)
#if defined(WIN32)
FFL_COMPILER_LOG(target platform win32)
#elif defined(IOS)
FFL_COMPILER_LOG(target platform ios)
#elif defined(MACOSX)
FFL_COMPILER_LOG(target platform macosx)
#elif defined(ANDROID)
FFL_COMPILER_LOG(target platform android)
#else
FFL_COMPILER_LOG(target platform not support)
#endif
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Ref
* Created by zhufeifei(34008081@qq.com) on 2017/08/12
* https://github.com/zhenfei2016/FFLv2-lib.git
* 强弱引用计数定义
* class xxx : public ref::RefBase{
* }
*/
#ifndef __FFL_REF_HPP_
#define __FFL_REF_HPP_
#include "FFL_RefBase.hpp"
#include "FFL_RefCount.hpp"
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Ref
* Created by zhufeifei(34008081@qq.com) on 2017/07/10
* https://github.com/zhenfei2016/FFLv2-lib.git
* 引用计数内部用的atomic系列函数
*
*/
#ifndef _FFL_REF_ATOMIC_H_
#define _FFL_REF_ATOMIC_H_
#include <FFL_Atomic.h>
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_RefBase
* Created by zhufeifei(34008081@qq.com) on 2017/08/12
* https://github.com/zhenfei2016/FFLv2-lib.git
* 基于android中的引用计数类修改的
*
*/
#ifndef _FFL_REF_BASE_H_
#define _FFL_REF_BASE_H_
#include <FFL_Core.h>
#include "FFL_RefWp.hpp"
#include "FFL_RefSp.hpp"
namespace FFL {
class weakref_impl;
class FFLIB_API_IMPORT_EXPORT RefBase
{
friend class weakref_type;
protected:
RefBase();
virtual ~RefBase();
//! Flags for extendObjectLifetime()
enum
{
//
//指针的声明周期由强引用计数控制还是弱引用计数控制
//
OBJECT_LIFETIME_STRONG = 0x0000,
OBJECT_LIFETIME_WEAK = 0x0001,
OBJECT_LIFETIME_MASK = 0x0001
};
//
//指定生命周期强还是弱
//需要初始化的时候指定
//
void extendObjectLifetime(int32_t mode);
//! Flags for onIncStrongAttempted()
enum
{
FIRST_INC_STRONG = 0x0001
};
virtual void onFirstRef();
virtual void onLastStrongRef(const void* id);
virtual bool onIncStrongAttempted(uint32_t flags, const void* id);
virtual void onLastWeakRef(const void* id);
public:
void incStrong(const void* id) const;
void decStrong(const void* id) const;
void forceIncStrong(const void* id) const;
//! DEBUGGING ONLY: Get current strong ref count.
int32_t getStrongCount() const;
weakref_type* createWeak(const void* id) const;
weakref_type* getWeakRefs() const;
//! DEBUGGING ONLY: Print references held on object.
inline void printRefs() const { getWeakRefs()->printRefs(); }
//! DEBUGGING ONLY: Enable tracking of object.
inline void trackMe(bool enable, bool retain)
{
getWeakRefs()->trackMe(enable, retain);
}
typedef RefBase basetype;
private:
//friend class ReferenceMover;
//static void moveReferences(void* d, void const* s, size_t n,
// const ReferenceConverterBase& caster);
private:
friend class weakref_type;
RefBase(const RefBase& o);
RefBase& operator=(const RefBase& o);
weakref_impl* const mRefs;
};
template class FFLIB_API_IMPORT_EXPORT FFL::sp<RefBase>;
};
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_RefBase
* Created by zhufeifei(34008081@qq.com) on 2017/08/12
* https://github.com/zhenfei2016/FFLv2-lib.git
* 基于android中的引用计数类修改的
*
*/
#ifndef _FFL_REF_COUNT_H_
#define _FFL_REF_COUNT_H_
#include "FFL_RefAtomic.hpp"
namespace FFL
{
template <class T>
class Refcount
{
public:
inline Refcount()
{
FFL_atomicInit(&mCount,0);
}
inline void incStrong(const void* id) const
{
FFL_atomicInc(&mCount);
}
inline void decStrong(const void* id) const
{
if (FFL_atomicDec(&mCount) == 1) {
delete static_cast<const T*>(this);
}
}
inline int32_t getStrongCount() const
{
return (int32_t)mCount;
}
typedef Refcount<T> basetype;
protected:
inline ~Refcount() { }
private:
mutable AtomicInt mCount;
};
};
#endif
#ifndef _FFL_REF_LOG_H_
#define _FFL_REF_LOG_H_
#define ALOG_ASSERT(condition__,format__,__class) if (!(condition__)) { FFL_LOG_DEBUG_TAG("ref:",format__); }
#if defined(WIN32)
#define ALOGD
#else
#define ALOGD(...) FFL_LOG_DEBUG_TAG("ref:",##__VA_ARGS__)
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_RefSp
* Created by zhufeifei(34008081@qq.com) on 2017/08/12
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 强引用
*/
#ifndef _FFL_REF_SP_HPP_
#define _FFL_REF_SP_HPP_
#include <stdint.h>
#include <sys/types.h>
#include <stdlib.h>
// ---------------------------------------------------------------------------
namespace FFL {
template<typename T> class wp;
#define COMPARE(_op_) \
inline bool operator _op_ (const sp<T>& o) const { \
return m_ptr _op_ o.m_ptr; \
} \
inline bool operator _op_ (const T* o) const { \
return m_ptr _op_ o; \
} \
template<typename U> \
inline bool operator _op_ (const sp<U>& o) const { \
return m_ptr _op_ o.m_ptr; \
} \
template<typename U> \
inline bool operator _op_ (const U* o) const { \
return m_ptr _op_ o; \
} \
inline bool operator _op_ (const wp<T>& o) const { \
return m_ptr _op_ o.m_ptr; \
} \
template<typename U> \
inline bool operator _op_ (const wp<U>& o) const { \
return m_ptr _op_ o.m_ptr; \
}
template <typename T>
#if FFL_EXPORTS
class FFLIB_API_IMPORT_EXPORT sp
#else
class sp
#endif
{
public:
inline sp() : m_ptr(0) { }
sp(T* other);
sp(const sp<T>& other);
template<typename U> sp(U* other);
template<typename U> sp(const sp<U>& other);
~sp();
// Assignment
sp& operator = (T* other);
sp& operator = (const sp<T>& other);
template<typename U> sp& operator = (const sp<U>& other);
template<typename U> sp& operator = (U* other);
//! Special optimization for use by ProcessState (and nobody else).
void force_set(T* other);
inline int is_empty()const { return get()==0;}
inline int isEmpty() const{ return get() == 0; }
// Reset
void clear();
// Accessors
inline T& operator* () const { return *m_ptr; }
inline T* operator-> () const { return m_ptr; }
inline T* get() const { return m_ptr; }
// Operators
COMPARE(==)
COMPARE(!=)
COMPARE(>)
COMPARE(<)
COMPARE(<=)
COMPARE(>=)
private:
template<typename Y> friend class sp;
template<typename Y> friend class wp;
void set_pointer(T* ptr);
T* m_ptr;
};
#undef COMPARE
// ---------------------------------------------------------------------------
// No user serviceable parts below here.
template<typename T>
sp<T>::sp(T* other)
: m_ptr(other)
{
if (other) other->incStrong(this);
}
template<typename T>
sp<T>::sp(const sp<T>& other)
: m_ptr(other.m_ptr)
{
if (m_ptr) m_ptr->incStrong(this);
}
template<typename T> template<typename U>
sp<T>::sp(U* other) : m_ptr(other)
{
if (other) ((T*)other)->incStrong(this);
}
template<typename T> template<typename U>
sp<T>::sp(const sp<U>& other)
: m_ptr(other.m_ptr)
{
if (m_ptr) m_ptr->incStrong(this);
}
template<typename T>
sp<T>::~sp()
{
if (m_ptr) m_ptr->decStrong(this);
}
template<typename T>
sp<T>& sp<T>::operator = (const sp<T>& other) {
T* otherPtr(other.m_ptr);
if (otherPtr) otherPtr->incStrong(this);
if (m_ptr) m_ptr->decStrong(this);
m_ptr = otherPtr;
return *this;
}
template<typename T>
sp<T>& sp<T>::operator = (T* other)
{
if (other) other->incStrong(this);
if (m_ptr) m_ptr->decStrong(this);
m_ptr = other;
return *this;
}
template<typename T> template<typename U>
sp<T>& sp<T>::operator = (const sp<U>& other)
{
T* otherPtr(other.m_ptr);
if (otherPtr) otherPtr->incStrong(this);
if (m_ptr) m_ptr->decStrong(this);
m_ptr = otherPtr;
return *this;
}
template<typename T> template<typename U>
sp<T>& sp<T>::operator = (U* other)
{
if (other) ((T*)other)->incStrong(this);
if (m_ptr) m_ptr->decStrong(this);
m_ptr = other;
return *this;
}
template<typename T>
void sp<T>::force_set(T* other)
{
other->forceIncStrong(this);
m_ptr = other;
}
template<typename T>
void sp<T>::clear()
{
if (m_ptr) {
m_ptr->decStrong(this);
m_ptr = 0;
}
}
template<typename T>
void sp<T>::set_pointer(T* ptr) {
m_ptr = ptr;
}
};
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_ref_weakimpl
* Created by zhufeifei(34008081@qq.com) on 2017/08/12
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 引用计数类,内部增加的引用计数相关结构
*/
#ifndef _FFL_REF_WEAK_REF_IMPL_H_
#define _FFL_REF_WEAK_REF_IMPL_H_
#include "FFL_RefBase.hpp"
#include "FFL_RefAtomic.hpp"
namespace FFL
{
#define INITIAL_STRONG_VALUE (1<<28)
class weakref_impl : public weakref_type
{
public:
AtomicInt mStrong;
AtomicInt mWeak;
RefBase* const mBase;
AtomicInt mFlags;
public:
weakref_impl(RefBase* base);
~weakref_impl();
void addStrongRef(const void* /*id*/);
void removeStrongRef(const void* /*id*/);
void renameStrongRefId(const void* /*old_id*/, const void* /*new_id*/);
void addWeakRef(const void* /*id*/);
void removeWeakRef(const void* /*id*/);
void renameWeakRefId(const void* /*old_id*/, const void* /*new_id*/);
void printRefs() const;
void trackMe(bool, bool);
};
};
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_ref_weakimpl
* Created by zhufeifei(34008081@qq.com) on 2017/08/12
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 弱引用
*/
#ifndef _FFL_REF_WP_H_
#define _FFL_REF_WP_H_
#include "FFL_RefSp.hpp"
// ---------------------------------------------------------------------------
namespace FFL {
// ---------------------------------------------------------------------------
//比较操作符定义,参数分为强指针,原始指针,其他派生类强指针, 其他派生类原始指针
//
#define COMPARE_WEAK(_op_) \
inline bool operator _op_ (const sp<T>& o) const { \
return m_ptr _op_ o.m_ptr; \
} \
inline bool operator _op_ (const T* o) const { \
return m_ptr _op_ o; \
} \
template<typename U> \
inline bool operator _op_ (const sp<U>& o) const { \
return m_ptr _op_ o.m_ptr; \
} \
template<typename U> \
inline bool operator _op_ (const U* o) const { \
return m_ptr _op_ o; \
}
class RefBase;
class FFLIB_API_IMPORT_EXPORT weakref_type
{
public:
RefBase* refBase() const;
void incWeak(const void* id);
void decWeak(const void* id);
// acquires a strong reference if there is already one.
bool attemptIncStrong(const void* id);
// acquires a weak reference if there is already one.
// This is not always safe. see ProcessState.cpp and BpBinder.cpp
// for proper use.
bool attemptIncWeak(const void* id);
//! DEBUGGING ONLY: Get current weak ref count.
int32_t getWeakCount() const;
//! DEBUGGING ONLY: Print references held on object.
void printRefs() const;
//! DEBUGGING ONLY: Enable tracking for this object.
// enable -- enable/disable tracking
// retain -- when tracking is enable, if true, then we save a stack trace
// for each reference and dereference; when retain == false, we
// match up references and dereferences and keep only the
// outstanding ones.
void trackMe(bool enable, bool retain);
};
template <typename T>
class FFLIB_API_IMPORT_EXPORT wp
{
public:
inline wp() : m_ptr(0) { }
wp(T* other);
wp(const wp<T>& other);
wp(const sp<T>& other);
template<typename U> wp(U* other);
template<typename U> wp(const sp<U>& other);
template<typename U> wp(const wp<U>& other);
~wp();
wp& operator = (T* other);
wp& operator = (const wp<T>& other);
wp& operator = (const sp<T>& other);
template<typename U> wp& operator = (U* other);
template<typename U> wp& operator = (const wp<U>& other);
template<typename U> wp& operator = (const sp<U>& other);
void set_object_and_refs(T* other, weakref_type* refs);
// promotion to sp
sp<T> promote() const;
// Reset
void clear();
// Accessors
inline weakref_type* get_refs() const { return m_refs; }
inline T* unsafe_get() const { return m_ptr; }
// Operators
COMPARE_WEAK(==)
COMPARE_WEAK(!=)
COMPARE_WEAK(>)
COMPARE_WEAK(<)
COMPARE_WEAK(<=)
COMPARE_WEAK(>=)
inline bool operator == (const wp<T>& o) const {
return (m_ptr == o.m_ptr) && (m_refs == o.m_refs);
}
template<typename U>
inline bool operator == (const wp<U>& o) const {
return m_ptr == o.m_ptr;
}
inline bool operator > (const wp<T>& o) const {
return (m_ptr == o.m_ptr) ? (m_refs > o.m_refs) : (m_ptr > o.m_ptr);
}
template<typename U>
inline bool operator > (const wp<U>& o) const {
return (m_ptr == o.m_ptr) ? (m_refs > o.m_refs) : (m_ptr > o.m_ptr);
}
inline bool operator < (const wp<T>& o) const {
return (m_ptr == o.m_ptr) ? (m_refs < o.m_refs) : (m_ptr < o.m_ptr);
}
template<typename U>
inline bool operator < (const wp<U>& o) const {
return (m_ptr == o.m_ptr) ? (m_refs < o.m_refs) : (m_ptr < o.m_ptr);
}
inline bool operator != (const wp<T>& o) const { return m_refs != o.m_refs; }
template<typename U> inline bool operator != (const wp<U>& o) const { return !operator == (o); }
inline bool operator <= (const wp<T>& o) const { return !operator > (o); }
template<typename U> inline bool operator <= (const wp<U>& o) const { return !operator > (o); }
inline bool operator >= (const wp<T>& o) const { return !operator < (o); }
template<typename U> inline bool operator >= (const wp<U>& o) const { return !operator < (o); }
private:
template<typename Y> friend class sp;
template<typename Y> friend class wp;
T* m_ptr;
weakref_type* m_refs;
};
#undef COMPARE_WEAK
template<typename T>
wp<T>::wp(T* other)
: m_ptr(other)
{
if (other) m_refs = other->createWeak(this);
}
template<typename T>
wp<T>::wp(const wp<T>& other)
: m_ptr(other.m_ptr), m_refs(other.m_refs)
{
if (m_ptr) m_refs->incWeak(this);
}
template<typename T>
wp<T>::wp(const sp<T>& other)
: m_ptr(other.m_ptr)
{
if (m_ptr) {
m_refs = m_ptr->createWeak(this);
}
}
template<typename T> template<typename U>
wp<T>::wp(U* other)
: m_ptr(other)
{
if (other) m_refs = other->createWeak(this);
}
template<typename T> template<typename U>
wp<T>::wp(const wp<U>& other)
: m_ptr(other.m_ptr)
{
if (m_ptr) {
m_refs = other.m_refs;
m_refs->incWeak(this);
}
}
template<typename T> template<typename U>
wp<T>::wp(const sp<U>& other)
: m_ptr(other.m_ptr)
{
if (m_ptr) {
m_refs = m_ptr->createWeak(this);
}
}
template<typename T>
wp<T>::~wp()
{
if (m_ptr) m_refs->decWeak(this);
}
template<typename T>
wp<T>& wp<T>::operator = (T* other)
{
weakref_type* newRefs =
other ? other->createWeak(this) : 0;
if (m_ptr) m_refs->decWeak(this);
m_ptr = other;
m_refs = newRefs;
return *this;
}
template<typename T>
wp<T>& wp<T>::operator = (const wp<T>& other)
{
weakref_type* otherRefs(other.m_refs);
T* otherPtr(other.m_ptr);
if (otherPtr) otherRefs->incWeak(this);
if (m_ptr) m_refs->decWeak(this);
m_ptr = otherPtr;
m_refs = otherRefs;
return *this;
}
template<typename T>
wp<T>& wp<T>::operator = (const sp<T>& other)
{
weakref_type* newRefs =
other != NULL ? other->createWeak(this) : 0;
T* otherPtr(other.m_ptr);
if (m_ptr) m_refs->decWeak(this);
m_ptr = otherPtr;
m_refs = newRefs;
return *this;
}
template<typename T> template<typename U>
wp<T>& wp<T>::operator = (U* other)
{
weakref_type* newRefs =
other ? other->createWeak(this) : 0;
if (m_ptr) m_refs->decWeak(this);
m_ptr = other;
m_refs = newRefs;
return *this;
}
template<typename T> template<typename U>
wp<T>& wp<T>::operator = (const wp<U>& other)
{
weakref_type* otherRefs(other.m_refs);
U* otherPtr(other.m_ptr);
if (otherPtr) otherRefs->incWeak(this);
if (m_ptr) m_refs->decWeak(this);
m_ptr = otherPtr;
m_refs = otherRefs;
return *this;
}
template<typename T> template<typename U>
wp<T>& wp<T>::operator = (const sp<U>& other)
{
weakref_type* newRefs =
other != NULL ? other->createWeak(this) : 0;
U* otherPtr(other.m_ptr);
if (m_ptr) m_refs->decWeak(this);
m_ptr = otherPtr;
m_refs = newRefs;
return *this;
}
template<typename T>
void wp<T>::set_object_and_refs(T* other, weakref_type* refs)
{
if (other) refs->incWeak(this);
if (m_ptr) m_refs->decWeak(this);
m_ptr = other;
m_refs = refs;
}
template<typename T>
sp<T> wp<T>::promote() const
{
sp<T> result;
if (m_ptr && m_refs->attemptIncStrong(&result)) {
result.set_pointer(m_ptr);
}
return result;
}
template<typename T>
void wp<T>::clear()
{
if (m_ptr) {
m_refs->decWeak(this);
m_ptr = 0;
}
}
};
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Serializable
* Created by zhufeifei(34008081@qq.com) on 2018/03/10
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 用于序列换的接口
*/
#ifndef _FFL_SERILIZABLE_HPP_
#define _FFL_SERILIZABLE_HPP_
#include <FFL_Ref.hpp>
namespace FFL{
class ByteStream;
class ISerializable{
public:
virtual void serialization(ByteStream& stream)=0;
virtual status_t deserialization(ByteStream& stream)=0;
};
class FFLIB_API_IMPORT_EXPORT Serializable : public ISerializable, public RefBase {
public:
Serializable();
~Serializable();
//
// 对象序列化到stream中
//
virtual void serialization(ByteStream& stream);
//
// stream中反序列到当前对象实例中
//
virtual status_t deserialization(ByteStream& stream);
};
}
#endif
/*
* Copyright (C) 2005 The Android Open Source Project
*
* 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.
*/
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_SharedBuffer.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/12/10
* https://github.com/zhenfei2016/FFL-v2.git
*
* ÒÆÖ²ÐÞ¸ÄһЩÄÚÈÝ
*/
#ifndef _FFL_SHARED_BUFFER_HPP_
#define _FFL_SHARED_BUFFER_HPP_
#include <FFL_Core.h>
namespace FFL {
class FFLIB_API_IMPORT_EXPORT SharedBuffer
{
public:
/* flags to use with release() */
enum {
eKeepStorage = 0x00000001
};
/*! allocate a buffer of size 'size' and acquire() it.
* call release() to free it.
*/
static SharedBuffer* alloc(size_t size);
/*! free the memory associated with the SharedBuffer.
* Fails if there are any users associated with this SharedBuffer.
* In other words, the buffer must have been release by all its
* users.
*/
static int dealloc(const SharedBuffer* released);
//! get the SharedBuffer from the data pointer
static inline const SharedBuffer* sharedBuffer(const void* data);
//! access the data for read
inline const void* data() const;
//! access the data for read/write
inline void* data();
//! get size of the buffer
inline size_t size() const;
//! get back a SharedBuffer object from its data
static inline SharedBuffer* bufferFromData(void* data);
//! get back a SharedBuffer object from its data
static inline const SharedBuffer* bufferFromData(const void* data);
//! get the size of a SharedBuffer object from its data
static inline size_t sizeFromData(const void* data);
//! edit the buffer (get a writtable, or non-const, version of it)
SharedBuffer* edit() const;
//! edit the buffer, resizing if needed
SharedBuffer* editResize(size_t size) const;
//! like edit() but fails if a copy is required
SharedBuffer* attemptEdit() const;
//! resize and edit the buffer, loose it's content.
SharedBuffer* reset(size_t size) const;
//! acquire/release a reference on this buffer
void acquire() const;
/*! release a reference on this buffer, with the option of not
* freeing the memory associated with it if it was the last reference
* returns the previous reference count
*/
int32_t release(uint32_t flags = 0) const;
//! returns wether or not we're the only owner
inline bool onlyOwner() const;
private:
inline SharedBuffer() { }
inline ~SharedBuffer() { }
inline SharedBuffer(const SharedBuffer&);
// 16 bytes. must be sized to preserve correct alingment.
size_t mSize;
uint32_t mReserved1;
mutable volatile int32_t mRefs;
uint32_t mReserved2;
//union {
// typedef struct{
// mutable volatile int32_t mRefCount;
// uint32_t mReserved1;
// uint32_t mSize;
// }mInfo;
// uint8_t mBytes[12];
//} mHeader;
};
// ---------------------------------------------------------------------------
const SharedBuffer* SharedBuffer::sharedBuffer(const void* data) {
return data ? reinterpret_cast<const SharedBuffer *>(data)-1 : 0;
}
const void* SharedBuffer::data() const {
return this + 1;
}
void* SharedBuffer::data() {
return this + 1;
}
size_t SharedBuffer::size() const {
return mSize;
}
SharedBuffer* SharedBuffer::bufferFromData(void* data)
{
return ((SharedBuffer*)data)-1;
}
const SharedBuffer* SharedBuffer::bufferFromData(const void* data)
{
return ((const SharedBuffer*)data)-1;
}
size_t SharedBuffer::sizeFromData(const void* data)
{
return (((const SharedBuffer*)data)-1)->mSize;
}
bool SharedBuffer::onlyOwner() const {
return (mRefs == 1);
}
};
// ---------------------------------------------------------------------------
#endif // ANDROID_VECTOR_H
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Stdint.h
* Created by zhufeifei(34008081@qq.com) on 2019/02/1
* https://github.com/zhenfei2016/FFLv2-lib.git
*
*
*/
#ifndef _FFL_STDINT_H_
#define _FFL_STDINT_H_
/* 支持 int8_t * 系列的定义 */
#ifdef WIN32
/* c99支持的 */
#include <stdint.h>
#else
#include <stdint.h>
#include <stddef.h>
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_String
* Created by zhufeifei(34008081@qq.com) on 2017/7/12.
* https://github.com/zhenfei2016/FFLv2-lib.git
*
* 内存的申请,释放,大小端控制 , 内存泄漏检测
*/
#ifndef _FFL_STRING_H_
#define _FFL_STRING_H_
#include <stdlib.h>
#include <memory.h>
#include <FFL_Config.h>
#include <FFL_Stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* 字符串复制
*/
FFLIB_API_IMPORT_EXPORT char* FFL_strdup(const char *s);
FFLIB_API_IMPORT_EXPORT char* FFL_strndup(const char *s, size_t len);
/* win平台在1600(vs2010)版本前需要自己定义snprintf */
#if WIN32
#if _MSC_VER <=1600
#define snprintf _snprintf
#elif FFLIB_COMPILE_SHARED
#pragma comment(lib,"legacy_stdio_definitions.lib")
#endif
#endif
#ifdef __cplusplus
}
#endif
#endif
/*
* Copyright (C) 2005 The Android Open Source Project
*
* 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.
*/
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_String.cpp
* Created by zhufeifei(34008081@qq.com) on 2018/12/10
* https://github.com/zhenfei2016/FFL-v2.git
*
* 为了方便shared模块导出,移植了这个文件
*/
#ifndef _FFL_STRING_HPP_
#define _FFL_STRING_HPP_
#include <FFL_Config.h>
#include <FFL_SharedBuffer.hpp>
#include <stdarg.h>
namespace FFL {
typedef int status_t;
class SharedBuffer;
//! This is a string holding UTF-8 characters. Does not allow the value more
// than 0x10FFFF, which is not valid unicode codepoint.
class FFLIB_API_IMPORT_EXPORT String8
{
public:
String8();
String8(const String8& o);
explicit String8(const char* o);
explicit String8(const char* o, size_t numChars);
~String8();
static inline const String8 empty();
#if WIN32
#define FORMAT_COMPILE_CHECK(f,v)
#else
//
//编译器检查可变参数格式是否正确
//
#define FORMAT_COMPILE_CHECK(f,v) __attribute__((format (printf, f, v)))
#endif
static String8 format(const char* fmt, ...) FORMAT_COMPILE_CHECK(1, 2);
static String8 formatV(const char* fmt, va_list args);
inline const char* string() const;
inline size_t size() const;
size_t length() const;
size_t bytes() const;
inline bool isEmpty() const;
const SharedBuffer* sharedBuffer() const;
void clear();
void setTo(const String8& other);
status_t setTo(const char* other);
status_t setTo(const char* other, size_t numChars);
status_t append(const String8& other);
status_t append(const char* other);
status_t append(const char* other, size_t numChars);
status_t appendFormat(const char* fmt, ...) FORMAT_COMPILE_CHECK(2, 3);
status_t appendFormatV(const char* fmt, va_list args);
inline String8& operator=(const String8& other);
inline String8& operator=(const char* other);
inline String8& operator+=(const String8& other);
inline String8 operator+(const String8& other) const;
inline String8& operator+=(const char* other);
inline String8 operator+(const char* other) const;
inline int compare(const String8& other) const;
inline int compare(const char* other) const;
inline bool operator<(const String8& other) const;
inline bool operator<=(const String8& other) const;
inline bool operator==(const String8& other) const;
inline bool operator!=(const String8& other) const;
inline bool operator>=(const String8& other) const;
inline bool operator>(const String8& other) const;
inline bool operator<(const char* other) const;
inline bool operator<=(const char* other) const;
inline bool operator==(const char* other) const;
inline bool operator!=(const char* other) const;
inline bool operator>=(const char* other) const;
inline bool operator>(const char* other) const;
inline operator const char*() const;
char* lockBuffer(size_t size);
void unlockBuffer();
status_t unlockBuffer(size_t size);
// return the index of the first byte of other in this at or after
// start, or -1 if not found
int find(const char* other, size_t start = 0) const;
void toLower();
void toLower(size_t start, size_t numChars);
void toUpper();
void toUpper(size_t start, size_t numChars);
//
// 转64位整形,32位整形
//
int64_t toInt64();
int32_t toInt32();
//
// 什么开始,结束
//
bool startWith(const char* sub);
bool endWith(const char*sub);
bool equal(const char* other);
bool equal(const String8& other);
//
// 不区分大小写的比较,你需要确定保存的字符串啊
//
bool equalIgnoreCase(const char* other);
bool equalIgnoreCase(const String8& other);
/*
* These methods operate on the string as if it were a path name.
*/
/*
* Set the filename field to a specific value.
*
* Normalizes the filename, removing a trailing '/' if present.
*/
void setPathName(const char* name);
void setPathName(const char* name, size_t numChars);
/*
* Get just the filename component.
*
* "/tmp/foo/bar.c" --> "bar.c"
*/
String8 getPathLeaf(void) const;
/*
* Remove the last (file name) component, leaving just the directory
* name.
*
* "/tmp/foo/bar.c" --> "/tmp/foo"
* "/tmp" --> "" // ????? shouldn't this be "/" ???? XXX
* "bar.c" --> ""
*/
String8 getPathDir(void) const;
/*
* Retrieve the front (root dir) component. Optionally also return the
* remaining components.
*
* "/tmp/foo/bar.c" --> "tmp" (remain = "foo/bar.c")
* "/tmp" --> "tmp" (remain = "")
* "bar.c" --> "bar.c" (remain = "")
*/
String8 walkPath(String8* outRemains = NULL) const;
/*
* Return the filename extension. This is the last '.' and any number
* of characters that follow it. The '.' is included in case we
* decide to expand our definition of what constitutes an extension.
*
* "/tmp/foo/bar.c" --> ".c"
* "/tmp" --> ""
* "/tmp/foo.bar/baz" --> ""
* "foo.jpeg" --> ".jpeg"
* "foo." --> ""
*/
String8 getPathExtension(void) const;
/*
* Return the path without the extension. Rules for what constitutes
* an extension are described in the comment for getPathExtension().
*
* "/tmp/foo/bar.c" --> "/tmp/foo/bar"
*/
String8 getBasePath(void) const;
/*
* Add a component to the pathname. We guarantee that there is
* exactly one path separator between the old path and the new.
* If there is no existing name, we just copy the new name in.
*
* If leaf is a fully qualified path (i.e. starts with '/', it
* replaces whatever was there before.
*/
String8& appendPath(const char* leaf);
String8& appendPath(const String8& leaf) { return appendPath(leaf.string()); }
/*
* Like appendPath(), but does not affect this string. Returns a new one instead.
*/
String8 appendPathCopy(const char* leaf) const
{
String8 p(*this); p.appendPath(leaf); return p;
}
String8 appendPathCopy(const String8& leaf) const { return appendPathCopy(leaf.string()); }
/*
* Converts all separators in this string to /, the default path separator.
*
* If the default OS separator is backslash, this converts all
* backslashes to slashes, in-place. Otherwise it does nothing.
* Returns self.
*/
String8& convertToResPath();
private:
status_t real_append(const char* other, size_t numChars);
char* find_extension(void) const;
const char* mString;
};
typedef String8 String;
// ---------------------------------------------------------------------------
// No user servicable parts below.
inline int compare_type(const String8& lhs, const String8& rhs)
{
return lhs.compare(rhs);
}
inline int strictly_order_type(const String8& lhs, const String8& rhs)
{
return compare_type(lhs, rhs) < 0;
}
inline const String8 String8::empty() {
return String8();
}
inline const char* String8::string() const
{
return mString;
}
inline size_t String8::size() const
{
return length();
}
inline bool String8::isEmpty() const
{
return length() == 0;
}
inline String8& String8::operator=(const String8& other)
{
setTo(other);
return *this;
}
inline String8& String8::operator=(const char* other)
{
setTo(other);
return *this;
}
inline String8& String8::operator+=(const String8& other)
{
append(other);
return *this;
}
inline String8 String8::operator+(const String8& other) const
{
String8 tmp(*this);
tmp += other;
return tmp;
}
inline String8& String8::operator+=(const char* other)
{
append(other);
return *this;
}
inline String8 String8::operator+(const char* other) const
{
String8 tmp(*this);
tmp += other;
return tmp;
}
inline int String8::compare(const String8& other) const
{
return strcmp(mString, other.mString);
}
inline int String8::compare(const char* other) const {
return strcmp(mString, other);
}
inline bool String8::operator<(const String8& other) const
{
return strcmp(mString, other.mString) < 0;
}
inline bool String8::operator<=(const String8& other) const
{
return strcmp(mString, other.mString) <= 0;
}
inline bool String8::operator==(const String8& other) const
{
return strcmp(mString, other.mString) == 0;
}
inline bool String8::operator!=(const String8& other) const
{
return strcmp(mString, other.mString) != 0;
}
inline bool String8::operator>=(const String8& other) const
{
return strcmp(mString, other.mString) >= 0;
}
inline bool String8::operator>(const String8& other) const
{
return strcmp(mString, other.mString) > 0;
}
inline bool String8::operator<(const char* other) const
{
return strcmp(mString, other) < 0;
}
inline bool String8::operator<=(const char* other) const
{
return strcmp(mString, other) <= 0;
}
inline bool String8::operator==(const char* other) const
{
return strcmp(mString, other) == 0;
}
inline bool String8::operator!=(const char* other) const
{
return strcmp(mString, other) != 0;
}
inline bool String8::operator>=(const char* other) const
{
return strcmp(mString, other) >= 0;
}
inline bool String8::operator>(const char* other) const
{
return strcmp(mString, other) > 0;
}
inline String8::operator const char*() const
{
return mString;
}
}
#endif
/*
* FFL_thread.h
* FFL
*
* Created by zhufeifei on 2017/8/12.
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
* 线程,主要移植于SDL库
*/
#ifndef _FFL_THREAD_H_
#define _FFL_THREAD_H_
#include <FFL_Core.h>
#include <FFL_ThreadConstant.h>
#ifdef __cplusplus
extern "C" {
#endif
struct FFL_Thread_sys;
//前向声明的,cpp那面会进行真正的定义的
//针对不同平台可能结构是不一样的
//
typedef struct FFL_Thread_sys FFL_Thread;
//创建线程 并等待线程函数开始执行
//当线程结束的时候,会自动删除创建的FFL_Thread
// fn : 线程函数
//name :线程名称
//data : 上下文参数
//
FFLIB_API_IMPORT_EXPORT FFL_Thread *FFL_CALL FFL_CreateThread(FFL_ThreadFunction fn, const char *name, void *data);
//获取线程名称
//
FFLIB_API_IMPORT_EXPORT const char *FFL_CALL FFL_GetThreadName(FFL_Thread *thread);
//获取线程id, 当前线程,其他线程
//
FFLIB_API_IMPORT_EXPORT FFL_ThreadID FFL_CALL FFL_CurrentThreadID(void);
FFLIB_API_IMPORT_EXPORT FFL_ThreadID FFL_CALL FFL_GetThreadID(FFL_Thread * thread);
//设置线程优先级
//
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_SetThreadPriority(FFL_ThreadPriority priority);
/*
* 阻塞等待线程结束,返回后thread就不可用了
*/
FFLIB_API_IMPORT_EXPORT void FFL_CALL FFL_WaitThread(FFL_Thread * thread, int *status);
/*
* 结束线程 非阻塞,返回后线程还有资源没释放,等会会自己释放的,但是thread不可用了
*/
FFLIB_API_IMPORT_EXPORT void FFL_CALL FFL_DetachThread(FFL_Thread * thread);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Thread
* Created by zhufeifei(34008081@qq.com) on 2017/11/25
* https://github.com/zhenfei2016/FFLv2-lib.git
* 基予Android Open Source Project,修改的线程封装
*
*/
#ifndef _FFL_THREAD_HPP_
#define _FFL_THREAD_HPP_
#include <FFL_Core.h>
#include <FFL_Thread.h>
#include <FFL_Mutex.hpp>
#include <FFL_Ref.hpp>
namespace FFL {
class FFLIB_API_IMPORT_EXPORT Thread : virtual public RefBase
{
public:
Thread();
virtual ~Thread();
// Start the thread in threadLoop() which needs to be implemented.
virtual status_t run(const char* name = 0,
int32_t priority = FFL_THREAD_PRIORITY_NORMAL,
size_t stack = 0);
// Ask this object's thread to exit. This function is asynchronous, when the
// function returns the thread might still be running. Of course, this
// function can be called from a different thread.
virtual void requestExit();
// Good place to do one-time initializations
virtual status_t readyToRun();
// Call requestExit() and wait until this object's thread exits.
// BE VERY CAREFUL of deadlocks. In particular, it would be silly to call
// this function from this object's thread. Will return WOULD_BLOCK in
// that case.
virtual status_t requestExitAndWait();
// Wait until this object's thread exits. Returns immediately if not yet running.
// Do not call from this object's thread; will return WOULD_BLOCK in that case.
status_t join();
bool isRunning() const;
FFL_ThreadID getTid() const;
// exit_pending() returns true if requestExit() has been called.
bool exitPending() const;
private:
virtual void threadLoopStart();
// Derived class must implement threadLoop(). The thread starts its life
// here. There are two ways of using the Thread object:
// 1) loop: if threadLoop() returns true, it will be called again if
// requestExit() wasn't called.
// 2) once: if threadLoop() returns false, the thread will exit upon return.
virtual bool threadLoop() = 0;
virtual void threadLoopExit(const Thread* t);
private:
static int FFL_CALL _threadLoop(void* user);
class ThreadData;
ThreadData* mThreadData;
DISABLE_COPY_CONSTRUCTORS(Thread);
};
template class FFLIB_API_IMPORT_EXPORT FFL::sp<Thread>;
};
// ---------------------------------------------------------------------------
#endif // _LIBS_UTILS_THREAD_H
// ---------------------------------------------------------------------------
/*
* FFL_thread_constant.h
* FFL
*
* Created by zhufeifei on 2017/8/12.
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
* 线程的一堆常量,单独分出来,因为线程的实现方需要这些值
*
*/
#ifndef _FFL_THREAD_CONSTANT_H_
#define _FFL_THREAD_CONSTANT_H_
/*
线程函数
*/
typedef int (FFL_CALL * FFL_ThreadFunction) (void *data);
/*
线程id
*/
typedef unsigned long FFL_ThreadID;
/*
线程的优先级
*/
typedef enum
{
FFL_THREAD_PRIORITY_LOW,
FFL_THREAD_PRIORITY_NORMAL,
FFL_THREAD_PRIORITY_HIGH
} FFL_ThreadPriority;
/*
线程状态
*/
typedef enum FFL_ThreadState
{
FFL_THREAD_STATE_ALIVE,
FFL_THREAD_STATE_DETACHED,
FFL_THREAD_STATE_ZOMBIE,
FFL_THREAD_STATE_CLEANED,
} FFL_ThreadState;
#endif
/*
* FFL_threadpool.h
* FFL
*
* Created by zhufeifei on 2017/8/12.
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
* 简单的线程池类
*/
#ifndef _FFL_THREADPOOL_H_
#define _FFL_THREADPOOL_H_
#include <FFL_Core.h>
#include <FFL_ThreadConstant.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct sys_threadpool_t* FFL_Threadpool;
typedef struct FFL_ThreadpoolJob_t
{
void *(FFL_CALL *func)(void *);
void *arg;
}FFL_ThreadpoolJob;
/*
* 创建线程池 : threadnum线程数量
*
*/
FFLIB_API_IMPORT_EXPORT FFL_Threadpool FFL_CALL FFL_CreateThreadpool(int threadnum);
/*
* 运行一个job,如果当前没有可用的线程则等待
* 返回是否成功呢 FFL_ERROR_SUCCESS:成功
*/
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_RunThreadpoolJob(FFL_Threadpool pool, FFL_ThreadpoolJob* job);
/*
* 结束线程池
* 等待所有的线程结束后才返回
*/
FFLIB_API_IMPORT_EXPORT void FFL_CALL FFL_DetachThreadpool(FFL_Threadpool pool);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Time
* Created by zhufeifei(34008081@qq.com) on 2018/06/10
* https://github.com/zhenfei2016/FFLv2-lib.git
* 时间获取相关的封装函数
*
*/
#ifndef _FFL_TIME_H_
#define _FFL_TIME_H_
#include <FFL_Config.h>
#include <FFL_Stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* sleep()
*/
FFLIB_API_IMPORT_EXPORT void FFL_sleep(int ms);
/*
* 获取当前时间 us
* */
FFLIB_API_IMPORT_EXPORT int64_t FFL_getNowUs();
FFLIB_API_IMPORT_EXPORT int32_t FFL_getNowMs();
/*
* 获取当前时间的字符串类型
*/
FFLIB_API_IMPORT_EXPORT void FFL_getNowString(char* s,int32_t bufSize);
/*
* 毫秒转化为string, s:需要保证足够存储转化出来的时间字符串
*/
FFLIB_API_IMPORT_EXPORT void FFL_usToString(int64_t timeUs, char* s, int32_t bufSize);
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Utils.hpp
* Created by zhufeifei(34008081@qq.com) on 七月 2017.
*
* 定义了一系列的公用宏,和头文件引用
*
*/
#ifndef _FFL_UTILITY_HPP_
#define _FFL_UTILITY_HPP_
//
// 删除指针,指针数组
//
#define FFL_SafeFree(p) \
while (p) { \
delete p;p = 0; break;\
}
#define FFL_SafeFreeA(p) \
while (p) { \
delete[] p;p = 0; break;\
}
//
// 栈退出时候,自动删除对应的对象
//
#define FFL_AutoFree(className, instance) \
internal_AutoFree<className> _auto_free_##instance(&instance, false)
template<class T>
class internal_AutoFree
{
public:
internal_AutoFree(T** p) : ptr(p) { }
~internal_AutoFree() { FFL_SafeFree(*ptr); }
private:
T** ptr;
};
//
// 栈退出时候,自动删除对应的数组对象
//
#define FFL_AutoFreeArray(className, instance) \
internal_AutoFreeA<className> _auto_free_array_##instance(&instance, true)
template<class T>
class internal_AutoFreeA
{
public:
internal_AutoFreeA(T* * p): ptr(p){ }
~internal_AutoFreeA() { FFL_SafeFreeA(*ptr); }
private:
T* * ptr;
};
//
// 禁用c++的拷贝构造,赋值函数
//
#define DISABLE_COPY_CONSTRUCTORS(class_name) \
class_name(const class_name &); \
class_name &operator=(const class_name &)
#include <FFL_String.hpp>
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Version
* Created by zhufeifei(34008081@qq.com) on 2018/1/7.
* https://github.com/zhenfei2016/FFLv2-lib.git
* 版本相关信息
*
*/
#ifndef _FFL_VERSION_H_
#define _FFL_VERSION_H_
#include <FFL_Core.h>
/*
* 转化成整形类型
*/
#define FFL_VERSION_INT(a, b, c) ((a)<<16 | (b)<<8 | (c))
/*
* 字符串连接成 "3.0.0"
* vs下没问题,
* gcc系列的编译器提示错误 ,如果不是vs编译,就不要使用这个宏
*/
#define FFL_VERSION_DOT(a, b, c) FFL_TOSTRING(a)##"."## FFL_TOSTRING(b) ##"."## FFL_TOSTRING(c)
/*
* 对应版本号的3段
*
*/
#define FFL_VERSION_MAJOR 3
#define FFL_VERSION_MINOR 0
#define FFL_VERSION_MICRO 190315
/*
* 字符串类型版本号 0.1.1
*/
#define FFLLIB_VERSION_STRING "3.0.190315"
/*
整形的版本号 ,版本号分2段,每段8字节的(0-255)
*/
#define FFLLIB_VERSION_INT FFL_VERSION_INT(FFL_VERSION_MAJOR,FFL_VERSION_MINOR,FFL_VERSION_MICRO)
#ifdef __cplusplus
extern "C" {
#endif
/*
* 获取版本号,字符串类型
*/
FFLIB_API_IMPORT_EXPORT const char* FFL_CALL FFL_GetVersion();
/*
* 获取版本号,整形
*/
FFLIB_API_IMPORT_EXPORT int FFL_CALL FFL_GetVersion_int();
#ifdef __cplusplus
}
#endif
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_lib.h
* Created by zhufeifei(34008081@qq.com) on 2018/12/08
* https://github.com/zhenfei2016/FFLv2-lib.git
* 包含进来需要的大多数头文件
*
*/
#ifndef _FFLIB_FFLv2_H_
#define _FFLIB_FFLv2_H_
#include <FFL_Core.h>
#include <FFL_Version.h>
#include <FFL_Log.h>
#include <FFL_Path.h>
#include <FFL_Console.h>
#endif
/*
* This file is part of FFL project.
*
* The MIT License (MIT)
* Copyright (C) 2017-2018 zhufeifei All rights reserved.
*
* FFL_Lib.hpp
* Created by zhufeifei(34008081@qq.com) on 2018/12/08
* https://github.com/zhenfei2016/FFLv2-lib.git
* 包含进来需要的大多数头文件,c++的头文件
*
*/
#ifndef _FFLIB_FFLv2_HPP_
#define _FFLIB_FFLv2_HPP_
#include <FFL_lib.h>
#include <FFL_Console.hpp>
#include <FFL_ByteBuffer.hpp>
#include <FFL_ByteStream.hpp>
#include <FFL_String.h>
#include <FFL_File.hpp>
#include <FFL_Module.hpp>
#endif
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册