refactor: migrate MICRO_PIP to fine-grained feature flags

Replace monolithic MICRO_PIP/PIP_MICRO with granular flags:

Feature flags (CMake options + platform auto-detection):
- PIP_NO_FILESYSTEM, PIP_NO_THREADS, PIP_NO_SOCKET
- PIP_NO_PROCESS, PIP_NO_DYNLIB, PIP_NO_FFT, PIP_NO_SERIAL

Embedded optimization flag:
- PIP_EMBEDDED (auto-set for Pico SDK and FreeRTOS)
  Controls buffer sizes, time stubs, terminal fallback, init stubs

Platform blocks in CMakeLists.txt:
- Pico SDK: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL;
  conditionally disables THREADS (no FreeRTOS) and SOCKET (no LWIP)
- FreeRTOS: auto-disables FS, PROCESS, DYNLIB, FFT, SERIAL;
  conditionally disables SOCKET (no LWIP)
- Android: auto-disables PROCESS, DYNLIB, FFT

Updated 96 files across libs/, utils/, tests/, and CMakeLists.txt.
Builds verified for Linux (547 tests pass) and Pico SDK (100%).
Removed all MICRO_PIP and PIP_MICRO references (0 remaining).
This commit is contained in:
2026-08-11 14:34:59 +03:00
parent 87c53d45a4
commit 4d8b743075
97 changed files with 1555 additions and 914 deletions
+14 -9
View File
@@ -1,6 +1,6 @@
/*
PIP - Platform Independent Primitives
High-level log
High-level log
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
@@ -24,6 +24,8 @@
#include "piliterals_time.h"
#include "pitime.h"
#ifndef PIP_NO_THREADS
# ifndef PIP_NO_FILESYSTEM
//! \class PILog pilog.h
//! \details
@@ -124,12 +126,12 @@ PIStringList PILog::readAllLogs() const {
auto it = names.makeIterator();
bool was_own = false;
auto readFile = [&ret](PIFile * f) {
PIIOTextStream ts(f);
PIString line;
while (!ts.isEnd()) {
line = ts.readLine().trim();
if (line.isNotEmpty()) ret << line;
}
PIIOTextStream ts(f);
PIString line;
while (!ts.isEnd()) {
line = ts.readLine().trim();
if (line.isNotEmpty()) ret << line;
}
};
while (it.next()) {
PIFile * f = nullptr;
@@ -203,8 +205,8 @@ void PILog::newFile() {
PIString aname = log_name;
if (aname.isNotEmpty()) aname += "__";
log_file.open(log_dir + "/" + aname + PIDateTime::current().toString("yyyy_MM_dd__hh_mm_ss") + ".log." +
PIString::fromNumber(++part_number),
PIIODevice::ReadWrite);
PIString::fromNumber(++part_number),
PIIODevice::ReadWrite);
}
@@ -245,3 +247,6 @@ void PILog::run() {
}
}
}
# endif // PIP_NO_FILESYSTEM
#endif // PIP_NO_THREADS
+7 -1
View File
@@ -29,6 +29,9 @@
#include "piiostream.h"
#include "pithread.h"
#ifndef PIP_NO_THREADS
# ifndef PIP_NO_FILESYSTEM
//! \~\ingroup Application
//! \~\brief
//! \~english High-level log
@@ -184,4 +187,7 @@ private:
int part_number = -1, cout_id = -1;
};
#endif
# endif // PIP_NO_FILESYSTEM
#endif // PIP_NO_THREADS
#endif // PIlog_H
@@ -24,6 +24,7 @@
#include "pisharedmemory.h"
#include "pitime.h"
#ifndef PIP_NO_THREADS
//! \class PISingleApplication pisingleapplication.h
//! \~\details
@@ -64,7 +65,7 @@
//!
#define SHM_SIZE 32_KiB
# define SHM_SIZE 32_KiB
PISingleApplication::PISingleApplication(const PIString & app_name): PIThread() {
@@ -150,3 +151,5 @@ void PISingleApplication::waitFirst() const {
while (!started)
piMSleep(50);
}
#endif // PIP_NO_THREADS
@@ -29,6 +29,8 @@
class PISharedMemory;
#ifndef PIP_NO_THREADS
//! \~\ingroup Application
//! \~\brief
//! \~english Single-instance application control.
@@ -92,4 +94,5 @@ private:
int sacnt;
};
#endif // PIP_NO_THREADS
#endif // PISINGLEAPPLICATION_H
+56 -53
View File
@@ -40,6 +40,7 @@ struct kqueue_id_t;
# include "esp_heap_caps.h"
#endif
#ifndef PIP_NO_THREADS
void PISystemMonitor::ProcessStats::makeStrings() {
physical_memsize_readable.setReadableSize(physical_memsize);
@@ -50,43 +51,43 @@ void PISystemMonitor::ProcessStats::makeStrings() {
}
#ifndef MICRO_PIP
# ifndef PIP_NO_PROCESS
PRIVATE_DEFINITION_START(PISystemMonitor)
# ifndef WINDOWS
# ifdef MAC_OS
# ifndef WINDOWS
# ifdef MAC_OS
PISystemTime
# else
# else
llong
# endif
# endif
cpu_u_cur,
cpu_u_prev, cpu_s_cur, cpu_s_prev;
PIString proc_dir;
PIFile file, filem;
# else
# else
HANDLE hProc;
PROCESS_MEMORY_COUNTERS mem_cnt;
PISystemTime tm_kernel, tm_user;
PITimeMeasurer tm;
# endif
# endif
PRIVATE_DEFINITION_END(PISystemMonitor)
#endif
# endif // PIP_NO_PROCESS
PISystemMonitor::PISystemMonitor(): PIThread() {
pID_ = cycle = 0;
cpu_count = PISystemInfo::instance()->processorsCount;
#ifndef MICRO_PIP
# ifndef WINDOWS
# ifdef QNX
# ifndef PIP_NO_PROCESS
# ifndef WINDOWS
# ifdef QNX
page_size = 4096;
# else
# else
page_size = getpagesize();
# endif
# else
# endif
# else
PRIVATE->hProc = 0;
PRIVATE->mem_cnt.cb = sizeof(PRIVATE->mem_cnt);
# endif
#endif
# endif
# endif // PIP_NO_PROCESS
setName("system_monitor"_a);
}
@@ -96,14 +97,14 @@ PISystemMonitor::~PISystemMonitor() {
}
#ifndef MICRO_PIP
# ifndef PIP_NO_PROCESS
bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
stop();
pID_ = pID;
Pool::instance()->add(this);
cycle = -1;
# ifndef WINDOWS
# ifndef MAC_OS
# ifndef WINDOWS
# ifndef MAC_OS
PRIVATE->proc_dir = PIStringAscii("/proc/") + PIString::fromNumber(pID_) + PIStringAscii("/");
PRIVATE->file.open(PRIVATE->proc_dir + "stat", PIIODevice::ReadOnly);
PRIVATE->filem.open(PRIVATE->proc_dir + "statm", PIIODevice::ReadOnly);
@@ -111,27 +112,27 @@ bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
piCoutObj << "Can`t find process with ID = %1!"_tr("PISystemMonitor").arg(pID_);
return false;
}
# endif
# else
# endif
# else
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
if (PRIVATE->hProc == 0) {
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
return false;
}
PRIVATE->tm.reset();
# endif
# endif
return start(interval);
}
#endif
# endif // PIP_NO_PROCESS
bool PISystemMonitor::startOnSelf(PISystemTime interval) {
#ifndef MICRO_PIP
# ifndef PIP_NO_PROCESS
bool ret = startOnProcess(PIProcess::currentPID(), interval);
cycle = -1;
#else
# else
bool ret = start(interval);
#endif
# endif // PIP_NO_PROCESS
return ret;
}
@@ -153,12 +154,12 @@ void PISystemMonitor::setStatistic(const PISystemMonitor::ProcessStats & s) {
void PISystemMonitor::stop() {
PIThread::stopAndWait();
#ifdef WINDOWS
# ifdef WINDOWS
if (PRIVATE->hProc != 0) {
CloseHandle(PRIVATE->hProc);
PRIVATE->hProc = 0;
}
#endif
# endif
Pool::instance()->remove(this);
}
@@ -169,18 +170,18 @@ PISystemMonitor::ProcessStats PISystemMonitor::statistic() const {
}
#ifdef MAC_OS
# ifdef MAC_OS
PISystemTime uint64toST(uint64_t v) {
return PISystemTime(((uint *)&(v))[1], ((uint *)&(v))[0]);
}
#endif
# endif
void PISystemMonitor::run() {
cur_tm.clear();
tbid.clear();
ProcessStats tstat;
tstat.ID = pID_;
#ifndef PIP_NO_THREADS
# ifndef PIP_NO_THREADS
__PIThreadCollection * pitc = __PIThreadCollection::instance();
pitc->lock();
PIVector<PIThread *> tv = pitc->threads();
@@ -188,14 +189,14 @@ void PISystemMonitor::run() {
if (t->isPIObject()) tbid[t->tid()] = t->name();
pitc->unlock();
// piCout << tbid.keys().toType<uint>();
# ifdef FREERTOS
# ifdef FREERTOS
for (auto * t: tv)
if (t->isPIObject()) gatherThread(t->tid());
# else // FREERTOS
# ifndef WINDOWS
# else // FREERTOS
# ifndef WINDOWS
double delay_ms = delay_.toMilliseconds();
tbid[pID_] = "main";
# ifdef MAC_OS
# ifdef MAC_OS
rusage_info_current ru;
proc_pid_rusage(pID_, RUSAGE_INFO_CURRENT, (rusage_info_t *)&ru);
// piCout << PISystemTime(((uint*)&(ru.ri_user_time))[1], ((uint*)&(ru.ri_user_time))[0]);
@@ -211,7 +212,7 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 100.f * (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
cycle = 0;
// piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
# else // MAC_OS
# else // MAC_OS
PRIVATE->file.seekToBegin();
PIString str = PIString::fromAscii(PRIVATE->file.readAll());
int si = str.find('(') + 1, fi = 0, cc = 1;
@@ -265,8 +266,8 @@ void PISystemMonitor::run() {
if (i.flags[PIFile::FileInfo::Dot] || i.flags[PIFile::FileInfo::DotDot]) continue;
gatherThread(i.name().toInt());
}
# endif // MAC_OS
# else // WINDOWS
# endif // MAC_OS
# else // WINDOWS
if (GetProcessMemoryInfo(PRIVATE->hProc, &PRIVATE->mem_cnt, sizeof(PRIVATE->mem_cnt)) != 0) {
tstat.physical_memsize = PRIVATE->mem_cnt.WorkingSetSize;
}
@@ -316,9 +317,9 @@ void PISystemMonitor::run() {
tstat.cpu_load_user = 0.f;
}
PRIVATE->tm.reset();
# endif // WINDOWS
# endif // FREERTOS
#endif // PIP_NO_THREADS
# endif // WINDOWS
# endif // FREERTOS
# endif // PIP_NO_THREADS
tstat.cpu_load_system = piClampf(tstat.cpu_load_system, 0.f, 100.f);
tstat.cpu_load_user = piClampf(tstat.cpu_load_user, 0.f, 100.f);
@@ -351,11 +352,11 @@ void PISystemMonitor::gatherThread(llong id) {
PISystemMonitor::ThreadStats ts;
if (id == 0) return;
ts.id = id;
#ifdef MICRO_PIP
# ifdef PIP_NO_PROCESS
ts.name = tbid.value(id, "<PIThread>");
#else
# else
ts.name = tbid.value(id, "<non-PIThread>");
# ifndef WINDOWS
# ifndef WINDOWS
PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat");
// piCout << f.path();
if (!f.open(PIIODevice::ReadOnly)) return;
@@ -375,7 +376,7 @@ void PISystemMonitor::gatherThread(llong id) {
// piCout << sl[0] << sl[12] << sl[13];
ts.user_time = PISystemTime::fromMilliseconds(sl[12].toInt() * 10.);
ts.kernel_time = PISystemTime::fromMilliseconds(sl[13].toInt() * 10.);
# else
# else
PISystemTime ct = PISystemTime::current();
FILETIME times[4];
HANDLE thdl = OpenThread(THREAD_QUERY_INFORMATION, FALSE, DWORD(id));
@@ -393,8 +394,8 @@ void PISystemMonitor::gatherThread(llong id) {
ts.work_time = ct - ts.created.toSystemTime();
ts.kernel_time = FILETIME2PISystemTime(times[2]);
ts.user_time = FILETIME2PISystemTime(times[3]);
# endif
#endif
# endif
# endif // PIP_NO_PROCESS
cur_tm[id] = ts;
}
@@ -406,34 +407,34 @@ float PISystemMonitor::calcThreadUsage(PISystemTime & t_new, PISystemTime & t_ol
ullong PISystemMonitor::totalRAM() {
#ifdef ESP_PLATFORM
# ifdef ESP_PLATFORM
multi_heap_info_t heap_info;
piZeroMemory(heap_info);
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
return heap_info.total_allocated_bytes + heap_info.total_free_bytes;
#endif
# endif
return 0;
}
ullong PISystemMonitor::freeRAM() {
#ifdef ESP_PLATFORM
# ifdef ESP_PLATFORM
multi_heap_info_t heap_info;
piZeroMemory(heap_info);
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
return heap_info.total_free_bytes;
#endif
# endif
return 0;
}
ullong PISystemMonitor::usedRAM() {
#ifdef ESP_PLATFORM
# ifdef ESP_PLATFORM
multi_heap_info_t heap_info;
piZeroMemory(heap_info);
heap_caps_get_info(&heap_info, MALLOC_CAP_8BIT);
return heap_info.total_allocated_bytes;
#endif
# endif
return 0;
}
@@ -460,3 +461,5 @@ void PISystemMonitor::Pool::remove(PISystemMonitor * sm) {
PIMutexLocker _ml(mutex);
sysmons.remove(sm->pID());
}
#endif // PIP_NO_THREADS
+8 -6
View File
@@ -28,6 +28,7 @@
#include "pifile.h"
#include "pithread.h"
#ifndef PIP_NO_THREADS
//! \~\ingroup Application
//! \~\brief
@@ -51,7 +52,7 @@ public:
//! \~russian Останавливает мониторинг и отсоединяет объект от текущей цели.
~PISystemMonitor();
#pragma pack(push, 1)
# pragma pack(push, 1)
//! \~\ingroup Application
//! \~\brief
//! \~english Process statistics (fixed-size fields).
@@ -155,7 +156,7 @@ public:
//! \~russian Дата и время создания
PIDateTime created;
};
#pragma pack(pop)
# pragma pack(pop)
//! \~\ingroup Application
//! \~\brief
@@ -205,12 +206,12 @@ public:
PIString name;
};
#ifndef MICRO_PIP
# ifndef PIP_NO_PROCESS
//! \~english Starts monitoring the process with PID "pID" using the given update interval.
//! \~russian Запускает мониторинг процесса с PID "pID" с указанным интервалом обновления.
bool startOnProcess(int pID, PISystemTime interval = PISystemTime::fromSeconds(1.));
#endif
# endif // PIP_NO_PROCESS
//! \~english Starts monitoring the current application process.
//! \~russian Запускает мониторинг текущего процесса приложения.
@@ -271,9 +272,9 @@ private:
PIMap<llong, PIString> tbid;
mutable PIMutex stat_mutex;
int pID_, page_size, cpu_count, cycle;
#ifndef MICRO_PIP
# ifndef PIP_NO_PROCESS
PRIVATE_DECLARATION(PIP_EXPORT)
#endif
# endif // PIP_NO_PROCESS
class PIP_EXPORT Pool {
friend class PISystemMonitor;
@@ -337,4 +338,5 @@ BINARY_STREAM_READ(PISystemMonitor::ThreadStats) {
return s;
}
#endif // PIP_NO_THREADS
#endif // PISYSTEMMONITOR_H
+7 -4
View File
@@ -1,6 +1,6 @@
/*
PIP - Platform Independent Primitives
Translation support
Translation support
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
@@ -25,6 +25,7 @@
#include "pitranslator_p.h"
#include "pivaluetree_conversions.h"
#ifndef PIP_NO_FILESYSTEM
//! \class PITranslator pitranslator.h
//! \details
@@ -64,9 +65,9 @@ void PITranslator::loadLang(const PIString & short_lang, PIString dir) {
auto vt = PIValueTreeConversions::fromText(getBuiltinConfig());
auto lang = vt.child(short_lang.toLowerCase().trim());
for (const auto & cn: lang.children()) {
auto c = s->PRIVATEWB->content.createContext(cn.name());
for (const auto & s: cn.children())
c->add(s.name(), s.value().toString());
auto c = s->PRIVATEWB->content.createContext(cn.name());
for (const auto & s: cn.children())
c->add(s.name(), s.value().toString());
}*/
}
@@ -114,3 +115,5 @@ PITranslator * PITranslator::instance() {
static PITranslator ret;
return &ret;
}
#endif // PIP_NO_FILESYSTEM