File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ cmake_minimum_required (VERSION 3.10 )
2+ project (system_core)
3+
4+ set (CMAKE_CXX_STANDARD 17)
5+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
6+
7+ # Platform-specific settings
8+ if (WIN32 )
9+ add_definitions (-DBUILDING_DLL )
10+ add_definitions (-D_CRT_SECURE_NO_WARNINGS )
11+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
12+ set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR} )
13+ endif ()
14+
15+ # Source files
16+ set (SOURCES
17+ src/system_core.cpp
18+ src/process_monitor.cpp
19+ )
20+
21+ # Include directories
22+ include_directories (include )
23+
24+ # Create shared library
25+ add_library (system_core SHARED ${SOURCES} )
26+
27+ # Platform-specific libraries
28+ if (WIN32 )
29+ target_link_libraries (system_core
30+ psapi
31+ kernel32
32+ user32
33+ gdi32
34+ winspool
35+ shell32
36+ ole32
37+ oleaut32
38+ uuid
39+ comdlg32
40+ advapi32
41+ )
42+ endif ()
43+
44+ # Installation
45+ install (TARGETS system_core
46+ LIBRARY DESTINATION lib
47+ RUNTIME DESTINATION bin
48+ ARCHIVE DESTINATION lib
49+ )
50+
51+ install (DIRECTORY include/ DESTINATION include)
Original file line number Diff line number Diff line change 1+ This is Folder (Demo or Beta)
Original file line number Diff line number Diff line change 1+ #ifndef PROCESS_MONITOR_H
2+ #define PROCESS_MONITOR_H
3+
4+ #include < string>
5+ #include < vector>
6+ #include < thread>
7+ #include < atomic>
8+ #include < mutex>
9+
10+ class ProcessMonitor {
11+ public:
12+ ProcessMonitor ();
13+ ~ProcessMonitor ();
14+
15+ void start ();
16+ void stop ();
17+
18+ double get_cpu_usage () const ;
19+ double get_memory_usage () const ;
20+ std::vector<std::string> get_active_processes () const ;
21+ bool limit_cpu_usage (int percentage);
22+
23+ private:
24+ void monitoring_thread ();
25+ void update_system_stats ();
26+
27+ std::atomic<bool > running_;
28+ std::thread monitor_thread_;
29+ mutable std::mutex data_mutex_;
30+
31+ double cpu_usage_;
32+ double memory_usage_mb_;
33+ std::vector<std::string> active_processes_;
34+
35+ // Platform-specific implementations
36+ void update_stats_windows ();
37+ void update_stats_linux ();
38+ void update_stats_macos ();
39+
40+ std::vector<std::string> get_processes_windows () const ;
41+ std::vector<std::string> get_processes_linux () const ;
42+ std::vector<std::string> get_processes_macos () const ;
43+
44+ // CPU limiting
45+ bool set_cpu_limit_windows (int percentage);
46+ bool set_cpu_limit_linux (int percentage);
47+ bool set_cpu_limit_macos (int percentage);
48+ };
49+
50+ #endif // PROCESS_MONITOR_H
Original file line number Diff line number Diff line change 1+
2+ #ifndef SYSTEM_CORE_H
3+ #define SYSTEM_CORE_H
4+
5+ #ifdef __cplusplus
6+ extern "C" {
7+ #endif
8+
9+ #ifdef _WIN32
10+ #ifdef BUILDING_DLL
11+ #define DLL_EXPORT __declspec(dllexport)
12+ #else
13+ #define DLL_EXPORT __declspec(dllimport)
14+ #endif
15+ #else
16+ #define DLL_EXPORT
17+ #endif
18+
19+ /**
20+ * @brief Start system resource monitoring
21+ */
22+ DLL_EXPORT void start_monitoring ();
23+
24+ /**
25+ * @brief Stop system resource monitoring
26+ */
27+ DLL_EXPORT void stop_monitoring ();
28+
29+ /**
30+ * @brief Get current CPU usage percentage
31+ * @return CPU usage as double (0-100)
32+ */
33+ DLL_EXPORT double get_cpu_usage ();
34+
35+ /**
36+ * @brief Get current memory usage in MB
37+ * @return Memory usage in megabytes
38+ */
39+ DLL_EXPORT double get_memory_usage ();
40+
41+ /**
42+ * @brief Get list of active processes
43+ * @return Array of process names, terminated by NULL
44+ */
45+ DLL_EXPORT char * * get_active_processes ();
46+
47+ /**
48+ * @brief Free memory allocated for process list
49+ * @param processes Array of process names
50+ */
51+ DLL_EXPORT void free_process_list (char * * processes );
52+
53+ /**
54+ * @brief Limit CPU usage for child processes
55+ * @param percentage Maximum CPU percentage (0-100)
56+ * @return 0 on success, -1 on error
57+ */
58+ DLL_EXPORT int limit_cpu_usage (int percentage );
59+
60+ #ifdef __cplusplus
61+ }
62+ #endif
63+
64+ #endif // SYSTEM_CORE_H
You can’t perform that action at this time.
0 commit comments