Skip to content

Commit

Permalink
add app layer and helper apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Forairaaaaa committed Jul 23, 2024
1 parent dc9ff48 commit 48caa66
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/app/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
*/
#pragma once
#include <cstdint>

namespace MOONCAKE
{
Expand Down Expand Up @@ -83,6 +84,9 @@ namespace MOONCAKE
private:
APP_PACKER_BASE* _app_packer;

// A layer for distinguish, like normal apps and daemon apps
std::uint8_t _app_layer;

// Internal state
struct State_t
{
Expand All @@ -94,7 +98,7 @@ namespace MOONCAKE
State_t _state;

public:
APP_BASE() : _app_packer(nullptr) {}
APP_BASE() : _app_packer(nullptr), _app_layer(0) {}
virtual ~APP_BASE() {}

/* -------------------- static asset getting and setting -------------------- */
Expand All @@ -116,6 +120,11 @@ namespace MOONCAKE
inline void resetGoingCloseFlag() { _state.go_close = false; }
inline void resetGoingDestroyFlag() { _state.go_destroy = false; }

/* -------------------------------- App layer ------------------------------- */
public:
inline void setAppLayer(const std::uint8_t& appLayer) { _app_layer = appLayer; }
inline const std::uint8_t& getAppLayer() { return _app_layer; }

/* --------------- Apis to controls lifecycle inside your app --------------- */
protected:
/**
Expand Down
14 changes: 14 additions & 0 deletions src/app/app_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,17 @@ void APP_Manager::destroyAllApps()
_app_lifecycle_list.clear();
_app_create_buffer.clear();
}

std::size_t APP_Manager::getCreatedAppNumByLayer(const std::uint8_t& appLayer)
{
std::size_t ret = 0;

/* Iterate the shit out */
for (auto& i : _app_lifecycle_list)
{
if (i.app->getAppLayer() == appLayer)
ret++;
}

return ret;
}
8 changes: 8 additions & 0 deletions src/app/app_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,13 @@ namespace MOONCAKE
* @return const std::vector<AppLifecycle_t>*
*/
inline const std::vector<AppLifecycle_t>* getAppLifecycleList() { return &_app_lifecycle_list; }

/**
* @brief Get created app num in app manager in specific app layer
*
* @param appLayer
* @return std::size_t
*/
std::size_t getCreatedAppNumByLayer(const std::uint8_t& appLayer);
};
} // namespace MOONCAKE
21 changes: 19 additions & 2 deletions src/mooncake.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ namespace MOONCAKE
*/
void update();

/* -------------------------------------------------------------------------- */
/* App register wrap */
/* -------------------------------------------------------------------------- */
public:
/**
* @brief Install an app (Register an app packer)
*
Expand Down Expand Up @@ -118,8 +122,10 @@ namespace MOONCAKE
return _data.app_register->getInstalledAppByName(appName);
}

/* Framework wrap to the App manager */

/* -------------------------------------------------------------------------- */
/* App manager warp */
/* -------------------------------------------------------------------------- */
public:
/**
* @brief Create an app
*
Expand Down Expand Up @@ -176,5 +182,16 @@ namespace MOONCAKE
* @return std::size_t
*/
inline std::size_t getCreatedAppNum() { return _data.app_manager->getCreatedAppNum(); }

/**
* @brief Get created app num in app manager in specific app layer
*
* @param appLayer
* @return std::size_t
*/
inline std::size_t getCreatedAppNumByLayer(const std::uint8_t& appLayer)
{
return _data.app_manager->getCreatedAppNumByLayer(appLayer);
}
};
} // namespace MOONCAKE

0 comments on commit 48caa66

Please sign in to comment.