13#error This is a C++ include file and cannot be used from plain C
21#define ngcbCMD_LIST_SIZE 256
26#define ngcbCMD_UPDATE 0x00000001
27#define ngcbCMD_PROTECTED 0x00000002
28#define ngcbCMD_PROTECT 0x00000004
29#define ngcbCMD_INTERNAL 0x00000008
30#define ngcbCMD_DISCARDED 0x00000010
35#define ngcbCMD_ID_IVLD -1
36#define ngcbCMD_ID_NOT_SET -2
71 int Id() {
return (id_);}
74 int Id(
const char *filter) {
82 else if ((strlen(param_) > 0) && (strlen(filter) <
sizeof(filter_)))
88 strcat(format, filter);
89 strcat(format,
" %d %1023[^\n]");
91 n = sscanf(param_, format, &id_, s);
94 if (n < 2) param_[0] =
'\0';
95 else strcpy(param_, s);
114 int Param(
const char *p,
const char *filter=NULL) {
122 str2str(param_, p,
sizeof(param_) - 1);
124 else if (strlen(filter) <
sizeof(filter_))
129 strcat(format, filter);
130 strcat(format,
" %d %1023[^\n]");
131 strcpy(filter_, filter);
132 n = sscanf(p, format, &id_, param_);
135 if (n < 2) param_[0] =
'\0';
152 str2str(param_, p,
sizeof(param_) - 1);
158 str2str(param_, p,
sizeof(param_) - 1);
184 int Get(
const char *filter,
char *s) {
185 return (
ngcbF2S(param_, filter, s));
189 int Get(
const char *filter,
double *v) {
194 int Get(
const char *filter) {
199 unsigned int GetX(
const char *filter) {
234 int LogIn(
const char *s);
252 void Encrypt(
char *s,
const char *key = NULL);
256 int KeyVal(
const char *key,
float *value);
259 int KeyVal(
const char *key,
double *value);
262 int KeyVal(
const char *key,
int *value);
265 int KeyVal(
const char *key,
unsigned int *value);
268 int KeyValHex(
const char *key,
int *value);
271 int KeyValHex(
const char *key,
unsigned int *value);
274 int KeyValFmt(
const char *key,
int *value);
277 int KeyValFmt(
const char *key,
unsigned int *value);
280 int KeyValFrac(
const char *key,
unsigned int n, uint64_t *v1, uint64_t *v2);
283 int KeyIdx(
char *key,
const char *mask);
333 return (strcmp(
Cmd(), other.
Cmd()) < 0);
338 str2str(cmd_, name,
sizeof(cmd_) - 1);
355 const char *
Cmd()
const {
return (cmd_);}
359 if (s == NULL) sprintf(
syntax,
"%s (...)",
Cmd());
360 else if (strlen(s) == 0) sprintf(
syntax,
"%s",
Cmd());
366 if (s == NULL) strcpy(
help,
"No help available!");
390 const char *syntax,
const char *help,
void *udata,
char *erms);
393 void Delete(
const char *cmd);
402 int Help(
const char *args,
char *reply);
int Help(const char *args, char *reply)
Get help-text.
Definition ngcbCMD_LIST.cpp:243
int Execute(const char *cmd, ngcb_cmd_handle_t *handle, char *reply)
Execute command.
Definition ngcbCMD_LIST.cpp:161
int Add(const char *cmd, ngcb_function_t function, int flags, const char *syntax, const char *help, void *udata, char *erms)
Create command handler and add it to the command list.
Definition ngcbCMD_LIST.cpp:84
void Sort()
Sort list alphabetically.
Definition ngcbCMD_LIST.cpp:154
int Status()
Return Status (0=open, 1=complete)
Definition ngcbCMD_LIST.cpp:72
int Defined(const char *cmd)
Check if command is defined.
Definition ngcbCMD_LIST.cpp:74
ngcbCMD_LIST(ngcbCMD_SRV *server)
Constructor.
Definition ngcbCMD_LIST.cpp:38
void Close()
Close command factory - no further commands can be added.
Definition ngcbCMD_LIST.cpp:68
void Delete(const char *cmd)
Delete command from the command list.
Definition ngcbCMD_LIST.cpp:138
virtual ~ngcbCMD_LIST()
Destructor.
Definition ngcbCMD_LIST.cpp:58
void Open()
Open command factory - further commands can be added.
Definition ngcbCMD_LIST.cpp:70
Definition ngcbCMD.hpp:219
int Locked()
Return locked status.
Definition ngcbCMD_SRV.cpp:181
void DiscardDetIdx(char *key)
Discard DETi index.
Definition ngcbCMD_SRV.cpp:310
int KeyValFmt(const char *key, int *value)
Get 32-bit signed integer value from string.
Definition ngcbCMD_SRV.cpp:294
void Unlock()
Unlock command system.
Definition ngcbCMD_SRV.cpp:177
virtual ~ngcbCMD_SRV()
Destructor.
Definition ngcbCMD_SRV.cpp:39
int KeyValFrac(const char *key, unsigned int n, uint64_t *v1, uint64_t *v2)
Fraction after n digits.
Definition ngcbCMD_SRV.cpp:304
int LogIn(const char *s)
Login to trusted mode with a key in the format "name:password".
Definition ngcbCMD_SRV.cpp:188
int LoggedIn()
Return login status.
Definition ngcbCMD_SRV.cpp:256
void StringReset(char *s, size_t size=256)
Fill string with zeros.
Definition ngcbCMD_SRV.cpp:320
ngcbCMD_SRV()
Constructor.
Definition ngcbCMD_SRV.cpp:29
int KeyIdx(char *key, const char *mask)
Get the index after the first occurrence of mask in the keyword.
Definition ngcbCMD_SRV.cpp:315
void AssignPassword(const char *fileName)
Assign password from file.
Definition ngcbCMD_SRV.cpp:52
int KeyValHex(const char *key, int *value)
Get 32-bit signed integer value from hexadecimal keyword string.
Definition ngcbCMD_SRV.cpp:284
const char * PW()
Return password.
Definition ngcbCMD_SRV.cpp:164
int KeyVal(const char *key, float *value)
Get single precision floating point value from keyword string.
Definition ngcbCMD_SRV.cpp:264
void Lock()
Lock command system.
Definition ngcbCMD_SRV.cpp:173
void LogOut()
Log out.
Definition ngcbCMD_SRV.cpp:248
void Encrypt(char *s, const char *key=NULL)
Encrypt string with key.
Definition ngcbCMD_SRV.cpp:118
Definition ngcbCMD.hpp:42
virtual ~ngcb_cmd_handle_t()
Destructor.
Definition ngcbCMD.hpp:68
int Param(const char *p, const char *filter=NULL)
Assign parameter string.
Definition ngcbCMD.hpp:114
int Get(const char *filter, double *v)
Get filtered double precision parameter.
Definition ngcbCMD.hpp:189
int Get(const char *filter, char *s)
Get filtered string parameter.
Definition ngcbCMD.hpp:184
unsigned int GetX(const char *filter)
Get filtered 32-bit unsigned integer parameter.
Definition ngcbCMD.hpp:199
int done
Done flag.
Definition ngcbCMD.hpp:51
void * udata
Forwarded user data.
Definition ngcbCMD.hpp:48
int fd
File descriptor of command source.
Definition ngcbCMD.hpp:54
int Id(const char *filter)
Format parameter string and return filtered component id.
Definition ngcbCMD.hpp:74
int Get(const char *filter)
Get filtered 32-bit signed integer parameter.
Definition ngcbCMD.hpp:194
int Id()
Return component id.
Definition ngcbCMD.hpp:71
char * Param()
Return parameter string.
Definition ngcbCMD.hpp:181
ngcb_cmd_handle_t()
Constructor.
Definition ngcbCMD.hpp:57
int flags
Forwarded flags (ngcbCMD_UPDATE, ngcbCMD_PROTECTED)
Definition ngcbCMD.hpp:45
Definition ngcbCMD.hpp:314
int flags
Flags (ngcbCMD_UPDATE, ngcbCMD_PROTECTED)
Definition ngcbCMD.hpp:326
ngcb_function_t function
Command handling function.
Definition ngcbCMD.hpp:317
ngcb_cmd_t(const char *name)
Constructor.
Definition ngcbCMD.hpp:337
char syntax[256]
Syntax string (for help)
Definition ngcbCMD.hpp:320
void * udata
User data to be forwarded.
Definition ngcbCMD.hpp:329
char help[1024]
Help text.
Definition ngcbCMD.hpp:323
void Syntax(const char *s)
Assign syntax.
Definition ngcbCMD.hpp:358
void Help(const char *s)
Assign help text.
Definition ngcbCMD.hpp:365
virtual ~ngcb_cmd_t()
Destructor.
Definition ngcbCMD.hpp:347
static bool Compare(const ngcb_cmd_t *a, const ngcb_cmd_t *b)
Comparison function.
Definition ngcbCMD.hpp:350
bool operator<(const ngcb_cmd_t &other) const
Comparison operator.
Definition ngcbCMD.hpp:332
const char * Cmd() const
Return command name.
Definition ngcbCMD.hpp:355
#define ngcbCMD_ID_NOT_SET
Definition ngcbCMD.hpp:36
#define ngcbCMD_ID_IVLD
Definition ngcbCMD.hpp:35
int(ngcbCMD_SRV::* ngcb_function_t)(ngcb_cmd_handle_t *handle, char *reply)
Definition ngcbCMD.hpp:308
#define ngcbCMD_LIST_SIZE
Definition ngcbCMD.hpp:21
int ngcbF2S(const char *s, const char *filter, char *v)
Definition ngcbString.c:356
int ngcbF2Int(const char *s, const char *filter)
Definition ngcbString.c:413
int ngcbF2Double(const char *s, const char *filter, double *v)
Definition ngcbString.c:527
#define str2str(s1, s2, n)
Definition ngcb.h:74
unsigned int ngcbF2UInt(const char *s, const char *filter)
Definition ngcbString.c:475