You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Modelbahn/server/block.h

73 lines
1.6 KiB

#ifndef _BLOCK_H_
#define _BLOCK_H_
#include "modelbahn.h"
#include "server.h"
#define BLOCK_F_OFF 0x0001
#define BLOCK_F_SHORT 0x0010
#define BLOCK_F_LONG 0x0020
#define BLOCK_F_ENDSTATION 0x0040
#define BLOCK_F_STATION 0x0080
#define BLOCK_F_SPEEDLIMIT 0x0100
#define BLOCK_F_ONLYCARGO 0x0200
#define BLOCK_F_ONLYPASSENGER 0x0400
struct s_Block {
char name[REFERENCENAME_LEN];
char s_pos_1[REFERENCENAME_LEN]; //
char s_center[REFERENCENAME_LEN];
char s_neg_1[REFERENCENAME_LEN];
int flags;
char lockedby[REFERENCENAME_LEN]; // element locked by locreference (only set by server, not by JSON/Webinterface)
} typedef Block;
class Blocks {
private:
Block *blocks;
int max;
int changed;
pthread_mutex_t mtx;
int Lock();
int UnLock();
// not thread safe
JSONParse _GetJSON(Block *bl);
JSONParse _GetJSON(int idx) { return _GetJSON(&blocks[idx]); };
int last_blockidx; // to speed up things
Block* FindBlock(string name);
public:
Blocks();
~Blocks();
bool IsChanged() { return changed; }
void ClearChanged() { changed = 0; };
int Change(Block *se);
int Delete(string name);
JSONParse GetJSON(string name);
void GetJSONAll(JSONParse *json);
Block GetBlockFromJSON(JSONParse *j);
int SetOff(string blname);
int IsOff(string blname);
string GetSensorMinus (string blname);
string GetSensorCenter (string blname);
string GetSensorPlus (string blname);
int GetFlags (string blname);
int SetLockedby (string blname, string lockedby, int lock_onoff);
string GetLockedby (string blname);
void ClearLockedby(string name);
int Clear(string name);
};
#endif