diff --git a/middleware/StateMachine/CMakeLists.txt b/middleware/StateMachine/CMakeLists.txt index d37241f4..89c5be3a 100644 --- a/middleware/StateMachine/CMakeLists.txt +++ b/middleware/StateMachine/CMakeLists.txt @@ -38,10 +38,19 @@ add_custom_target( -p ${CMAKE_SOURCE_DIR_IPCSDK}/cmake-shell WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/StateMachine ) +file(GLOB_RECURSE HEADER_FILES *.h) +add_custom_target( + StateMahince_code_format + COMMAND ${CLANG_FORMAT_EXE} + -style=file + -i ${SRC_FILES} ${HEADER_FILES} + WORKING_DIRECTORY ${MIDDLEWARE_SOURCE_PATH}/StateMachine +) add_custom_command( TARGET ${TARGET_NAME} PRE_BUILD COMMAND make StateMahince_code_check + COMMAND make StateMahince_code_format WORKING_DIRECTORY ${PROJECT_ROOT_PATH}/cmake-shell/ ) endif() \ No newline at end of file diff --git a/middleware/StateMachine/include/IStateMachine.h b/middleware/StateMachine/include/IStateMachine.h index df42cf7e..e614572c 100644 --- a/middleware/StateMachine/include/IStateMachine.h +++ b/middleware/StateMachine/include/IStateMachine.h @@ -3,9 +3,9 @@ * 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. @@ -57,7 +57,10 @@ public: virtual void SendMessage(int msgName) {} virtual void StopHandlerThread() {} virtual void SendMessage(int msgName, const std::shared_ptr &messageObj) {} - virtual void MessageExecutedLater(int msgName, const std::shared_ptr &messageObj, int64_t delayTimeMs) {} + virtual void MessageExecutedLater(int msgName, const std::shared_ptr &messageObj, + int64_t delayTimeMs) + { + } virtual void SwitchState(State *targetState) {} virtual void StopTimer(int timerName) {} virtual void DelayMessage(VStateMachineData *msg) {} diff --git a/middleware/StateMachine/src/IStateMachine.cpp b/middleware/StateMachine/src/IStateMachine.cpp index dbfa6437..33a48529 100644 --- a/middleware/StateMachine/src/IStateMachine.cpp +++ b/middleware/StateMachine/src/IStateMachine.cpp @@ -3,9 +3,9 @@ * 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. @@ -19,22 +19,18 @@ std::shared_ptr &IStateMachine::GetInstance(std::shared_ptr instance = std::make_shared(); static bool instanceChanging = false; - if (impl && false == instanceChanging) - { + if (impl && false == instanceChanging) { instanceChanging = true; - if (instance.use_count() == 1) - { + if (instance.use_count() == 1) { LogInfo("Instance change succeed.\n"); instance = *impl; } - else - { + else { LogError("Instance change failed, using by some one.\n"); } instanceChanging = false; } - if (instanceChanging) - { + if (instanceChanging) { static std::shared_ptr tmporaryInstance = std::make_shared(); return tmporaryInstance; } diff --git a/middleware/StateMachine/src/OpenHarmony/handler.h b/middleware/StateMachine/src/OpenHarmony/handler.h index 85e13633..ac0ab658 100644 --- a/middleware/StateMachine/src/OpenHarmony/handler.h +++ b/middleware/StateMachine/src/OpenHarmony/handler.h @@ -16,15 +16,16 @@ #ifndef OHOS_HANDLER_H #define OHOS_HANDLER_H -#include #include "internal_message.h" #include "message_queue.h" +#include // namespace OHOS { // namespace Wifi { const int USEC_1000 = 1000; -class Handler { +class Handler +{ public: /** * @Description : Construct a new Handler:: Handler object. diff --git a/middleware/StateMachine/src/OpenHarmony/internal_message.h b/middleware/StateMachine/src/OpenHarmony/internal_message.h index feb740fc..a91fd4b0 100644 --- a/middleware/StateMachine/src/OpenHarmony/internal_message.h +++ b/middleware/StateMachine/src/OpenHarmony/internal_message.h @@ -26,7 +26,8 @@ // namespace OHOS { // namespace Wifi { const int MAX_POOL_SIZE_INIT = 50; -class MessageBody { +class MessageBody +{ public: /** * @Description : Save an Integer Data. @@ -76,7 +77,8 @@ private: std::list stringArray_; }; -class InternalMessage : public VStateMachineData { +class InternalMessage : public VStateMachineData +{ public: /** * @Description : Construct a new Internal Message object. @@ -196,10 +198,7 @@ public: // mMessageObj = T(messageObj); // } - void SetMessageObj(const std::shared_ptr &messageObj) - { - mMessageObj = messageObj; - } + void SetMessageObj(const std::shared_ptr &messageObj) { mMessageObj = messageObj; } /** * @DescriptionGet the Message Obj object @@ -224,10 +223,7 @@ public: // { // return mMessageObj; // } - const std::shared_ptr &GetMessageObj(void) const override - { - return mMessageObj; - } + const std::shared_ptr &GetMessageObj(void) const override { return mMessageObj; } /** * @Description : Release Message Object. @@ -286,7 +282,8 @@ private: /* Message execution time */ int64_t mHandleTime; }; -class MessageManage { +class MessageManage +{ public: /** * @Description : Obtains a single instance. @@ -346,7 +343,8 @@ public: * @param messageObj - Message pointer.[in] * @return InternalMessage* */ - InternalMessage *CreateMessage(int messageName, int param1, int param2, const std::shared_ptr &messageObj); + InternalMessage *CreateMessage(int messageName, int param1, int param2, + const std::shared_ptr &messageObj); /** * @Description :Recycle message. diff --git a/middleware/StateMachine/src/OpenHarmony/message_queue.h b/middleware/StateMachine/src/OpenHarmony/message_queue.h index 290174eb..ad9a34d3 100644 --- a/middleware/StateMachine/src/OpenHarmony/message_queue.h +++ b/middleware/StateMachine/src/OpenHarmony/message_queue.h @@ -16,16 +16,17 @@ #ifndef OHOS_MESSAGE_QUEUE_H #define OHOS_MESSAGE_QUEUE_H +#include "internal_message.h" #include #include #include -#include "internal_message.h" // namespace OHOS { // namespace Wifi { #define TIME_USEC_1000 1000 #define TIME_INTERVAL 30000 -class MessageQueue { +class MessageQueue +{ public: /** * @Description : Construct a new Message Queue object. diff --git a/middleware/StateMachine/src/OpenHarmony/state.h b/middleware/StateMachine/src/OpenHarmony/state.h index 8bcf8d54..a3796ebe 100644 --- a/middleware/StateMachine/src/OpenHarmony/state.h +++ b/middleware/StateMachine/src/OpenHarmony/state.h @@ -16,8 +16,8 @@ #ifndef OHOS_STATE_H #define OHOS_STATE_H -#include #include "message_queue.h" +#include // namespace OHOS { // namespace Wifi { diff --git a/middleware/StateMachine/src/OpenHarmony/state_machine.h b/middleware/StateMachine/src/OpenHarmony/state_machine.h index c73aae66..99b3e995 100644 --- a/middleware/StateMachine/src/OpenHarmony/state_machine.h +++ b/middleware/StateMachine/src/OpenHarmony/state_machine.h @@ -16,12 +16,12 @@ #ifndef OHOS_STA_MACHINE_H #define OHOS_STA_MACHINE_H +#include "IStateMachine.h" +#include "handler.h" +#include "message_queue.h" #include #include #include -#include "handler.h" -#include "message_queue.h" -#include "IStateMachine.h" // namespace OHOS { // namespace Wifi { @@ -140,7 +140,8 @@ public: * @param messageObj - User-defined data * @return InternalMessage* : Pointer to the constructed internal message. */ - InternalMessage *CreateMessage(int msgName, int param1, int param2, const std::shared_ptr &messageObj); + InternalMessage *CreateMessage(int msgName, int param1, int param2, + const std::shared_ptr &messageObj); /** * @Description : Constructs internal messages and places the @@ -246,7 +247,8 @@ public: * @param messageObj -User-defined data * @param delayTimeMs - Delay time, in milliseconds.[in] */ - void MessageExecutedLater(int msgName, const std::shared_ptr &messageObj, int64_t delayTimeMs) override; + void MessageExecutedLater(int msgName, const std::shared_ptr &messageObj, + int64_t delayTimeMs) override; /** * @Description : Constructs internal messages and places them in the @@ -259,7 +261,8 @@ public: * @param messageObj - User-defined data * @param delayTimeMs - Delay time, in milliseconds.[in] */ - void MessageExecutedLater(int msgName, int param1, int param2, const std::shared_ptr &messageObj, int64_t delayTimeMs); + void MessageExecutedLater(int msgName, int param1, int param2, const std::shared_ptr &messageObj, + int64_t delayTimeMs); /** * @Description : Construct a new State Machine:: State Machine object. diff --git a/middleware/StateMachine/src/StateMachineImpl.cpp b/middleware/StateMachine/src/StateMachineImpl.cpp index 3b6d14bd..98a5dfe5 100644 --- a/middleware/StateMachine/src/StateMachineImpl.cpp +++ b/middleware/StateMachine/src/StateMachineImpl.cpp @@ -3,9 +3,9 @@ * 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. diff --git a/middleware/StateMachine/src/StateMachineImpl.h b/middleware/StateMachine/src/StateMachineImpl.h index 12d48af5..b8750546 100644 --- a/middleware/StateMachine/src/StateMachineImpl.h +++ b/middleware/StateMachine/src/StateMachineImpl.h @@ -3,9 +3,9 @@ * 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. diff --git a/middleware/StateMachine/src/StateMachineMakePtr.cpp b/middleware/StateMachine/src/StateMachineMakePtr.cpp index 98e42272..28df1688 100644 --- a/middleware/StateMachine/src/StateMachineMakePtr.cpp +++ b/middleware/StateMachine/src/StateMachineMakePtr.cpp @@ -3,9 +3,9 @@ * 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. @@ -14,16 +14,15 @@ */ #include "StateMachineMakePtr.h" #include "ILog.h" -#include "state_machine.h" #include "IStateMachine.h" #include "StateMachineImpl.h" +#include "state_machine.h" #include bool CreateStateMachine(void) { auto instance = std::make_shared(); StatusCode code = StateMachineMakePtr::GetInstance()->CreateStateMachine(instance); - if (IsCodeOK(code)) - { + if (IsCodeOK(code)) { LogInfo("State machine instance is ok.\n"); IStateMachine::GetInstance(&instance); return true; @@ -33,8 +32,7 @@ bool CreateStateMachine(void) std::shared_ptr &StateMachineMakePtr::GetInstance(std::shared_ptr *impl) { static auto instance = std::make_shared(); - if (impl) - { + if (impl) { instance = *impl; } return instance; @@ -43,8 +41,7 @@ StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr("TODO"); - if (tmp) - { + if (tmp) { stateMachine = std::move(tmp); return CreateStatusCode(STATUS_CODE_OK); } @@ -54,8 +51,7 @@ StatusCode StateMachineMakePtr::CreateStateMachine(std::shared_ptr &instance) { auto tmp = std::make_shared(); - if (tmp) - { + if (tmp) { instance = std::move(tmp); return CreateStatusCode(STATUS_CODE_OK); } diff --git a/middleware/StateMachine/src/StateMachineMakePtr.h b/middleware/StateMachine/src/StateMachineMakePtr.h index 7a8d420d..797bfc41 100644 --- a/middleware/StateMachine/src/StateMachineMakePtr.h +++ b/middleware/StateMachine/src/StateMachineMakePtr.h @@ -3,9 +3,9 @@ * 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. @@ -14,8 +14,8 @@ */ #ifndef STATE_MACHINE_MAKE_PTR_H #define STATE_MACHINE_MAKE_PTR_H -#include "StatusCode.h" #include "IStateMachine.h" +#include "StatusCode.h" #include class StateMachineMakePtr { diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 8a312530..a8dd921e 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -4,4 +4,3 @@ add_subdirectory(Config) add_subdirectory(StatusCode) add_subdirectory(Log) add_subdirectory(SharedData) -add_subdirectory(SharedMemory)