📄 tinydb.h
字号:
short knownExprs; //bitmask indicating what exprs we've seen //13 uint16_t queryRoot; // obsoleted bool hasBuf; //19 BufInfo buf; //29 bool needsEvent; //30 bool hasEvent; //31 bool hasForClause; //32 char eventName[COMMAND_SIZE]; //40 Field fields[1]; //access via GET_FIELD, SET_FIELD //47 //Expr exprs[1] //access vis GET_EXPR, SET_EXPR} Query, *QueryPtr;enum { MAX_FIELDS = 16, MAX_EXPRS = 16, kNO_QUERY = 0xFF};typedef char Op;enum { EQ = 0, NEQ = 1, GT = 2, GE = 3, LT = 4, LE = 5};typedef char Agg;//field operators, for use in exprsenum { FOP_NOOP = 0, FOP_TIMES = 1, FOP_DIVIDE = 2, FOP_ADD = 3, FOP_SUBTRACT = 4, FOP_MOD = 5, FOP_RSHIFT = 6};//expressions are either aggregates or selections//for now we support the simplest imagineable types (e.g.//no nested expressions, joins, or modifiers on fields)typedef struct { short field; //2 Op op; //3 short value; //5} OpValExpr;typedef struct { short field; //2 short groupingField; //field to group on //4 short groupFieldOp; //6 short groupFieldConst; //8 Agg op; //9} AggregateExpression;typedef struct { AggregateExpression agg; //9 //temporal agg can have at most 4 arguments uint8_t args[4];//13} TemporalAggExpr;typedef struct { Op op; //1 short field; //3 char s[STRING_SIZE]; //11} StringExpr; //11enum { kNO_GROUPING_FIELD = 0xFFFF};//operator state represents the per operator//query state stored in the tuple router and//sent to the operators on invocationtypedef char** OperatorStateHandle;enum { kSEL = 0, kAGG = 1, kTEMP_AGG = 2,};typedef struct { char opType:6; bool isStringExp:1; //is this a string expression or not? bool success:1; //boolean indicating if this query was successfully applied //1 char idx; //index of this expression in the query //2 union { OpValExpr opval; AggregateExpression agg; TemporalAggExpr tagg; StringExpr sexp; //for comparisons with strings } ex; //15 short fieldOp; //17 -- from FOP... defines above short fieldConst; //19 OperatorStateHandle opState; //21} Expr, *ExprPtr;enum { kFIRST_RESULT = 0xFF, };//enums for the QueryResult qrType (what kind of query result)enum { kUNDEFINED = 0, kIS_AGG = 1, kNOT_AGG = 2, kAGG_SINGLE_FIELD = 3};typedef struct { uint8_t qid; //query this result corresponds to bool isAgg; //is this an aggregate result, or a base tuple uint16_t epoch; //epoch this result corresponds to TinyDBError error; //error flag for return union { uint16_t tupleField; //which record of this result is this? struct { int16_t group; //aggregate result group id uint8_t id; uint8_t len; //and length in bytes } agg; } u; char *data; //the data corresponding to this result} ResultTuple; /* ----------------------- Query Types ------------------------ */ //queries have to be decomposed into multiple messages //these are sent one by one to fill in a query data structure, //which is then converted to a parsed query //in query message -- is this a field or an expression enum { kFIELD = 0, kEXPR =1, kBUF_MSG = 2, kEVENT_MSG = 3, kN_EPOCHS_MSG = 4, kDROP_TABLE_MSG = 5 }; // type of query message enum {ADD_MSG = 0, DEL_MSG = 1, MODIFY_MSG = 2, RATE_MSG = 3, DROP_TABLE_MSG = 5 };enum { CRC_FAILURE = 1, //source of loss for contention monitoring ACK_FAILURE = 2, SEND_FAILURE = 3, ENQUEUE_FAILURE = 4, SEND_BUSY_FAILURE = 5};//enums for adjust the sample rate based on observed contentionenum { HIGH_CONTENTION_THRESH = 20, LOW_CONTENTION_THRESH = 10}; /** Message type for carrying query messages */ typedef struct QueryMessage { // XXX recompute header size //7 uint8_t qid; //query id //8 -- note that this byte must be qid uint16_t fwdNode; //10 -- node that forwarded the query message char msgType; //type of message (e.g. add, modify, delete q) //11 char numFields; //12 char numExprs; //13 char fromBuffer; //14 uint8_t fromCatalogBuffer:1; //15 uint8_t hasEvent:1; //15 uint8_t hasForClause:1; //15 uint8_t bufferType:5; //15 -- output buffer type short epochDuration; //in millisecs -- 17 char type; //is this a field, expression, buffer, or event msg -- 18 char idx; //19 uint8_t timeSyncData[5]; int16_t clockCount; union { Field field; Expr expr; //40 BufInfo buf; char eventName[COMMAND_SIZE]; short numEpochs; int8_t ttl; //for delete msg } u; //40 } QueryMessage, *QueryMessagePtr;#ifdef kQUERY_SHARING //these messages sent from remote motes requesting a querytypedef struct { uint8_t qid; //note that this byte must be query id uint32_t qmsgMask; // bit mask for query messages already received uint16_t reqNode; // node that is requesting the query, purely for debugging uint16_t fromNode; // node to request query from, purely for debugging} QueryRequestMessage, *QueryRequestMessagePtr;#endif struct UartMsg { char data[30];};struct RTCMsg { uint32_t time_high32; uint32_t time_low32;}; /* ----------------------- Status Message ------------------------ */enum { kMAX_QUERIES = 8 };typedef struct StatusMessage { bool fromBase; uint8_t numQueries; unsigned char queries[kMAX_QUERIES];} StatusMessage;typedef bool *BoolPtr;typedef char *CharPtr;enum { kDATA_MESSAGE_ID = 240, // XXX must be one of the amids in lib/Route/MultiHop.h kQUERY_MESSAGE_ID = 101, kCOMMAND_MESSAGE_ID = 103, kQUERY_REQUEST_MESSAGE_ID = 104, kEVENT_MESSAGE_ID = 105, kSTATUS_MESSAGE_ID = 106, kDIRECTED_DATA_MESSAGE_ID = 107, kMSG_LEN = DATA_LENGTH, AM_QUERYRESULT = kDATA_MESSAGE_ID, AM_QUERYMESSAGE = kQUERY_MESSAGE_ID, AM_STATUSMESSAGE = kSTATUS_MESSAGE_ID, AM_UARTMSG = 1, AM_RTCMSG = 107};enum { kTINYDB_SERVICE_ID = 0};//header information that MUST be in every message//if it is to be send via TINYDB_NETWORK -- we require//so that TINYDB_NETWORK doesn't have to copy messages// this is for TinyDB native network only!! typedef struct { short senderid; //id of the sender short parentid; //id of senders parent uint8_t level; //level of the sender // unsigned char xmitSlots; //number of transmission slots? -- unused now unsigned char timeRemaining; //number of clock cyles til end of epoch // short idx; //message index uint8_t idx; } DbMsgHdr; typedef struct NetworkMessage { DbMsgHdr hdr; char data[0]; } NetworkMessage;#define isRoot() (TOS_LOCAL_ADDRESS == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -