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