Skip to content

Commit

Permalink
add userdata
Browse files Browse the repository at this point in the history
  • Loading branch information
Forairaaaaa committed Apr 9, 2024
1 parent ca730b9 commit 52ce991
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions example/framework/app_internal_api_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
#include <iostream>
#include <mooncake.h>
#include <string>

using namespace MOONCAKE;

Expand All @@ -22,6 +23,7 @@ class App_1111 : public APP_BASE
{
/* Frame work define wrap */
std::cout << mcAppGetFramework()->getInstalledAppList()[0]->getAppName() << "\n";
std::cout << (const char*)mcAppGetFramework()->getUserData() << "\n";
}
};
/* Create a new app packer with new resource and memory manager */
Expand All @@ -41,6 +43,9 @@ int main()
Mooncake mooncake;
mooncake.init();

std::string hi = "hi im fine, thank you";
mooncake.setUserData((void*)hi.c_str());

mooncake.installApp(new App_1111_packer);
mooncake.createApp(mooncake.getInstalledAppList()[0]);

Expand Down
7 changes: 7 additions & 0 deletions src/mooncake.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace MOONCAKE
{
APP_Register* app_register = nullptr;
APP_Manager* app_manager = nullptr;
void* user_data = nullptr;
};
Data_t _data;
void _free_components();
Expand All @@ -48,6 +49,12 @@ namespace MOONCAKE
inline APP_Register* getAppRegister() { return _data.app_register; }
inline APP_Manager* getAppManager() { return _data.app_manager; }

/* -------------------------------- User data ------------------------------- */
// Can be your database or anything
public:
inline void setUserData(void* userData) { _data.user_data = userData; }
inline void* getUserData() { return _data.user_data; }

/* ----------------------------- Framework apis ----------------------------- */
public:
/**
Expand Down

0 comments on commit 52ce991

Please sign in to comment.