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, ',' },
400 andreas 174
    { "^LPB", true, true, ',' },
175
    { "^LPC", false, false, ',' },
14 andreas 176
    { "^LPR", false, true, ',' },
177
    { "^LPS", false, true, ',' },
178
    { "ABEEP", false, false, ',' },
179
    { "ADBEEP", false, false, ',' },
180
    { "@AKB", false, true, ';' },
181
    { "AKEYB", false, true, ',' },
182
    { "AKEYP", false, true, ',' },
183
    { "AKEYR", false, true, ',' },
184
    { "@AKP", false, true, ';' },
185
    { "@AKR", false, false, ',' },
186
    { "BEEP", false, false, ',' },
104 andreas 187
    { "^ABP", false, false, ',' },
14 andreas 188
    { "BRIT", false, true, ',' },
189
    { "@BRT", false, true, ',' },
190
    { "DBEEP", false, false, ',' },
104 andreas 191
    { "^ADP", false, false, ',' },
14 andreas 192
    { "@EKP", false, true, ';' },
193
    { "PKEYP", false, true, ',' },
63 andreas 194
    { "@PKB", false, true, ';' },
104 andreas 195
    { "^PKB", false, true, ';' },
14 andreas 196
    { "@PKP", false, true, ';' },
104 andreas 197
    { "^PKP", false, true, ';' },
14 andreas 198
    { "SETUP", false, false, ',' },
104 andreas 199
    { "^STP", false, false, ',' },
14 andreas 200
    { "SHUTDOWN", false, false, ',' },
201
    { "SLEEP", false, false, ',' },
202
    { "@SOU", false, true, ',' },
104 andreas 203
    { "^SOU", false, true, ',' },
14 andreas 204
    { "@TKP", false, true, ';' },
104 andreas 205
    { "^TKP", false, true, ';' },
14 andreas 206
    { "TPAGEON", false, false, ',' },
207
    { "TPAGEOFF", false, false, ',' },
208
    { "@VKB", false, false, ',' },
104 andreas 209
    { "^VKB", false, false, ',' },
14 andreas 210
    { "WAKE", false, false, ',' },
211
    { "^CAL", false, false, ',' },
212
    { "^KPS", false, true, ',' },
213
    { "^VKS", false, true, ',' },
127 andreas 214
    { "^WCN?", false, true, ',' },
14 andreas 215
    { "@PWD", false, true, ',' },
216
    { "^PWD", false, true, ',' },
217
    { "^BBR", true, true, ',' },
218
    { "^RAF", false, true, ',' },
219
    { "^RFR", false, true, ',' },
220
    { "^RMF", false, true, ',' },
221
    { "^RSR", false, true, ',' },
222
    { "^MODEL?", false, false, ',' },
127 andreas 223
    { "^MOD", false, false, ',' },
224
    { "^VER?", false, false, ',' },
14 andreas 225
    { "^ICS", false, true, ',' },
226
    { "^ICE", false, false, ',' },
227
    { "^ICM", false, true, ',' },
228
    { "^PHN", false, true, ',' },
229
    { "?PHN", false, true, ',' },
233 andreas 230
    { "^LVC", false, true, ',' },
227 andreas 231
    { "^LVD", true, true, ',' },
232
    { "^LVE", true, true, ',' },
233
    { "^LVF", true, true, ',' },
233 andreas 234
    { "^LVL", true, true, ',' },
235
    { "^LVM", true, true, '|' },
236
    { "^LVN", true, true, ',' },
237
    { "^LVR", true, true, ',' },
238
    { "^LVS", true, true, ',' },
127 andreas 239
    { "GET ", false, false, ',' },
240
    { "SET ", false, false, ',' },
14 andreas 241
    { "LEVON", false, false, ',' },
318 andreas 242
    { "LEVOF", false, false, ',' },
14 andreas 243
    { "RXON", false, false, ',' },
244
    { "ON", false, true, ',' },
245
    { "OFF", false, true, ',' },
15 andreas 246
    { "LEVEL", false, true, ',' },
247
    { "BLINK", false, true, ',' },
23 andreas 248
    { "#FTR", false, true, ':' },
134 andreas 249
    { "TPCCMD", false, true, ',' },
250
    { "TPCACC", false, true, ',' },
153 andreas 251
    { "TPCSIP", false, true, ',' },
300 andreas 252
    { "^EPR", true, true, ',' },
253
    { "^SCE", true, true, ',' },
254
    { "^SDR", true, true, ',' },
318 andreas 255
    { "^SHA", true, false, ',' },
300 andreas 256
    { "^SHD", true, true, ',' },
257
    { "^SSH", true, true, ',' },
