

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/
//_/_/  This file is part of CMSDK version 2.1.1.260726 (26 July 2026)
//_/_/  
//_/_/  developed by
//_/_/  
//_/_/  Communicative Machines Ltd. 
//_/_/    http://cmlabs.com/
//_/_/  Copyright (c) 2026
//_/_/  
//_/_/  in collaboration with 
//_/_/  
//_/_/  Icelandic Institute for Intelligent Machines ses
//_/_/    Menntavegur 1
//_/_/    101 Reykjavik
//_/_/    ICELAND
//_/_/    http://www.iiim.is/
//_/_/
//_/_/  and is released under the following
//_/_/  
//_/_/  EXTENDED BSD License
//_/_/
//_/_/  Redistribution and use in source and binary forms, with or without
//_/_/  modification, is permitted provided that the following conditions 
//_/_/  are met:
//_/_/
//_/_/  - Redistributions of source code must retain the above copyright 
//_/_/    and collaboration notice, this list of conditions and the following 
//_/_/    disclaimer.
//_/_/
//_/_/  - Redistributions in binary form must reproduce the above copyright 
//_/_/    notice, this list of conditions and the following disclaimer in the 
//_/_/    documentation and/or other materials provided with the distribution.
//_/_/
//_/_/  - Neither the name of its copyright holders nor the names of its 
//_/_/    contributors may be used to endorse or promote products derived from 
//_/_/    this software without specific prior written permission.
//_/_/
//_/_/  - CADIA Clause: The license granted in and to the software under this 
//_/_/    agreement is a limited-use license. The software may not be used in 
//_/_/    furtherance of: (i) intentionally causing bodily injury or severe 
//_/_/    emotional harm to any person; (ii) invading the personal privacy or 
//_/_/    violating the human rights of any person; or (iii) committing or 
//_/_/    preparing for any act of war. 
//_/_/
//_/_/  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
//_/_/  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
//_/_/  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 
//_/_/  PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
//_/_/  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
//_/_/  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
//_/_/  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
//_/_/  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
//_/_/  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
//_/_/  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
//_/_/  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
/*! @file ObjectIDs.h
	@brief Object type ids used to tag and verify every binary structure in CMSDK memory.

	Every flat binary object in Psyclone (messages, memory maps, index entries,
	specs, ...) carries a uint32 @c cid field at byte offset 4 identifying what
	the block is. The ids are generated by GenObjID(n), which stores the small
	type number redundantly in the low and high 16 bits so that a corrupted or
	misaligned block can be detected cheaply (VerObjID). This is the first line
	of defence when reading structures out of shared memory, network buffers or
	recordings.
	@ingroup Messaging
*/

#if !defined(_OBJECTIDS_H_)
#define _OBJECTIDS_H_

#include "Types.h"

namespace cmlabs {

//! Generate a self-verifying object id from a small type number: the number is duplicated in the high and low 16 bits.
#define GenObjID(n)			(((n) << 16) | n)
//! Verify an object id's internal redundancy (both halves must agree and the id must be non-zero).
#define VerObjID(id)		( (id != 0) && ((((id) & 0xFF00) >> 16) == ((id) & 0x00FF)) )
//! Extract the cid field from a binary object block: the uint32 at byte offset 4 (after the leading size field).
#define GetObjID(data)		*(((uint32*)(data))+1)
//! Extract and verify the cid of a binary object block in one step.
#define VerObj(data)		VerObjID(GetObjID(data))

/*! @name Built-in object type ids
	Ids for the core value types stored inside DataMessages (UNUSEDID..CHARDATAINFOID),
	the shared-memory subsystems, and the message/spec structures. The ...INFOID
	variants mark "draft" placeholder entries carrying only name+size instead of
	the full payload (see DataMessage draft constructors).
@{ */

#define UNUSEDID			GenObjID(	1	)
#define CONSTCHARID			GenObjID(	2	)
#define TIMEID				GenObjID(	3	)
#define CHARDATAID			GenObjID(	4	)
#define INTID				GenObjID(	5	)
#define DOUBLEID			GenObjID(	6	)
#define CONSTCHARINFOID		GenObjID(	7	)
#define CHARDATAINFOID		GenObjID(	8	)

#define PSYCLONEINDEXID		GenObjID(	10	)
#define PSYCLONEMASTERID	GenObjID(	11	)
#define TEMPORALMEMORYID	GenObjID(	12	)
#define PROCESSMEMORYID		GenObjID(	13	)
#define COMPONENTMEMORYID	GenObjID(	14	)
#define DATAMAPSMEMORYID	GenObjID(	15	)

#define DATAMESSAGEOLDID	GenObjID(	20	)
#define CONTROLMESSAGEID	GenObjID(	21	)
#define LOGENTRYID			GenObjID(	22	)
#define TIMESYNCDATA		GenObjID(	23	)
#define TRIGGERDATA			GenObjID(	24	)
#define RETRIEVEDATA		GenObjID(	25	)
#define POSTDATA			GenObjID(	26	)
#define COMPONENTSETUPDATA	GenObjID(	27	)
#define IDRESERVATION		GenObjID(	28	)
#define TYPELEVELID			GenObjID(	29	)
#define CONTEXTLEVELID		GenObjID(	30	)
#define CRANKID				GenObjID(	31	)
#define COMPONENTID			GenObjID(	32	)
#define TAGID				GenObjID(	33	)
#define NODEINFOPACKID		GenObjID(	34	)
#define NODEMAPID			GenObjID(	35	)
#define DATAMESSAGEINFOID	GenObjID(	36	)
#define DATAMESSAGEDRAFTID	GenObjID(	37	)

#define MEMORYREQUESTSERVERID	GenObjID(	38	)
#define DYNAMICMEMORYID		GenObjID(	39	)
#define OBSERVATIONID		GenObjID(	40	)
#define DATAMESSAGEID		GenObjID(	41	)
#define TRIGGERGROUPDATA	GenObjID(	42	)	/*!< T1.6 <code>&lt;triggergroup&gt;</code> declarative join spec. */
/*! @} */

/*! @name Built-in control message types
	Predefined PsyType values (root level 1 = control) used by the runtime
	itself for self-test, log printing and ping/pong liveness checks.
@{ */
static struct PsyType CTRL_TEST =			{ { 1,10001,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
static struct PsyType CTRL_LOGPRINT =		{ { 1,10002,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
static struct PsyType CTRL_PING =			{ { 1,10003,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
static struct PsyType CTRL_PING_REPLY =	{ { 1,10004,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } };
/*! @} */

} // namespace cmlabs

#endif //_OBJECTIDS_H_

