31 std::map<uint32, TimeQueueSchedule*>::iterator it, itEnd;
32 for (it = schedules.begin(), itEnd = schedules.end(); it!=itEnd; it++)
40 if (schedules[schedule->
id]) {
44 schedules[schedule->
id] = schedule;
46 return timer->addTimer(schedule->
id, schedule->
interval, schedule->
start, schedule->
end);
56 timer->removeTimer(
id);
67 if (!timer->waitForTimer(ms,
id, time))
93 masterCreatedTime = 0;
95 this->isAdHoc = isAdHoc;
100 this->isLocal = isLocal;
101 this->procID = procID;
102 finishedShuttingDown =
false;
104 memset(waitCounters, 0, 3*
sizeof(uint32));
105 memset(procCounters, 0, 3*
sizeof(uint32));
107 threadPoolWaitLowerThreshold = 5;
108 threadPoolWaitUpperThreshold = 20;
109 threadPoolWaitIncrement = 5;
111 threadPoolCheckInterval = 5000;
132 if (timeQ)
delete(timeQ);
140 this->isMaster = isMaster;
145 if (!
manager->connect(systemID, isMaster)) {
151 finishedShuttingDown =
false;
155 if (!
manager->processMemory->getProcessID(name.c_str(), checkID)) {
161 else if (procID != checkID) {
162 LogPrint(0,
LOG_SPACE, 0,
"Process ID '%u' does not match shared memory id '%u'...", procID, checkID);
167 if (
manager->processMemory->getProcessID(name.c_str(), checkID) && checkID) {
171 if (!
manager->processMemory->createNewProcess(name.c_str(), procID)) {
172 LogPrint(0,
LOG_SPACE, 0,
"PsySpace couldn't connect to local Node %u...", systemID);
180 if (!
manager->processMemory->addToCmdQ(0, msg)) {
181 LogPrint(procID,
LOG_SPACE, 0,
"Could not communicate with System Command Queue...");
193 manager->processMemory->setProcessCommandLine(procID, cmdline);
199 if (!
manager->processMemory->addToCmdQ(0, msg)) {
200 LogPrint(procID,
LOG_SPACE, 0,
"Could not communicate with System Command Queue...");
214 manager->getNodeStatus(lastSeen, masterCreatedTime);
231 uint64 lastSeen, createTime;
232 uint8 status =
manager->getNodeStatus(lastSeen, createTime);
233 if (masterCreatedTime && (createTime != masterCreatedTime)) {
234 LogPrint(procID,
LOG_SPACE, 0,
"Psyclone Node process appears to have restarted...");
239 LogPrint(procID,
LOG_SPACE, 0,
"Psyclone Node process doesn't appear to be running...");
244 LogPrint(procID,
LOG_SPACE, 0,
"Psyclone Node process appears to have stopped, resetting connection...");
254static std::multiset<PsySpace*>&
ShutdownInProgress() {
static std::multiset<PsySpace*>* s =
new std::multiset<PsySpace*>();
return *s; }
271 for (uint32 w = 0;
manager && w < 600; w++) {
272 threadPoolMutex.enter(1000, __FUNCTION__);
273 size_t left = threadPool.size();
274 threadPoolMutex.leave();
282 std::map<std::string, utils::Library*>::iterator it = libraries.begin(), itEnd = libraries.end();
284 delete((it++)->second);
287 std::map<uint32, PsyAPI*>::iterator ait = psyAPIs.begin(), aitEnd = psyAPIs.end();
288 while (ait != aitEnd)
289 delete((ait++)->second);
292 std::map<PsyType, SignalStruct*>::iterator sit = signalList.begin(), sitEnd = signalList.end();
293 while (sit != sitEnd) {
294 delete(sit->second->lastSignalMsg);
295 delete((sit++)->second);
303 LogPrint(procID,
LOG_SPACE, 1,
"PsySpace '%s' (%u) starting up...", name.c_str(), procID);
304 return setThreadPoolSize(threadCount);
308 if (finishedShuttingDown)
310 finishedShuttingDown =
true;
315 LogPrint(procID,
LOG_SPACE, 1,
"PsySpace '%s' (%u) shutting down...", name.c_str(), procID);
318 if (!
manager->processMemory->addToCmdQ(0, msg)) {
319 LogPrint(procID,
LOG_SPACE, 0,
"Could not communicate with System Command Queue...");
326 std::map<uint32, PsyAPI*>::iterator it, itEnd;
327 for (it=psyAPIs.begin(), itEnd=psyAPIs.end(); it != itEnd; it++)
335 uint32 maxWaitCount = 200;
337 threadPoolMutex.enter(1000, __FUNCTION__);
338 size_t left = threadPool.size();
339 threadPoolMutex.leave();
342 if (!(--maxWaitCount)) {
343 threadPoolMutex.enter(1000, __FUNCTION__);
344 std::map<uint32, uint8> remaining = threadPool;
346 threadPoolMutex.leave();
347 LogPrint(procID,
LOG_SPACE, 0,
"PsySpace '%s' waited for the last %u threads to terminate, killing threads now...", name.c_str(), (uint32)remaining.size());
348 for (std::map<uint32, uint8>::iterator threadI = remaining.begin(); threadI != remaining.end(); threadI++) {
350 LogPrint(procID,
LOG_SPACE, 0,
"PsySpace '%s' couldn't kill thread %u...", name.c_str(), threadI->first);
352 LogPrint(procID,
LOG_SPACE, 0,
"PsySpace '%s' killed thread %u...", name.c_str(), threadI->first);
358 LogPrint(procID,
LOG_SPACE,0,
"PsySpace '%s' waiting for the main thread to terminate...", name.c_str());
363 LogPrint(procID,
LOG_SPACE, 0,
"PsySpace '%s' has shut down (%u, %p)", name.c_str(), procID,
this);
368 return finishedShuttingDown;
376 manager->processMemory->addToCmdQ(0, msg);
387 msg->
setData(
"LogEntry", (
char*)entry, entry->
size);
388 manager->processMemory->addToCmdQ(0, msg);
402bool PsySpace::setThreadPoolSize(uint16 threadCount) {
406 int32 c = threadCount - (uint32)threadPool.size();
407 threadTarget = threadCount;
412 c, (uint32)threadPool.size(), threadCount);
414 for (n=0; n<c; n++) {
427 if (!
manager->dataMapsMemory->getCrankID(name, crankID) || !crankID)
430 uint32 compID =
manager->dataMapsMemory->getCrankCompID(crankID);
434 uint16 oldCompNodeID =
manager->componentMemory->getComponentNodeID(compID);
438 if (!pullRemoteComponentData(compID, oldCompNodeID))
441 if (!threadPoolMutex.enter(1000, __FUNCTION__))
443 if (!(api = psyAPIs[crankID])) {
446 api->currentCompID = compID;
447 psyAPIs[crankID] = api;
449 threadPoolMutex.leave();
455 if (!
manager->dataMapsMemory->getCrankID(name, crankID) || !crankID)
457 if (!threadPoolMutex.enter(1000, __FUNCTION__))
459 cranks[crankID] = func;
460 threadPoolMutex.leave();
465 if (!name || !*name || !func)
467 if (!threadPoolMutex.enter(1000, __FUNCTION__))
469 internalCranks[name] = func;
470 threadPoolMutex.leave();
476 if (
manager->componentMemory->getComponentID(name, compID))
482bool PsySpace::pullRemoteComponentData(uint32 compID, uint16 fromNodeID) {
484 msg->
setInt(
"CompID", compID);
485 msg->
setInt(
"ProcID", this->procID);
486 msg->
setInt(
"NodeID", fromNodeID);
488 uint8 result =
query(msg, &resultMsg, 5000);
518 uint64 eol = msg->
getEOL();
519 if (eol && (eol < msg->getCreatedTime() - 10000))
522 if (!
manager->insertMessage(msg, memID)) {
528 if (!
manager->processMemory->addToMsgQ(0, msg)) {
529 LogPrint(procID,
LOG_SPACE, 0,
"Could not communicate with System Message Queue...");
532 manager->processMemory->addToProcessStats(procID, NULL, msg);
541 if (!signalsMutex.enter(3000, __FUNCTION__))
547 signalList[type] = signal;
549 signalsMutex.leave();
551 if (signal->
mutex.
enter(3000, __FUNCTION__)) {
563 if (!
manager->processMemory->addToAllSignalQsExcept(msg, procID)) {
564 LogPrint(procID,
LOG_SPACE, 0,
"Could not communicate with All Signal Queues...");
567 manager->processMemory->addToProcessStats(procID, NULL, msg);
573 if (!signalsMutex.enter(3000, __FUNCTION__))
579 signalList[type] = signal;
581 signalsMutex.leave();
585 if (lastReceivedTime) {
586 if (signal->
mutex.
enter(3000, __FUNCTION__)) {
592 manager->processMemory->addToProcessStats(procID, msg, NULL);
615 if (lastReceivedTime) {
629 manager->processMemory->addToProcessStats(procID, msg, NULL);
639 uint32 to = msg->
getTo();
642 if (!
manager->dataMapsMemory->createNewRequest(msg->
getFrom(), to, 0, reqID))
647 manager->processMemory->addToProcessStats(procID, NULL, msg);
649 uint16 otherNodeID = 0;
650 uint16 otherProcID = 0;
654 if (!
manager->processMemory->addToReqQ(0, msg)) {
655 manager->dataMapsMemory->deleteRequest(reqID);
660 if (!
manager->componentMemory->getComponentLocation(to, otherNodeID, otherProcID))
663 if (otherNodeID !=
manager->getNodeID()) {
665 if (!
manager->processMemory->addToReqQ(0, msg)) {
666 manager->dataMapsMemory->deleteRequest(reqID);
672 otherProcID =
manager->componentMemory->getComponentProcessID(to);
673 if (!
manager->processMemory->addToReqQ(otherProcID, msg)) {
674 manager->dataMapsMemory->deleteRequest(reqID);
684 if (!
manager->dataMapsMemory->waitForRequestReply(reqID, timeout, status, time, msgID, msgEOL)) {
685 LogPrint(procID,
LOG_SPACE,0,
"Request reply timeout (%u) from node %u (req %u from comp %u)...",
686 status, otherNodeID, reqID, msg->
getFrom());
687 manager->dataMapsMemory->deleteRequest(reqID);
690 manager->dataMapsMemory->deleteRequest(reqID);
696 LogPrint(procID,
LOG_SPACE, 0,
"Request failed as remote system cannot be reached (req %u from comp %u)...", reqID, msg->
getFrom());
698 LogPrint(procID,
LOG_SPACE,0,
"Request reply failed (%u) from node %u (req %u from comp %u)...", status, otherNodeID, reqID, msg->
getFrom());
705 if (!(*result =
manager->temporalMemory->getCopyOfMessage(msgID))) {
706 LogPrint(procID,
LOG_SPACE,0,
"Couldn't getCopyOfMessage reply from node %u (req %u from comp %u)...", otherNodeID, reqID, msg->
getFrom());
711 manager->processMemory->addToProcessStats(procID, *result, NULL);
718 manager->processMemory->addToProcessStats(procID, NULL, resultMsg);
723 if (!
manager->dataMapsMemory->getRequestInfo(
id, origin, source, remoteID)) {
728 if (remoteID && !origin) {
735 manager->processMemory->addToReqQ(0, netMsg);
744 uint16 otherNodeID =
manager->componentMemory->getComponentNodeID(origin);
745 if (otherNodeID && (otherNodeID !=
manager->getNodeID())) {
751 manager->processMemory->addToReqQ(0, netMsg);
755 return manager->dataMapsMemory->deleteRequest(
id);
758 LogPrint(procID,
LOG_SPACE,0,
"Couldn't find otherNode %u for remote request %u (local %u) (source %u, origin %u)...",
759 otherNodeID, remoteID,
id, source, origin);
769 resultMsg->
setTTL(10000000);
770 msgEOL = resultMsg->
getEOL();
772 manager->temporalMemory->insertMessage(resultMsg, msgID);
788 return manager->dataMapsMemory->setRequestStatus(
id, reqStatus, msgID, msgEOL);
817bool PsySpace::threadPoolDispatch() {
818 DataMessage* msg, *dmsg;
821 uint32 idleCount = 0;
826 crankFunction[0] = 0;
828 crankLanguage[0] = 0;
830 libraryFilename[0] = 0;
835 TriggerSpec* trigger;
839 DeliveryOrderHold order;
840 threadPoolMutex.
enter();
845 if (idleCount < threadPoolWaitLowerThreshold)
846 setThreadPoolSize((uint16)(threadPool.size() + threadPoolWaitIncrement));
853 if (threadTarget < threadPool.size()) {
854 threadPoolMutex.
leave();
862 waitCounters[proc]++;
863 threadPoolMutex.leave();
869 msg =
manager->processMemory->waitForMsgQ(procID, 100);
870 if (!msg) order.release();
878 waitCounters[proc]++;
879 threadPoolMutex.leave();
880 msg =
manager->processMemory->waitForReqQ(procID, 100);
885 waitCounters[proc]++;
886 threadPoolMutex.leave();
887 if (msg =
manager->processMemory->waitForSigQ(procID, 100)) {
888 manager->processMemory->addToProcessStats(procID, msg, NULL);
890 if (signalsMutex.enter(3000, __FUNCTION__)) {
891 SignalStruct* signal = signalList[msg->getType()];
893 signal =
new SignalStruct;
894 signal->lastSignalMsg = NULL;
895 signalList[msg->getType()] = signal;
897 signalsMutex.leave();
898 if (signal->mutex.enter(3000, __FUNCTION__)) {
899 if (signal->lastSignalMsg)
900 delete(signal->lastSignalMsg);
901 signal->lastSignalMsg = msg;
902 signal->mutex.leave();
903 signal->event.signal();
920 while (!threadPoolMutex.enter(1000,
"Threadpool run with msg")) {
923 waitCounters[proc]--;
924 procCounters[proc]++;
943 if (!(compID = msg->getTo())) {
946 procCounters[proc]--;
947 threadPoolMutex.leave();
951 manager->processMemory->addToProcessStats(procID, msg, NULL);
954 if (
manager->componentMemory->isComponentPaused(compID)) {
955 LogPrint(procID,
LOG_SPACE, 3,
"Component %u is stopped, message dropped", compID);
957 procCounters[proc]--;
958 threadPoolMutex.leave();
966 if (!(trigger = (TriggerSpec*) msg->getData(
"TriggerSpec", s))) {
968 procCounters[proc]--;
969 threadPoolMutex.leave();
972 crankID = trigger->crankID;
977 procCounters[proc]--;
978 threadPoolMutex.leave();
983 if (!(dmsg = msg->getAttachedMessageCopy(
"Message"))) {
987 procCounters[proc]--;
988 threadPoolMutex.leave();
997 if (!(crankID = compCrankIDs[compID])) {
1001 if (
manager->dataMapsMemory->getCrankID(compName, crankID)) {
1002 compCrankIDs[compID] = crankID;
1006 else if ((crankID =
manager->dataMapsMemory->getComponentCrankID(compID))) {
1007 compCrankIDs[compID] = crankID;
1013 LogPrint(procID,
LOG_SPACE, 0,
"Unknown Component Crank for '%s' (%u)", compName, compID);
1016 procCounters[proc]--;
1017 threadPoolMutex.leave();
1025 if (!crank && !(crank = cranks[crankID])) {
1026 manager->dataMapsMemory->getCrankName(crankID, crankName, 256);
1028 if (
manager->dataMapsMemory->getCrankLanguage(crankID, crankLanguage,
MAXVALUENAMELEN) && crankLanguage && strlen(crankLanguage)) {
1031 LogPrint(procID,
LOG_SPACE, 0,
"Scripted language (%s) crank '%s' loading binary library '%s'", crankLanguage, crankName, libraryFilename);
1035 if (!
manager->dataMapsMemory->getCrankFunction(crankID, crankFunction,
MAXVALUENAMELEN) || !crankFunction) {
1036 LogPrint(procID,
LOG_SPACE, 0,
"Unknown Crank ID %u in Trigger Message", crankID);
1038 procCounters[proc]--;
1039 threadPoolMutex.leave();
1042 if (!
manager->dataMapsMemory->getCrankLibraryFilename(crankID, libraryFilename,
MAXVALUENAMELEN) || !libraryFilename) {
1043 LogPrint(procID,
LOG_SPACE, 0,
"Crank '%s' doesn't have a valid library specified", crankFunction);
1045 procCounters[proc]--;
1046 threadPoolMutex.leave();
1055 if (crankFunction && strlen(crankFunction)) {
1056 if (!(crank = loadCrankFromLibrary(crankFunction, libraryFilename))) {
1057 if (strlen(crankLanguage)) {
1058 LogPrint(procID,
LOG_SPACE, 0,
"The language library '%s' is unavailable - the language name '%s' may be incorrect", libraryFilename, crankLanguage);
1061 LogPrint(procID,
LOG_SPACE, 0,
"Couldn't find crank '%s' in library '%s'", crankFunction, libraryFilename);
1063 procCounters[proc]--;
1064 threadPoolMutex.leave();
1067 cranks[crankID] = crank;
1074 if (!(api = psyAPIs[crankID])) {
1077 psyAPIs[crankID] = api;
1087 status = api->addInputTrigger(crankID, compID, msg, dmsg);
1092 status = api->addInputTrigger(crankID, compID, msg, NULL);
1093 else if (msg->getString(
"PsyWake")) {
1097 status = api->claimForWake(crankID, compID);
1100 if (status !=
CRANKAPI_IDLE) { procCounters[proc]--; threadPoolMutex.leave();
continue; }
1104 status = api->addInputTrigger(crankID, compID, NULL, msg);
1110 procCounters[proc]--;
1111 threadPoolMutex.leave();
1132 DataMessage* requeue = dmsg ? dmsg : msg;
1133 DataMessage* discard = dmsg ? msg : NULL;
1138 procCounters[proc]--;
1139 threadPoolMutex.leave();
1141 if (!
manager->processMemory->addToMsgQ(procID, requeue)) {
1143 "re-queue FAILED; message DROPPED", crankID);
1154 procCounters[proc]--;
1155 threadPoolMutex.leave();
1159 threadPoolMutex.leave();
1169 LogPrint(procID,
LOG_SPACE, 0,
"Crank %u ('%s') caused an exception", crankID, crankName);
1172 }
while (api->shouldContinue() && api->getInputQueueSize());
1180 threadPoolMutex.enter();
1181 procCounters[proc]--;
1183 threadPoolMutex.leave();
1187 LogPrint(procID,
LOG_SPACE,3,
"Thread Pool %u exited, target %u, size: %u",
threadID, threadTarget, threadPool.size() - 1);
1188 threadPoolMutex.enter();
1189 std::map<uint32, uint8>::iterator i = threadPool.find(
threadID);
1190 if (i != threadPool.end())
1191 threadPool.erase(i);
1192 threadPoolMutex.leave();
1193 delete [] crankName;
1194 delete [] crankFunction;
1195 delete [] libraryFilename;
1199CrankFunction PsySpace::loadCrankFromLibrary(
const char* crankName,
const char* libraryFilename) {
1200 if (!crankName || !libraryFilename)
1203 if (!strlen(libraryFilename)) {
1205 return internalCranks[crankName];
1208 utils::Library* lib = libraries[libraryFilename];
1211 LogPrint(procID,
LOG_SPACE, 0,
"Could not find or load library '%s'", libraryFilename);
1214 libraries[libraryFilename] = lib;
1219 LogPrint(procID,
LOG_SPACE, 0,
"Could not load Crank '%s' from library '%s'", crankName, libraryFilename);
1226bool PsySpace::startContinuousComponent(uint32 compID) {
1228 std::map<uint32, uint32>::iterator it = continuousComponentThreads.find(compID);
1229 if (it != continuousComponentThreads.end())
1232 continuousComponentThreads[
threadID] = 0;
1238 continuousComponentThreads[
threadID] = compID;
1242bool PsySpace::runContinuousComponent() {
1244 DataMessage* msg = NULL;
1250 while (!(compID = continuousComponentThreads[
threadID])) {
1266bool PsySpace::run() {
1271 uint64 currentCPUTicks;
1273 uint32 checkCount = 50, c = 0;
1274 uint64 lastMsgCheck;
1275 std::map<uint32, PsyAPI*>::iterator i, e = psyAPIs.end();
1279 if (cmsg =
manager->processMemory->waitForCmdQ(procID, 100)) {
1283 ShutdownInProgressMark inProgress(
this);
1296 i = psyAPIs.begin();
1298 if ((i->second) && (lastMsgCheck = i->second->checkLastWaitForMessage())) {
1299 i->second->logPrint(1,
"Component has unchecked messages, last check %s ago",
#define REQ_PROCESSING_REMOTE
#define REQ_SUCCESS_DATA_EOL
#define REQ_FAILED_DATA_EOL
#define REQ_FAILED_TO_SEND
#define REQ_PROCESSING_LOCAL
#define PSYCLONE_STATUS_READY
Instance is fully operational.
#define PSYPROC_INIT
Process is initialising.
#define PSYPROC_ACTIVE
Process is actively running.
#define PSYPROC_SHUTTING_DOWN
Process is shutting down.
#define PSYPROC_TERMINATED
Process has terminated.
#define PSYPROC_READY
Process is ready to run components.
#define QUERY_NOT_REACHABLE
The target could not be reached (e.g.
#define QUERY_SUCCESS
The query succeeded.
#define CRANKAPI_RUNNING
The crank is currently executing.
#define QUERY_FAILED
General failure.
#define CRANKAPI_IDLE
The crank is idle, waiting for input.
#define CRANKAPI_FAILED
The API could not be obtained or is invalid.
#define CRANKAPI_INUSE
The API is already in use by another thread.
#define QUERY_TIMEOUT
No reply within the timeout.
The PsySpace process/node context: the runtime container in which Psyclone components (cranks) live a...
#define PROCSIGNAL
Signal processing.
#define LOG_SPACE
Log source id used by PsySpace when writing entries to the system log.
#define PROCREQUEST
Query/request processing.
#define PROCMESSAGE
Ordinary trigger-message processing.
#define thread_ret_val(ret)
#define THREAD_FUNCTION_CALL
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setTTL(uint64 ttl)
setTTL(uint64 ttl)
uint32 getFrom()
getFrom() Get the sender id
bool setString(const char *key, const char *value)
setString(const char* key, const char* value)
bool setInt(const char *key, int64 value)
setInt(const char* key, int64 value)
bool setTag(uint32 tag)
setTag(uint32 tag)
DataMessageHeader * data
Pointer to the message's flat memory block (header + user entries).
bool setStatus(uint16 status)
setStatus(uint16 status)
bool setAttachedMessage(const char *key, DataMessage *msg)
setAttachedMessage(const char* key, DataMessage* msg)
bool setReference(uint64 ref)
setReference(uint64 ref) Set message reference
uint64 getCreatedTime()
getCreatedTime()
bool setData(const char *key, const char *value, uint32 size)
setData(const char* key, const char* value, uint32 size)
static bool SetLogReceiver(LogReceiver *rec)
Register a receiver that gets every accepted LogEntry.
Top-level facade of the shared-memory subsystem for one process.
static struct PsyType CTRL_PROCESS_INITIALISE
Sent to a process to initialise it.
static struct PsyType CTRL_PROCESS_SHUTDOWN
Orders a single process to shut down.
static struct PsyType CTRL_PULLCOMPONENTDATA
Requests component data from another node.
static struct PsyType CTRL_TRIGGER_GROUP
T1.6: wraps a <triggergroup> joined-set delivery (member map) to a component.
static struct PsyType CTRL_TRIGGER
Wraps a trigger delivery to a component.
static struct PsyType CTRL_PROCESS_GREETING
Handshake from a newly joined process.
static struct PsyType CTRL_QUERY_REPLY
Carries a query reply back to the asker.
bool setCommandlineBasedir(const char *cmdlineBasedir)
Internal use only.
static struct PsyType CTRL_INTERSYSTEM_QUERY_REPLY
Reply from a different Psyclone system.
static struct PsyType CTRL_SYSTEM_SHUTDOWN
Orders a full system shutdown.
static struct PsyType CTRL_CREATECUSTOMPAGE
Registers a custom PsyProbe view.
The runtime container (one OS process/node context) hosting Psyclone components.
bool postMessage(DataMessage *msg)
Post a raw message into the system for distribution to subscribers.
bool reset()
Reset the space's runtime state (counters, queues) without disconnecting.
bool connect(uint16 systemID, bool isMaster=false, const char *cmdline=NULL)
Join a Psyclone system (attach to the node's shared memory).
bool registerInternalCrank(const char *name, CrankFunction func)
Register a built-in ("internal") crank by function name, resolved when a component's <crank function=...
bool shutdown()
Request an orderly shutdown of the space and all its components.
friend THREAD_RET THREAD_FUNCTION_CALL PsySpaceRun(THREAD_ARG arg)
Thread entry for the space's main service thread.
bool start(uint16 threadCount=5)
Start processing: spin up the thread pool and begin dispatching triggers.
uint8 query(DataMessage *msg, DataMessage **result, uint32 timeout)
Send a query message and wait for its reply.
uint32 getComponentID(const char *name)
Look up the numeric component id for a component name.
DataMessage * waitForSignal(const PsyType &type, uint32 timeout, uint64 lastReceivedTime=0)
Block until a signal of the given type arrives (or has already arrived).
friend THREAD_RET THREAD_FUNCTION_CALL PsySpaceContinuousRun(THREAD_ARG arg)
Thread entry for continuously running components.
bool isConnected(uint32 timeoutMS=5000)
Wait until the space is fully connected to the system.
MemoryManager * manager
The process-local memory manager: entry point to the node's shared-memory fabric. Owned by the space.
bool registerCrankCallback(const char *name, CrankFunction func)
Register a C/C++ entry function for a crank, to be invoked by the thread pool when the component trig...
bool addPsyProbeCustomView(uint32 compID, const char *name, const char *templateURL)
Add a custom PsyProbe view tab for a component (space-level variant of PsyAPI::addPsyProbeCustomView(...
PsyAPI * getCrankAPI(const char *name)
Get (or create) the PsyAPI handle for a crank hosted in this space.
bool queryReply(uint32 id, uint8 status, DataMessage *result)
Reply to a previously received query.
bool emitSignal(const PsyType &type, DataMessage *msg)
Emit a system-wide signal of the given type.
bool logEntry(LogEntry *entry)
LogReceiver interface: accept a log entry produced within this space.
PsySpace(const char *name=NULL, bool isAdHoc=true, uint16 procID=0, bool isLocal=false)
Create a space (does not yet join a system; call connect()).
bool isRunning
Set by the worker while its loop is active.
virtual bool stop(uint32 timeout=200)
Ask the worker loop to finish and wait for it to do so.
uint32 threadID
ThreadManager slot ID of the worker thread (0 until known).
bool shouldContinue
Loop-continuation flag; cleared by stop().
static bool GetLocalThreadID(uint32 &id)
Look up the manager slot ID of the calling thread.
static bool CreateThread(THREAD_FUNCTION func, void *args, uint32 &newID, uint32 reqID=0)
Create a new native thread and start it immediately.
static bool TerminateThread(uint32 id)
Forcibly terminate the thread and release its slot.
Time-binned activation queue used by a PsySpace to drive time-triggered modules.
DataMessage * waitForNextEvent(uint32 ms)
Block until the next scheduled event is due, or the timeout expires.
bool removeSchedule(uint32 id)
Remove (and delete) a schedule by id.
bool addSchedule(TimeQueueSchedule *schedule)
Add a schedule to the queue.
~TimeQueue()
Destroy the queue and delete all remaining schedules (owned by the queue).
TimeQueue()
Create an empty time queue with its own timer.
One recurring (or time-bounded) activation schedule managed by a TimeQueue.
uint32 msgTag
Tag attached to the generated message.
uint64 start
First-activation time (µs), or 0 for immediate.
PsyType msgType
Type of the message generated on each activation.
uint32 interval
Repeat interval in milliseconds.
TimeQueueSchedule(uint32 interval, uint64 start=0, uint64 end=0)
Create a schedule.
~TimeQueueSchedule()
Destructor.
uint64 end
Expiry time (µs), or 0 for no expiry.
uint32 id
Unique schedule id, used for removal via TimeQueue::removeSchedule().
bool waitNext()
Block until the next signal() occurs.
bool signal()
Wake all threads currently waiting on this event.
Recursive mutual-exclusion lock, optionally named for cross-process use.
bool leave()
Release the mutex.
bool enter()
Block until the mutex is acquired.
Multiplexing timer: schedule many periodic timers and consume their expiries from one queue.
std::string PrintTimeString(uint64 t, bool local=true, bool us=true, bool ms=true)
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
std::string PrintTimeDifString(uint64 t, bool us=true, bool ms=true)
int32 GetTimeAgeMS(uint64 t)
Age of a timestamp relative to now, in milliseconds.
int64 GetTimeAge(uint64 t)
Age of a timestamp relative to now.
bool Sleep(uint32 ms)
Suspend the calling thread.
bool GetProcessCPUTicks(uint64 &ticks)
Get accumulated CPU time of the current process.
uint32 strcpyavail(char *dst, const char *src, uint32 maxlen, bool copyAvailable)
Bounded strcpy that always NUL-terminates.
std::string GetCommandLinePath()
Get the directory portion of the executable path.
double RandomValue()
Uniform random double in [0,1).
std::string TextTrimQuotes(const char *text)
Strip a single pair of surrounding quotes if present.
bool StringFormatInto(char *dst, uint32 maxsize, const char *format,...)
printf into a caller-supplied buffer with truncation.
std::string StringFormat(const char *format,...)
printf into a std::string.
Library * OpenLibrary(const char *libName)
Load a library by name, applying platform filename conventions.
std::string TextCapitalise(const char *text)
Capitalise the first letter of text.
int8 Internal_QueryTest(PsyAPI *api)
Exercises query/queryReply round-trips.
int8 Internal_Pong(PsyAPI *api)
Latency test counterpart: answers pings.
int8(* CrankFunction)(PsyAPI *api)
Signature of a component (crank) entry function.
static utils::Mutex * DeliveryOrderMutex
int8 Internal_Print(PsyAPI *api)
Prints incoming messages to the console/log.
static struct PsyType CTRL_LOGPRINT
static std::multiset< PsySpace * > & ShutdownInProgress()
int8 Internal_Simple(PsyAPI *api)
Pass-through test crank: copies each incoming message to its posts.
int8 Internal_SignalPong(PsyAPI *api)
Signal-based pong counterpart.
int8 Internal_StatsLog(PsyAPI *api)
Periodically logs system statistics.
int8 Internal_SignalPing(PsyAPI *api)
Signal-based ping test.
THREAD_RET THREAD_FUNCTION_CALL PsySpaceContinuousRun(THREAD_ARG arg)
Continuous-component thread entry: runs PsySpace::runContinuousComponent() for the space passed in ar...
int8 Internal_MessageToggler(PsyAPI *api)
Alternates/toggles message output for testing.
int8 Internal_Shutdown(PsyAPI *api)
Initiates system shutdown when triggered.
THREAD_RET THREAD_FUNCTION_CALL PsySpaceRun(THREAD_ARG arg)
Main service-thread entry: runs PsySpace::run() for the space passed in arg.
static bool IsShuttingDown(PsySpace *s)
int8 Internal_Ping(PsyAPI *api)
Latency test: posts pings, expects pongs.
int8 Internal_Time(PsyAPI *api)
Posts time information/timestamps.
THREAD_RET THREAD_FUNCTION_CALL PsySpacePoolRun(THREAD_ARG arg)
Pool worker-thread entry: runs PsySpace::threadPoolDispatch() for the space passed in arg.
int8 Internal_BitmapPoster(PsyAPI *api)
Posts test bitmap/image messages.
int8 Internal_MessageTypeConverter(PsyAPI *api)
Converts incoming messages to another type before reposting.
int8 Internal_MessageScript(PsyAPI *api)
Plays back scripted TrackPlayerMessage sequences.
int8 Internal_RetrieveTest(PsyAPI *api)
Exercises whiteboard retrieve calls.
static std::mutex & ShutdownInProgressMutex()
Hierarchical message type identifier — the key used for publish/subscribe matching in Psyclone.
Wire/storage layout of one log record: fixed header immediately followed by the message text.
~ShutdownInProgressMark()
ShutdownInProgressMark(PsySpace *s)
Per-signal bookkeeping for PsySpace signal distribution.
utils::Mutex mutex
Protects lastSignalMsg.
DataMessage * lastSignalMsg
Most recently emitted message for this signal type (owned by the space).
utils::Event event
Signalled whenever a new message arrives; wakes waiters.