Subversion Repositories tpanel

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 andreas 1
/*
101 andreas 2
 * Copyright (C) 2020 to 2022 by Andreas Theofilu <andreas@theosys.at>
11 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#include "tamxcommands.h"
209 andreas 20
#include "tpagemanager.h"
11 andreas 21
#include "terror.h"
22
#include "tresources.h"
14 andreas 23
#include "tconfig.h"
78 andreas 24
#include "texpat++.h"
326 andreas 25
#if TESTMODE == 1
26
#include "testmode.h"
27
#endif
11 andreas 28
 
83 andreas 29
#include <string>
30
#include <vector>
31
 
186 andreas 32
#if __cplusplus < 201402L
33
#   error "This module requires at least C++14 standard!"
34
#else
35
#   if __cplusplus < 201703L
36
#       include <experimental/filesystem>
37
namespace fs = std::experimental::filesystem;
38
#       warning "Support for C++14 and experimental filesystem will be removed in a future version!"
39
#   else
40
#       include <filesystem>
41
#       ifdef __ANDROID__
42
namespace fs = std::__fs::filesystem;
43
#       else
44
namespace fs = std::filesystem;
45
#       endif
46
#   endif
47
#endif
48
 
11 andreas 49
using std::string;
50
using std::vector;
78 andreas 51
using namespace Expat;
11 andreas 52
 
53
typedef struct CMD_DEFINATIONS
54
{
55
    string cmd;
56
    bool hasChannels{false};
57
    bool hasPars{false};
14 andreas 58
    char separator{0};
11 andreas 59
}CMD_DEFINATIONS;
60
 
61
CMD_DEFINATIONS cmdDefinations[] = {
14 andreas 62
    { "@WLD", false, true, ',' },
63
    { "@AFP", false, true, ',' },
127 andreas 64
    { "^AFP", false, true, ',' },
14 andreas 65
    { "@GCE", false, true, ',' },
127 andreas 66
    { "^GCE", false, true, ',' },
14 andreas 67
    { "@APG", false, true, ';' },
68
    { "@CPG", false, true, ',' },
69
    { "@DPG", false, true, ';' },
70
    { "@PDR", false, true, ';' },
71
    { "@PHE", false, true, ';' },
72
    { "@PHP", false, true, ';' },
73
    { "@PHT", false, true, ';' },
74
    { "@PPA", false, true, ',' },
104 andreas 75
    { "^PPA", false, true, ',' },
14 andreas 76
    { "@PPF", false, true, ';' },
104 andreas 77
    { "^PPF", false, true, ';' },
14 andreas 78
    { "@PPG", false, true, ';' },
104 andreas 79
    { "^PPG", false, true, ';' },
14 andreas 80
    { "@PPK", false, true, ',' },
104 andreas 81
    { "^PPK", false, true, ',' },
14 andreas 82
    { "@PPM", false, true, ';' },
104 andreas 83
    { "^PPM", false, true, ';' },
14 andreas 84
    { "@PPN", false, true, ';' },
104 andreas 85
    { "^PPN", false, true, ';' },
14 andreas 86
    { "@PPT", false, true, ';' },
104 andreas 87
    { "^PPT", false, true, ';' },
14 andreas 88
    { "@PPX", false, false, '\0' },
104 andreas 89
    { "^PPX", false, false, '\0' },
14 andreas 90
    { "@PSE", false, true, ';' },
91
    { "@PSP", false, true, ';' },
92
    { "@PST", false, true, ';' },
93
    { "PAGE", false, true, ',' },
104 andreas 94
    { "^PGE", false, true, ',' },
14 andreas 95
    { "PPOF", false, true, ';' },
96
    { "PPOG", false, true, ';' },
97
    { "PPON", false, true, ';' },
98
    { "^ANI", true, true, ',' },
99
    { "^APF", true, true, ',' },
100
    { "^BAT", true, true, ',' },
101
    { "^BAU", true, true, ',' },
102
    { "^BCB", true, true, ',' },
103
    { "?BCB", true, true, ',' },
104
    { "^BCF", true, true, ',' },
105
    { "?BCF", true, true, ',' },
106
    { "^BCT", true, true, ',' },
107
    { "?BCT", true, true, ',' },
108
    { "^BDO", true, true, ',' },
109
    { "^BFB", true, true, ',' },
110
    { "^BIM", true, true, ',' },
111
    { "^BLN", true, true, ',' },
112
    { "^BMC", true, true, ',' },
113
    { "^BMF", true, true, ',' },
114
    { "^BMI", true, true, ',' },
115
    { "^BML", true, true, ',' },
116
    { "^BMP", true, true, ',' },
117
    { "?BMP", true, true, ',' },
118
    { "^BNC", true, true, ',' },
119
    { "^BNN", true, true, ',' },
120
    { "^BNT", true, true, ',' },
121
    { "^BOP", true, true, ',' },
122
    { "?BOP", true, true, ',' },
123
    { "^BOR", true, true, ',' },
124
    { "^BOS", true, true, ',' },
125
    { "^BPP", true, true, ',' },
126
    { "^BRD", true, true, ',' },
127
    { "?BRD", true, true, ',' },
128
    { "^BSF", true, true, ',' },
129
    { "^BSP", true, true, ',' },
130
    { "^BSM", true, false, ',' },
131
    { "^BSO", true, true, ',' },
132
    { "^BVL", true, true, ',' },
133
    { "^BVN", false, true, ',' },
134
    { "^BVP", true, true, ',' },
135
    { "^BVT", true, true, ',' },
136
    { "^BWW", true, true, ',' },
137
    { "?BWW", true, true, ',' },
138
    { "^CPF", true, false, ',' },
139
    { "^DLD", false, false, ',' },
140
    { "^DPF", true, true, ',' },
141
    { "^ENA", true, true, ',' },
142
    { "^FON", true, true, ',' },
143
    { "?FON", true, true, ',' },
144
    { "^GDI", true, true, ',' },
145
    { "^GIV", true, true, ',' },
146
    { "^GLH", true, true, ',' },
147
    { "^GLL", true, true, ',' },
148
    { "^GRD", true, true, ',' },
149
    { "^GRU", true, true, ',' },
150
    { "^GSC", true, true, ',' },
151
    { "^GSN", true, true, ',' },
152
    { "^ICO", true, true, ',' },
153
    { "?ICO", true, true, ',' },
154
    { "^IRM", false, true, ',' },
155
    { "^JSB", true, true, ',' },
156
    { "?JSB", true, true, ',' },
157
    { "^JSI", true, true, ',' },
158
    { "?JSI", true, true, ',' },
159
    { "^JST", true, true, ',' },
160
    { "?JST", true, true, ',' },
395 andreas 161
    { "^MSP", true, true, ',' },
14 andreas 162
    { "^MBT", false, false, ',' },
163
    { "^MDC", false, false, ',' },
164
    { "^SHO", true, true, ',' },
165
    { "^TEC", true, true, ',' },
166
    { "?TEC", true, true, ',' },
167
    { "^TEF", true, true, ',' },
168
    { "?TEF", true, true, ',' },
169
    { "^TOP", false, true, ',' },
170
    { "^TXT", true, true, ',' },
171
    { "?TXT", true, true, ',' },
172
    { "^UNI", true, true, ',' },
104 andreas 173
    { "^UTF", true, true, ',' },
14 andreas 174
    { "^LPC", false, true, ',' },
175
    { "^LPR", false, true, ',' },
176
    { "^LPS", false, true, ',' },
177
    { "ABEEP", false, false, ',' },
178
    { "ADBEEP", false, false, ',' },
179
    { "@AKB", false, true, ';' },
180
    { "AKEYB", false, true, ',' },
181
    { "AKEYP", false, true, ',' },
182
    { "AKEYR", false, true, ',' },
183
    { "@AKP", false, true, ';' },
184
    { "@AKR", false, false, ',' },
185
    { "BEEP", false, false, ',' },
104 andreas 186
    { "^ABP", false, false, ',' },
14 andreas 187
    { "BRIT", false, true, ',' },
188
    { "@BRT", false, true, ',' },
189
    { "DBEEP", false, false, ',' },
104 andreas 190
    { "^ADP", false, false, ',' },
14 andreas 191
    { "@EKP", false, true, ';' },
192
    { "PKEYP", false, true, ',' },
63 andreas 193
    { "@PKB", false, true, ';' },
104 andreas 194
    { "^PKB", false, true, ';' },
14 andreas 195
    { "@PKP", false, true, ';' },
104 andreas 196
    { "^PKP", false, true, ';' },
14 andreas 197
    { "SETUP", false, false, ',' },
104 andreas 198
    { "^STP", false, false, ',' },
14 andreas 199
    { "SHUTDOWN", false, false, ',' },
200
    { "SLEEP", false, false, ',' },
201
    { "@SOU", false, true, ',' },
104 andreas 202
    { "^SOU", false, true, ',' },
14 andreas 203
    { "@TKP", false, true, ';' },
104 andreas 204
    { "^TKP", false, true, ';' },
14 andreas 205
    { "TPAGEON", false, false, ',' },
206
    { "TPAGEOFF", false, false, ',' },
207
    { "@VKB", false, false, ',' },
104 andreas 208
    { "^VKB", false, false, ',' },
14 andreas 209
    { "WAKE", false, false, ',' },
210
    { "^CAL", false, false, ',' },
211
    { "^KPS", false, true, ',' },
212
    { "^VKS", false, true, ',' },
127 andreas 213
    { "^WCN?", false, true, ',' },
14 andreas 214
    { "@PWD", false, true, ',' },
215
    { "^PWD", false, true, ',' },
216
    { "^BBR", true, true, ',' },
217
    { "^RAF", false, true, ',' },
218
    { "^RFR", false, true, ',' },
219
    { "^RMF", false, true, ',' },
220
    { "^RSR", false, true, ',' },
221
    { "^MODEL?", false, false, ',' },
127 andreas 222
    { "^MOD", false, false, ',' },
223
    { "^VER?", false, false, ',' },
14 andreas 224
    { "^ICS", false, true, ',' },
225
    { "^ICE", false, false, ',' },
226
    { "^ICM", false, true, ',' },
227
    { "^PHN", false, true, ',' },
228
    { "?PHN", false, true, ',' },
233 andreas 229
    { "^LVC", false, true, ',' },
227 andreas 230
    { "^LVD", true, true, ',' },
231
    { "^LVE", true, true, ',' },
232
    { "^LVF", true, true, ',' },
233 andreas 233
    { "^LVL", true, true, ',' },
234
    { "^LVM", true, true, '|' },
235
    { "^LVN", true, true, ',' },
236
    { "^LVR", true, true, ',' },
237
    { "^LVS", true, true, ',' },
127 andreas 238
    { "GET ", false, false, ',' },
239
    { "SET ", false, false, ',' },
14 andreas 240
    { "LEVON", false, false, ',' },
318 andreas 241
    { "LEVOF", false, false, ',' },
14 andreas 242
    { "RXON", false, false, ',' },
243
    { "ON", false, true, ',' },
244
    { "OFF", false, true, ',' },
15 andreas 245
    { "LEVEL", false, true, ',' },
246
    { "BLINK", false, true, ',' },
23 andreas 247
    { "#FTR", false, true, ':' },
134 andreas 248
    { "TPCCMD", false, true, ',' },
249
    { "TPCACC", false, true, ',' },
153 andreas 250
    { "TPCSIP", false, true, ',' },
300 andreas 251
    { "^EPR", true, true, ',' },
252
    { "^SCE", true, true, ',' },
253
    { "^SDR", true, true, ',' },
318 andreas 254
    { "^SHA", true, false, ',' },
300 andreas 255
    { "^SHD", true, true, ',' },
256
    { "^SSH", true, true, ',' },
257
    { "^STG", true, true, ',' },
326 andreas 258
    { "^MUT", false, true, ',' },
14 andreas 259
    { "", false, false, '\0' }
11 andreas 260
};
261
 
262
CMD_DEFINATIONS& findCmdDefines(const string& cmd)
263
{
264
    DECL_TRACER("findCmdDefines(const string& cmd)");
265
 
266
    int i = 0;
101 andreas 267
    string uCmd = cmd;
268
    uCmd = toUpper(uCmd);
11 andreas 269
 
270
    while (cmdDefinations[i].cmd.length() > 0)
271
    {
101 andreas 272
        if (cmdDefinations[i].cmd.compare(uCmd) == 0)
11 andreas 273
            return cmdDefinations[i];
274
 
275
        i++;
276
    }
277
 
278
    return cmdDefinations[i];
279
}
280
 
281
TAmxCommands::TAmxCommands()
282
{
283
    DECL_TRACER("TAmxCommands::TAmxCommands()");
284
}
285
 
286
TAmxCommands::~TAmxCommands()
287
{
288
    DECL_TRACER("TAmxCommands::~TAmxCommands()");
194 andreas 289
 
290
    if (mMap && mSystemMap && mMap != mSystemMap)
291
    {
292
        delete mMap;
293
        delete mSystemMap;
294
    }
295
    else if (mMap)
296
        delete mMap;
297
    else if (mSystemMap)
298
        delete mSystemMap;
11 andreas 299
}
300
 
14 andreas 301
bool TAmxCommands::readMap()
302
{
303
    DECL_TRACER("TAmxCommands::readMap()");
304
 
193 andreas 305
    bool err = false;
186 andreas 306
    string projectPath = TConfig::getProjectPath();
307
 
193 andreas 308
    if (fs::exists(projectPath + "/prj.xma"))
88 andreas 309
    {
194 andreas 310
        mMap = new TMap(projectPath);
193 andreas 311
        err = mMap->haveError();
88 andreas 312
    }
14 andreas 313
 
193 andreas 314
    projectPath += "/__system";
14 andreas 315
 
193 andreas 316
    if (fs::exists(projectPath + "/prj.xma"))
14 andreas 317
    {
194 andreas 318
        mSystemMap = new TMap(projectPath);
14 andreas 319
 
193 andreas 320
        if (!err)
194 andreas 321
            err = mSystemMap->haveError();
14 andreas 322
    }
323
 
194 andreas 324
    if (!mMap)
325
        mMap = mSystemMap;
326
 
193 andreas 327
    return !err;
14 andreas 328
}
329
 
330
vector<string> TAmxCommands::getFields(string& msg, char sep)
331
{
332
    DECL_TRACER("TAmxCommands::getFields(string& msg, char sep)");
333
 
334
    vector<string> flds;
335
    bool bStr = false;
336
    string part;
337
 
16 andreas 338
    for (size_t i = 0; i < msg.length(); i++)
14 andreas 339
    {
16 andreas 340
        if (msg.at(i) == sep && !bStr)
14 andreas 341
        {
342
            flds.push_back(part);
343
            part.clear();
344
            continue;
345
        }
16 andreas 346
        else if (msg.at(i) == '\'' && !bStr)
14 andreas 347
            bStr = true;
16 andreas 348
        else if (msg.at(i) == '\'' && bStr)
14 andreas 349
            bStr = false;
350
        else
16 andreas 351
            part.append(msg.substr(i, 1));
14 andreas 352
    }
353
 
354
    if (!part.empty())
355
        flds.push_back(part);
356
 
83 andreas 357
    if (flds.size() > 0 && TStreamError::checkFilter(HLOG_DEBUG))
14 andreas 358
    {
359
        MSG_DEBUG("Found fields:");
360
        vector<string>::iterator iter;
361
        int i = 1;
362
 
118 andreas 363
        for (iter = flds.begin(); iter != flds.end(); ++iter)
14 andreas 364
        {
365
            MSG_DEBUG("    " << i << ": " << *iter);
366
            i++;
367
        }
368
    }
369
 
370
    return flds;
371
}
372
 
193 andreas 373
vector<TMap::MAP_T> TAmxCommands::findButtons(int port, vector<int>& channels, TMap::MAP_TYPE mt)
14 andreas 374
{
193 andreas 375
    DECL_TRACER("TAmxCommands::findButtons(int port, vector<int>& channels, TMap::MAP_TYPE mt)");
14 andreas 376
 
193 andreas 377
    vector<TMap::MAP_T> map;
14 andreas 378
 
209 andreas 379
    if (gPageManager && gPageManager->isSetupActive())
380
        map = mSystemMap->findButtons(port, channels, mt);
381
    else
382
        map = mMap->findButtons(port, channels, mt);
19 andreas 383
 
14 andreas 384
    return map;
385
}
386
 
165 andreas 387
string TAmxCommands::findImage(int bt, int page, int instance)
388
{
389
    DECL_TRACER("TAmxCommands::findImage(int bt, int page, int instance)");
390
 
209 andreas 391
    if (page < SYSTEM_PAGE_START)
193 andreas 392
        return mMap->findImage(bt, page, instance);
165 andreas 393
 
193 andreas 394
    return mSystemMap->findImage(bt, page, instance);
165 andreas 395
}
396
 
397
string TAmxCommands::findImage(const string& name)
398
{
399
    DECL_TRACER("TAmxCommands::findImage(const string& name)");
400
 
193 andreas 401
    string str = mMap->findImage(name);
165 andreas 402
 
193 andreas 403
    if (str.empty())
404
        return mSystemMap->findImage(name);
165 andreas 405
 
193 andreas 406
    return str;
165 andreas 407
}
408
 
193 andreas 409
vector<TMap::MAP_T> TAmxCommands::findButtonByName(const string& name)
97 andreas 410
{
411
    DECL_TRACER("TAmxCommands::findButtonByName(const string& name)");
412
 
193 andreas 413
    vector<TMap::MAP_T> map = mMap->findButtonByName(name);
97 andreas 414
 
193 andreas 415
    if (map.empty())
416
        return mSystemMap->findButtonByName(name);
97 andreas 417
 
418
    return map;
419
}
420
 
193 andreas 421
vector<TMap::MAP_T> TAmxCommands::findBargraphs(int port, vector<int>& channels)
15 andreas 422
{
423
    DECL_TRACER("TAmxCommands::findBargraphs(int port, vector<int>& channels)");
424
 
193 andreas 425
    vector<TMap::MAP_T> map = mMap->findBargraphs(port, channels);
15 andreas 426
 
193 andreas 427
    if (map.empty())
428
        return mSystemMap->findBargraphs(port, channels);
83 andreas 429
 
15 andreas 430
    return map;
431
}
432
 
107 andreas 433
vector<string> TAmxCommands::findSounds()
434
{
435
    DECL_TRACER("TAmxCommands::findSounds()");
436
 
193 andreas 437
    return mMap->findSounds();      // This is enough because there are no sounds in the system settings
107 andreas 438
}
439
 
118 andreas 440
bool TAmxCommands::soundExist(const string& sname)
107 andreas 441
{
442
    DECL_TRACER("TAmxCommands::soundExist(const string sname)");
443
 
193 andreas 444
    return mMap->soundExist(sname);
107 andreas 445
}
446
 
11 andreas 447
bool TAmxCommands::parseCommand(int device, int port, const string& cmd)
448
{
449
    DECL_TRACER("TAmxCommands::parseCommand(int device, int port, const string& cmd)");
169 andreas 450
 
11 andreas 451
    vector<CMD_TABLE>::iterator iter;
16 andreas 452
    size_t pos = cmd.find_first_of("-");
127 andreas 453
    int system = TConfig::getSystem();
454
    string scmd = getCommand(cmd);
11 andreas 455
 
127 andreas 456
    MSG_TRACE("Parsing for device <" << device << ":" << port << ":" << system << "> the command: " << scmd);
13 andreas 457
 
11 andreas 458
    if (pos != string::npos)    // Command with parameters
459
    {
460
        string rest = cmd.substr(pos + 1);
461
 
118 andreas 462
        for (iter = mCmdTable.begin(); iter != mCmdTable.end(); ++iter)
11 andreas 463
        {
13 andreas 464
            iter->channels.clear();
465
            iter->pars.clear();
466
 
153 andreas 467
            if (iter->cmd.compare(scmd) == 0 && iter->command)
11 andreas 468
            {
153 andreas 469
                CMD_DEFINATIONS cdef = findCmdDefines(scmd);
11 andreas 470
 
471
                if (cdef.cmd.empty())
472
                {
153 andreas 473
                    MSG_WARNING("Command \"" << scmd << "\" not found in command table! Ignoring it.");
11 andreas 474
                    continue;
475
                }
476
 
477
                if (cdef.hasChannels || cdef.hasPars)
478
                {
14 andreas 479
                    vector<string> parts = getFields(rest, cdef.separator);
11 andreas 480
 
481
                    if (cdef.hasChannels)
13 andreas 482
                        extractChannels(parts[0], &iter->channels);
11 andreas 483
 
484
                    if (cdef.hasPars)
485
                    {
13 andreas 486
                        MSG_DEBUG("Command may have parameters. Found " << parts.size() << " parameters.");
11 andreas 487
 
13 andreas 488
                        if (parts.size() > 0)
11 andreas 489
                        {
13 andreas 490
                            vector<string>::iterator piter;
491
                            int cnt = 0;
492
 
118 andreas 493
                            for (piter = parts.begin(); piter != parts.end(); ++piter)
11 andreas 494
                            {
13 andreas 495
                                if (cdef.hasChannels && !cnt)
496
                                {
497
                                    cnt++;
498
                                    continue;
499
                                }
500
 
501
                                iter->pars.push_back(*piter);
11 andreas 502
                                cnt++;
503
                            }
504
                        }
13 andreas 505
                        else
506
                            iter->pars.push_back(rest);
11 andreas 507
                    }
508
                }
509
 
510
                iter->command(port, iter->channels, iter->pars);
511
                return true;
512
            }
513
        }
514
    }
515
    else        // Command without parameter
516
    {
118 andreas 517
        for (iter = mCmdTable.begin(); iter != mCmdTable.end(); ++iter)
11 andreas 518
        {
153 andreas 519
            if (iter->cmd.compare(scmd) == 0 && iter->command)
11 andreas 520
            {
521
                iter->command(port, iter->channels, iter->pars);
522
                return true;
523
            }
524
        }
525
    }
526
 
527
    MSG_WARNING("Command \"" << cmd << "\" currently not supported!");
326 andreas 528
#if TESTMODE == 1
529
    __done = true;
530
#endif
11 andreas 531
    return false;
532
}
533
 
534
bool TAmxCommands::extractChannels(const string& schan, vector<int>* ch)
535
{
536
    DECL_TRACER("TAmxCommands::extractChannels(const string& schan, vector<int>* ch)");
537
 
538
    if (!ch || schan.empty())
539
        return false;
540
 
16 andreas 541
    if (schan.find("&") == string::npos && schan.find(".") == string::npos)
11 andreas 542
    {
543
        int c = atoi(schan.c_str());
544
        ch->push_back(c);
545
        return true;
546
    }
547
 
548
    if (schan.find("&") != string::npos)
549
    {
550
        vector<string> parts = StrSplit(schan, "&");
551
        vector<string>::iterator iter;
552
 
83 andreas 553
        if (parts.size() > 0)
11 andreas 554
        {
118 andreas 555
            for (iter = parts.begin(); iter != parts.end(); ++iter)
11 andreas 556
            {
83 andreas 557
                if (iter->find(".") != string::npos)
558
                {
559
                    vector<string> p2 = StrSplit(*iter, ".");
11 andreas 560
 
83 andreas 561
                    if (p2.size() >= 2)
562
                    {
563
                        for (int i = atoi(p2[0].c_str()); i <= atoi(p2[1].c_str()); i++)
564
                            ch->push_back(i);
565
                    }
566
                    else if (p2.size() > 0)
567
                        ch->push_back(atoi(p2[0].c_str()));
38 andreas 568
                }
83 andreas 569
                else
570
                    ch->push_back(atoi(iter->c_str()));
11 andreas 571
            }
572
        }
573
    }
574
    else
575
    {
576
        vector<string> parts = StrSplit(schan, ".");
577
 
38 andreas 578
        if (parts.size() >= 2)
579
        {
60 andreas 580
            for (int i = atoi(parts[0].c_str()); i <= atoi(parts[1].c_str()); i++)
38 andreas 581
                ch->push_back(i);
582
        }
583
        else if (parts.size() > 0)
584
            ch->push_back(atoi(parts[0].c_str()));
11 andreas 585
    }
586
 
587
    return true;
588
}
589
 
590
void TAmxCommands::registerCommand(std::function<void (int port, vector<int>& channels, vector<string>& pars)> command, const string& name)
591
{
592
    DECL_TRACER("TAmxCommands::registerCommand(std::function<void (vector<int>& channels, vector<string>& pars)> command, const string& name)");
593
 
594
    vector<CMD_TABLE>::iterator iter;
595
 
118 andreas 596
    for (iter = mCmdTable.begin(); iter != mCmdTable.end(); ++iter)
11 andreas 597
    {
598
        if (iter->cmd.compare(name) == 0)
599
        {
600
            iter->command = command;
601
            iter->channels.clear();
602
            iter->pars.clear();
603
            return;
604
        }
605
    }
606
 
607
    CMD_TABLE ctbl;
608
    ctbl.cmd = name;
609
    ctbl.command = command;
610
    mCmdTable.push_back(ctbl);
611
}