258
    { "^STG", true, true, ',' },
326 andreas 259
    { "^MUT", false, true, ',' },
14 andreas 260
    { "", false, false, '\0' }
11 andreas 261
};
262
 
263
CMD_DEFINATIONS& findCmdDefines(const string& cmd)
264
{
265
    DECL_TRACER("findCmdDefines(const string& cmd)");
266
 
267
    int i = 0;
101 andreas 268
    string uCmd = cmd;
269
    uCmd = toUpper(uCmd);
11 andreas 270
 
271
    while (cmdDefinations[i].cmd.length() > 0)
272
    {
101 andreas 273
        if (cmdDefinations[i].cmd.compare(uCmd) == 0)
11 andreas 274
            return cmdDefinations[i];
275
 
276
        i++;
277
    }
278
 
279
    return cmdDefinations[i];
280
}
281
 
282
TAmxCommands::TAmxCommands()
283
{
284
    DECL_TRACER("TAmxCommands::TAmxCommands()");
285
}
286
 
287
TAmxCommands::~TAmxCommands()
288
{
289
    DECL_TRACER("TAmxCommands::~TAmxCommands()");
194 andreas 290
 
291
    if (mMap && mSystemMap && mMap != mSystemMap)
292
    {
293
        delete mMap;
294
        delete mSystemMap;
295
    }
296
    else if (mMap)
297
        delete mMap;
298
    else if (mSystemMap)
299
        delete mSystemMap;
11 andreas 300
}
301
 
14 andreas 302
bool TAmxCommands::readMap()
303
{
304
    DECL_TRACER("TAmxCommands::readMap()");
305
 
193 andreas 306
    bool err = false;
186 andreas 307
    string projectPath = TConfig::getProjectPath();
308
 
193 andreas 309
    if (fs::exists(projectPath + "/prj.xma"))
88 andreas 310
    {
194 andreas 311
        mMap = new TMap(projectPath);
193 andreas 312
        err = mMap->haveError();
88 andreas 313
    }
14 andreas 314
 
193 andreas 315
    projectPath += "/__system";
14 andreas 316
 
193 andreas 317
    if (fs::exists(projectPath + "/prj.xma"))
14 andreas 318
    {
194 andreas 319
        mSystemMap = new TMap(projectPath);
14 andreas 320
 
193 andreas 321
        if (!err)
194 andreas 322
            err = mSystemMap->haveError();
14 andreas 323
    }
324
 
194 andreas 325
    if (!mMap)
326
        mMap = mSystemMap;
327
 
193 andreas 328
    return !err;
14 andreas 329
}
330
 
331
vector<string> TAmxCommands::getFields(string& msg, char sep)
332
{
333
    DECL_TRACER("TAmxCommands::getFields(string& msg, char sep)");
334
 
335
    vector<string> flds;
336
    bool bStr = false;
337
    string part;
338
 
16 andreas 339
    for (size_t i = 0; i < msg.length(); i++)
14 andreas 340
    {
16 andreas 341
        if (msg.at(i) == sep && !bStr)
14 andreas 342
        {
343
            flds.push_back(part);
344
            part.clear();
345
            continue;
346
        }
16 andreas 347
        else if (msg.at(i) == '\'' && !bStr)
14 andreas 348
            bStr = true;
16 andreas 349
        else if (msg.at(i) == '\'' && bStr)
14 andreas 350
            bStr = false;
351
        else
16 andreas 352
            part.append(msg.substr(i, 1));
14 andreas 353
    }
354
 
355
    if (!part.empty())
356
        flds.push_back(part);
357
 
83 andreas 358
    if (flds.size() > 0 && TStreamError::checkFilter(HLOG_DEBUG))
14 andreas 359
    {
360
        MSG_DEBUG("Found fields:");
361
        vector<string>::iterator iter;
362
        int i = 1;
363
 
118 andreas 364
        for (iter = flds.begin(); iter != flds.end(); ++iter)
14 andreas 365
        {
366
            MSG_DEBUG("    " << i << ": " << *iter);
367
            i++;
368
        }
369
    }
370
 
371
    return flds;
372
}
373
 
193 andreas 374
vector<TMap::MAP_T> TAmxCommands::findButtons(int port, vector<int>& channels, TMap::MAP_TYPE mt)
14 andreas 375
{
193 andreas 376
    DECL_TRACER("TAmxCommands::findButtons(int port, vector<int>& channels, TMap::MAP_TYPE mt)");
14 andreas 377
 
193 andreas 378
    vector<TMap::MAP_T> map;
14 andreas 379
 
209 andreas 380
    if (gPageManager && gPageManager->isSetupActive())
381
        map = mSystemMap->findButtons(port, channels, mt);
382
    else
383
        map = mMap->findButtons(port, channels, mt);
19 andreas 384
 
14 andreas 385
    return map;
386
}
387
 
