12#error This is a C++ include file and cannot be used from plain C
20#define ngcbCMD_LIST_SIZE 256
25#define ngcbCMD_UPDATE 0x00000001
26#define ngcbCMD_PROTECTED 0x00000002
27#define ngcbCMD_PROTECT 0x00000004
28#define ngcbCMD_INTERNAL 0x00000008
29#define ngcbCMD_DISCARDED 0x00000010
34#define ngcbCMD_ID_IVLD -1
35#define ngcbCMD_ID_NOT_SET -2
70 int Id() {
return (id_);}
73 int Id(
const char *filter) {
81 else if ((strlen(param_) > 0) && (strlen(filter) <
sizeof(filter_)))
87 strcat(format, filter);
88 strcat(format,
" %d %1023[^\n]");
90 n = sscanf(param_, format, &id_, s);
93 if (n < 2) param_[0] =
'\0';
94 else strcpy(param_, s);
113 int Param(
const char *p,
const char *filter=NULL) {
121 str2str(param_, p,
sizeof(param_) - 1);
123 else if (strlen(filter) <
sizeof(filter_))
128 strcat(format, filter);
129 strcat(format,
" %d %1023[^\n]");
130 strcpy(filter_, filter);
131 n = sscanf(p, format, &id_, param_);
134 if (n < 2) param_[0] =
'\0';
151 str2str(param_, p,
sizeof(param_) - 1);
157 str2str(param_, p,
sizeof(param_) - 1);
183 int Get(
const char *filter,
char *s) {
184 return (
ngcbF2S(param_, filter, s));
188 int Get(
const char *filter,
double *v) {
193 int Get(
const char *filter) {
198 unsigned int GetX(
const char *filter) {
233 int LogIn(
const char *s);
251 void Encrypt(
char *s,
const char *key = NULL);
255 int KeyVal(
const char *key,
float *value);
258 int KeyVal(
const char *key,
double *value);
261 int KeyVal(
const char *key,
int *value);
264 int KeyVal(
const char *key,
unsigned int *value);
267 int KeyValHex(
const char *key,
int *value);
270 int KeyValHex(
const char *key,
unsigned int *value);
273 int KeyValFmt(
const char *key,
int *value);
276 int KeyValFmt(
const char *key,
unsigned int *value);
279 int KeyValFrac(
const char *key,
unsigned int n, uint64_t *v1, uint64_t *v2);
282 int KeyIdx(
char *key,
const char *mask);
332 return (strcmp(
Cmd(), other.
Cmd()) < 0);
337 str2str(cmd_, name,
sizeof(cmd_) - 1);
354 const char *
Cmd()
const {
return (cmd_);}
358 if (s == NULL) sprintf(
syntax,
"%s (...)",
Cmd());
359 else if (strlen(s) == 0) sprintf(
syntax,
"%s",
Cmd());
365 if (s == NULL) strcpy(
help,
"No help available!");
389 const char *syntax,
const char *help,
void *udata,
char *erms);
392 void Delete(
const char *cmd);
401 int Help(
const char *args,
char *reply);
int Help(const char *args, char *reply)
Get help-text.
Definition ngcbCMD_LIST.cpp:242
int Execute(const char *cmd, ngcb_cmd_handle_t *handle, char *reply)
Execute command.
Definition ngcbCMD_LIST.cpp:160
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:83
void Sort()
Sort list alphabetically.
Definition ngcbCMD_LIST.cpp:153
int Status()
Return Status (0=open, 1=complete)
Definition ngcbCMD_LIST.cpp:71
int Defined(const char *cmd)
Check if command is defined.
Definition ngcbCMD_LIST.cpp:73
ngcbCMD_LIST(ngcbCMD_SRV *server)
Constructor.
Definition ngcbCMD_LIST.cpp:37
void Close()
Close command factory - no further commands can be added.
Definition ngcbCMD_LIST.cpp:67
void Delete(const char *cmd)
Delete command from the command list.
Definition ngcbCMD_LIST.cpp:137
virtual ~ngcbCMD_LIST()
Destructor.
Definition ngcbCMD_LIST.cpp:57
void Open()
Open command factory - further commands can be added.
Definition ngcbCMD_LIST.cpp:69
Definition ngcbCMD.hpp:218
int Locked()
Return locked status.
Definition ngcbCMD_SRV.cpp:180
void DiscardDetIdx(char *key)
Discard DETi index.
Definition ngcbCMD_SRV.cpp:309
int KeyValFmt(const char *key, int *value)
Get 32-bit signed integer value from string.
Definition ngcbCMD_SRV.cpp:293
void Unlock()
Unlock command system.
Definition ngcbCMD_SRV.cpp:176
virtual ~ngcbCMD_SRV()
Destructor.
Definition ngcbCMD_SRV.cpp:38
int KeyValFrac(const char *key, unsigned int n, uint64_t *v1, uint64_t *v2)
Fraction after n digits.
Definition ngcbCMD_SRV.cpp:303
int LogIn(const char *s)
Login to trusted mode with a key in the format "name:password".
Definition ngcbCMD_SRV.cpp:187
int LoggedIn()
Return login status.
Definition ngcbCMD_SRV.cpp:255
void StringReset(char *s, size_t size=256)
Fill string with zeros.
Definition ngcbCMD_SRV.cpp:319
ngcbCMD_SRV()
Constructor.
Definition ngcbCMD_SRV.cpp:28
int KeyIdx(char *key, const char *mask)
Get the index after the first occurrence of mask in the keyword.
Definition ngcbCMD_SRV.cpp:314
void AssignPassword(const char *fileName)
Assign password from file.
Definition ngcbCMD_SRV.cpp:51
int KeyValHex(const char *key, int *value)
Get 32-bit signed integer value from hexadecimal keyword string.
Definition ngcbCMD_SRV.cpp:283
const char * PW()
Return password.
Definition ngcbCMD_SRV.cpp:163
int KeyVal(const char *key, float *value)
Get single precision floating point value from keyword string.
Definition ngcbCMD_SRV.cpp:263
void Lock()
Lock command system.
Definition ngcbCMD_SRV.cpp:172
void LogOut()
Log out.
Definition ngcbCMD_SRV.cpp:247
void Encrypt(char *s, const char *key=NULL)
Encrypt string with key.
Definition ngcbCMD_SRV.cpp:117
Definition ngcbCMD.hpp:41
virtual ~ngcb_cmd_handle_t()
Destructor.
Definition ngcbCMD.hpp:67
int Param(const char *p, const char *filter=NULL)
Assign parameter string.
Definition ngcbCMD.hpp:113
int Get(const char *filter, double *v)
Get filtered double precision parameter.
Definition ngcbCMD.hpp:188
int Get(const char *filter, char *s)
Get filtered string parameter.
Definition ngcbCMD.hpp:183
unsigned int GetX(const char *filter)
Get filtered 32-bit unsigned integer parameter.
Definition ngcbCMD.hpp:198
int done
Done flag.
Definition ngcbCMD.hpp:50
void * udata
Forwarded user data.
Definition ngcbCMD.hpp:47
int fd
File descriptor of command source.
Definition ngcbCMD.hpp:53
int Id(const char *filter)
Format parameter string and return filtered component id.
Definition ngcbCMD.hpp:73
int Get(const char *filter)
Get filtered 32-bit signed integer parameter.
Definition ngcbCMD.hpp:193
int Id()
Return component id.
Definition ngcbCMD.hpp:70
char * Param()
Return parameter string.
Definition ngcbCMD.hpp:180
ngcb_cmd_handle_t()
Constructor.
Definition ngcbCMD.hpp:56
int flags
Forwarded flags (ngcbCMD_UPDATE, ngcbCMD_PROTECTED)
Definition ngcbCMD.hpp:44
Definition ngcbCMD.hpp:313
int flags
Flags (ngcbCMD_UPDATE, ngcbCMD_PROTECTED)
Definition ngcbCMD.hpp:325
ngcb_function_t function
Command handling function.
Definition ngcbCMD.hpp:316
ngcb_cmd_t(const char *name)
Constructor.
Definition ngcbCMD.hpp:336
char syntax[256]
Syntax string (for help)
Definition ngcbCMD.hpp:319
void * udata
User data to be forwarded.
Definition ngcbCMD.hpp:328
char help[1024]
Help text.
Definition ngcbCMD.hpp:322
void Syntax(const char *s)
Assign syntax.
Definition ngcbCMD.hpp:357
void Help(const char *s)
Assign help text.
Definition ngcbCMD.hpp:364
virtual ~ngcb_cmd_t()
Destructor.
Definition ngcbCMD.hpp:346
static bool Compare(const ngcb_cmd_t *a, const ngcb_cmd_t *b)
Comparison function.
Definition ngcbCMD.hpp:349
bool operator<(const ngcb_cmd_t &other) const
Comparison operator.
Definition ngcbCMD.hpp:331
const char * Cmd() const
Return command name.
Definition ngcbCMD.hpp:354
#define ngcbCMD_ID_NOT_SET
Definition ngcbCMD.hpp:35
#define ngcbCMD_ID_IVLD
Definition ngcbCMD.hpp:34
int(ngcbCMD_SRV::* ngcb_function_t)(ngcb_cmd_handle_t *handle, char *reply)
Definition ngcbCMD.hpp:307
#define ngcbCMD_LIST_SIZE
Definition ngcbCMD.hpp:20
int ngcbF2S(const char *s, const char *filter, char *v)
Definition ngcbString.c:355
int ngcbF2Int(const char *s, const char *filter)
Definition ngcbString.c:412
int ngcbF2Double(const char *s, const char *filter, double *v)
Definition ngcbString.c:526
#define str2str(s1, s2, n)
Definition ngcb.h:73
unsigned int ngcbF2UInt(const char *s, const char *filter)
Definition ngcbString.c:474