165 andreas 388
string TAmxCommands::findImage(int bt, int page, int instance)
389
{
390
    DECL_TRACER("TAmxCommands::findImage(int bt, int page, int instance)");
391
 
209 andreas 392
    if (page < SYSTEM_PAGE_START)
193 andreas 393
        return mMap->findImage(bt, page, instance);
165 andreas 394
 
193 andreas 395
    return mSystemMap->findImage(bt, page, instance);
165 andreas 396
}
397
 
398
string TAmxCommands::findImage(const string& name)
399
{
400
    DECL_TRACER("TAmxCommands::findImage(const string& name)");
401
 
193 andreas 402
    string str = mMap->findImage(name);
165 andreas 403
 
193 andreas 404
    if (str.empty())
405
        return mSystemMap->findImage(name);
165 andreas 406
 
193 andreas 407
    return str;
165 andreas 408
}
409
 
193 andreas 410
vector<TMap::MAP_T> TAmxCommands::findButtonByName(const string& name)
97 andreas 411
{
412
    DECL_TRACER("TAmxCommands::findButtonByName(const string& name)");
413
 
193 andreas 414
    vector<TMap::MAP_T> map = mMap->findButtonByName(name);
97 andreas 415
 
193 andreas 416
    if (map.empty())
417
        return mSystemMap->findButtonByName(name);
97 andreas 418
 
419
    return map;
420
}
421
 
193 andreas 422
vector<TMap::MAP_T> TAmxCommands::findBargraphs(int port, vector<int>& channels)
15 andreas 423
{
424
    DECL_TRACER("TAmxCommands::findBargraphs(int port, vector<int>& channels)");
425
 
193 andreas 426
    vector<TMap::MAP_T> map = mMap->findBargraphs(port, channels);
15 andreas 427
 
193 andreas 428
    if (map.empty())
429
        return mSystemMap->findBargraphs(port, channels);
83 andreas 430
 
15 andreas 431
    return map;
432
}
433
 
107 andreas 434
vector<string> TAmxCommands::findSounds()
435
{
436
    DECL_TRACER("TAmxCommands::findSounds()");
437
 
193 andreas 438
    return mMap->findSounds();      // This is enough because there are no sounds in the system settings
107 andreas 439
}
440
 
118 andreas 441
bool TAmxCommands::soundExist(const string& sname)
107 andreas 442
{
443
    DECL_TRACER("TAmxCommands::soundExist(const string sname)");
444
 
193 andreas 445
    return mMap->soundExist(sname);
107 andreas 446
}
447
 
11 andreas 448
bool TAmxCommands::parseCommand(int device, int port, const string& cmd)
449
{
450
    DECL_TRACER("TAmxCommands::parseCommand(int device, int port, const string& cmd)");
169 andreas 451
 
11 andreas 452
    vector<CMD_TABLE>::iterator iter;
16 andreas 453
    size_t pos = cmd.find_first_of("-");
127 andreas 454
    int system = TConfig::getSystem();
455
    string scmd = getCommand(cmd);
11 andreas 456
 
127 andreas 457
    MSG_TRACE("Parsing for device <" << device << ":" << port << ":" << system << "> the command: " << scmd);
13 andreas 458
 
11 andreas 459
    if (pos != string::npos)    // Command with parameters
460
    {
461
        string rest = cmd.substr(pos + 1);
462
 
118 andreas 463
        for (iter = mCmdTable.begin(); iter != mCmdTable.end(); ++iter)
11 andreas 464
        {
13 andreas 465
            iter->channels.clear();
466
            iter->pars.clear();
467
 
153 andreas 468
            if (iter->cmd.compare(scmd) == 0 && iter->command)
11 andreas 469
            {
153 andreas 470
                CMD_DEFINATIONS cdef = findCmdDefines(scmd);
11 andreas 471
 
472
                if (cdef.cmd.empty())
473
                {
153 andreas 474
                    MSG_WARNING("Command \"" << scmd << "\" not found in command table! Ignoring it.");
11 andreas 475
                    continue;
476
                }
477
 
478
                if (cdef.hasChannels || cdef.hasPars)
479
                {
14 andreas 480
                    vector<string> parts = getFields(rest, cdef.separator);
11 andreas 481
 
482
                    if (cdef.hasChannels)
13 andreas 483
                        extractChannels(parts[0], &iter->channels);
11 andreas 484
 
485
                    if (cdef.hasPars)
486
                    {
13 andreas 487
                        MSG_DEBUG("Command may have parameters. Found " << parts.size() << " parameters.");
11 andreas 488
 
13 andreas 489
                        if (parts.size() > 0)
11 andreas 490
                        {
13 andreas 491
                            vector<string>::iterator piter;
492
                            int cnt = 0;
493
 
118 andreas 494
                            for (piter = parts.begin(); piter != parts.end(); ++piter)
11 andreas 495
                            {
13 andreas 496
                                if (cdef.hasChannels && !cnt)
497
                                {
498
                                    cnt++;
499
                                    continue;
500
                                }
501
 
502
                                iter->pars.push_back(*piter);
11 andreas 503
                                cnt++;
504
                            }
505
                        }
13 andreas 506
                        else
507
                            iter->pars.push_back(rest);
11 andreas 508
                    }
509
                }
510
 
511
                iter->command(port, iter->channels, iter->pars);
512
                return true;
513
            }
514
        }
515
    }
516
    else        // Command without parameter
517
    {
118 andreas 518
        for (iter = mCmdTable.begin(); iter != mCmdTable.end(); ++iter)
11 andreas 519
        {
153 andreas 520
            if (iter->cmd.compare(scmd) == 0 && iter->command)
11 andreas 521
            {
522
                iter->command(port, iter->channels, iter->pars);
523
                return true;
524
            }
525
        }
526
    }
527
 
528
    MSG_WARNING("Command \"" << cmd << "\" currently not supported!");
326 andreas 529
#if TESTMODE == 1
530
    __done = true;
531
#endif
11 andreas 532
    return false;
533
}
534
 
535
bool TAmxCommands::extractChannels(const string& schan, vector<int>* ch)
536
{
537
    DECL_TRACER("TAmxCommands::extractChannels(const string& schan, vector<int>* ch)");
538
 
539
    if (!ch || schan.empty())
540
        return false;
541
 
16 andreas 542
    if (schan.find("&") == string::npos && schan.find(".") == string::npos)
11 andreas 543
    {
544
        int c = atoi(schan.c_str());
545
        ch->push_back(c);
546
        return true;
547
    }
548
 
549
    if (schan.find("&") != string::npos)
550
    {
551
        vector<string> parts = StrSplit(schan, "&");
552
        vector<string>::iterator iter;
553
 
83 andreas 554
        if (parts.size() > 0)
11 andreas 555
        {
118 andreas 556
            for (iter = parts.begin(); iter != parts.end(); ++iter)
11 andreas 557
            {
83 andreas 558
                if (iter->find(".") != string::npos)
559
                {
560
                    vector<string> p2 = StrSplit(*iter, ".");
11 andreas 561
 
83 andreas 562
                    if (p2.size() >= 2)
563
                    {
564
                        for (int i = atoi(p2[0].c_str()); i <= atoi(p2[1].c_str()); i++)
565
                            ch->push_back(i);
566
                    }
567
                    else if (p2.size() > 0)
568
                        ch->push_back(atoi(p2[0].c_str()));
38 andreas 569
                }
83 andreas 570
                else
571
                    ch->push_back(atoi(iter->c_str()));
11 andreas 572
            }
573
        }
574
    }
575
    else
576
    {
577
        vector<string> parts = StrSplit(schan, ".");
578
 
38 andreas 579
        if (parts.size() >= 2)
580
        {
60 andreas 581
            for (int i = atoi(parts[0].c_str()); i <= atoi(parts[1].c_str()); i++)
38 andreas 582
                ch->push_back(i);
583
        }
584
        else if (parts.size() > 0)
585
            ch->push_back(atoi(parts[0].c_str()));
11 andreas 586
    }
587
 
588
    return true;
589
}
590
 
591
void TAmxCommands::registerCommand(std::function<void (int port, vector<int>& channels, vector<string>& pars)> command, const string& name)
592
{
593
    DECL_TRACER("TAmxCommands::registerCommand(std::function<void (vector<int>& channels, vector<string>& pars)> command, const string& name)");
594
 
595
    vector<CMD_TABLE>::iterator iter;
596
 
118 andreas 597
    for (iter = mCmdTable.begin(); iter != mCmdTable.end(); ++iter)
11 andreas 598
    {
599
        if (iter->cmd.compare(name) == 0)
600
        {
601
            iter->command = command;
602
            iter->channels.clear();
603
            iter->pars.clear();
604
            return;
605
        }
606
    }
607
 
608
    CMD_TABLE ctbl;
609
    ctbl.cmd = name;
610
    ctbl.command = command;
611
    mCmdTable.push_back(ctbl);
612
}