1 // Copyright (C) 1999-2005 Open Source Telecom Corporation.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 //
17 // As a special exception, you may use this file as part of a free software
18 // library without restriction. Specifically, if other files instantiate
19 // templates or use macros or inline functions from this file, or you compile
20 // this file and link it with other files to produce an executable, this
21 // file does not by itself cause the resulting executable to be covered by
22 // the GNU General Public License. This exception does not however
23 // invalidate any other reasons why the executable file might be covered by
24 // the GNU General Public License.
25 //
26 // This exception applies only to the code released under the name GNU
27 // ccScript. If you copy code from other releases into a copy of GNU
28 // ccScript, as the General Public License permits, the exception does
29 // not apply to the code that you add in this way. To avoid misleading
30 // anyone as to the status of such modified files, you must delete
31 // this exception notice from them.
32 //
33 // If you write modifications of your own for GNU ccScript, it is your choice
34 // whether to permit this exception to apply to your modifications.
35 // If you do not wish that, delete this exception notice.
36 //
37
44 #ifndef CCXX_SCRIPT3_H_
45 #define CCXX_SCRIPT3_H_
46
47 #ifndef CCXX_MISC_H_
49 #endif
50
51 #ifndef CXXX_FILE_H_
53 #endif
54
55 #ifndef CCXX_BUFFER_H_
57 #endif
58
59 #define TRAP_BITS (sizeof(unsigned long) * 8)
60 #define SCRIPT_INDEX_SIZE KEYDATA_INDEX_SIZE
61 #define SCRIPT_MAX_ARGS 250
62 #define SCRIPT_TEMP_SPACE 16
63 #define SCRIPT_STACK_SIZE 32
64 #define SCRIPT_ROUTE_SLOTS 16
65 #define SCRIPT_EXEC_WRAPPER
66 #define SCRIPT_APPS_WRAPPER
67 #define SCRIPT_RIPPLE_LEVEL 2
68 #define SCRIPT_RIPPLE_KEYDATA
69 #define SCRIPT_BINDER_SELECT
70 #define SCRIPT_SERVER_PREFIX
71 #define SCRIPT_DEFINE_TOKENS
72
73 #ifndef CCXX_PACKING
74 #if defined(__GNUC__)
75 #define CCXX_PACKED
76 #elif !defined(__hpux) && !defined(_AIX)
78 #endif
79 #endif
80
81 namespace ost {
82
91
100 {
101 public:
104
108 typedef long (*Function)(
long *args,
unsigned prec);
111 typedef void (*Init)(void);
112
119 };
120
122
143 };
144
146
154
155 #ifdef CCXX_PACKED
156 #pragma pack(1)
157 #endif
158
160 unsigned short head,
tail, rec, count;
162
163 #ifdef CCXX_PACKED
164 #pragma pack()
165 #endif
166
167 public:
169 {
170 public:
172 union {
176 } scr;
179 unsigned short loop, line, lnum;
181 };
182
184 {
185 public:
190 };
191
193 {
194 public:
202 };
203
205 {
206 public:
210 };
211
213 {
214 public:
219 };
220
222 {
223 public:
227 };
228
230 {
231 public:
236 };
237
239 {
240 public:
243 };
244
246 {
247 public:
251
253 };
254
262
263 static bool isScript(
Name *scr);
264 static bool isSymbol(const char *id);
265 static bool use(const char *name);
266 static unsigned getIndex(const char *id);
268 static bool commit(
Symbol *sym,
const char *value);
269 static bool append(
Symbol *sym,
const char *value);
270 static bool symindex(
Symbol *sym,
short offset);
271 static const char *extract(
Symbol *sym);
272 static unsigned count(
Symbol *sym);
273 static unsigned storage(
Symbol *sym);
274 static void clear(
Symbol *sym);
293
297
298 static void addFunction(const char *name, unsigned count, Function i);
299 static void addConditional(const char *name, Cond test);
300
301 static bool isPrivate(
Name *scr);
302 static bool isFunction(
Name *scr);
303
304 protected:
307
308 };
309
311 {
312 protected:
314
315 void purge(void);
316
317 public:
320
323
324 unsigned gathertype(Symbol **idx, unsigned max, const char *prefix, symType group);
325 unsigned gather(Symbol **idx, unsigned max, const char *prefix, const char *suffix);
326 Symbol *
find(
const char *
id,
unsigned short size = 0);
327 Symbol *make(const char *id, unsigned short size);
328
329 Symbol *setReference(const char *id, Symbol *target);
330 };
331
344 {
345 private:
350
351 #ifdef CCXX_PACKED
352 #pragma pack(1)
353 #endif
354
362
363 #ifdef CCXX_PACKED
364 #pragma pack()
365 #endif
366
376
377 protected:
381
382 virtual const char *getExternal(const char *opt);
383
384 public:
392 virtual bool isInput(
Line *line);
393
401 Method getHandler(const char *keyword);
402
410 bool control(char **args);
411
418 {return active;};
419
426 const char *getTrapName(unsigned id);
427
434 void aliasModule(const char *id, const char *use);
435
436 protected:
443 bool isInitial(const char *keyword);
444
453 const char *check(
char *command, Line *line,
ScriptImage *img);
454
461 virtual unsigned getTrapId(const char *name);
462
468 virtual unsigned long getTrapDefault(void);
469
475 virtual unsigned long getTrapHandler(Name *script);
476
484 virtual unsigned long getTrapMask(unsigned id);
485
494 virtual unsigned long getTrapModifier(const char *name);
495
504 virtual unsigned long getTrapMask(const char *name);
505
512 static bool hasKeywords(Line *line);
513
514 public:
522 static const char *findKeyword(Line *line, const char *keyword);
523
532 static const char *findKeyword(
ScriptImage *img, Line *line,
const char *keyword);
533
540 virtual void errlog(const char *level, const char *text);
541
542 public:
550 static bool useKeywords(Line *line, const char *list);
551
558 static unsigned getCount(Line *line);
559
566 static const char *getMember(Line *line);
567
568
569 protected:
577 static bool useMember(Line *line, const char *list);
578
586 static const char *getOption(Line *line, unsigned *index);
587
596
606 int trap(const char *name, bool inherited = true);
607
614 {return trap_count;};
615
619 bool isInherited(unsigned id);
620
629 virtual const char *check(Check chk, Line *line,
ScriptImage *img);
630
631 public:
636
641
648 {return activity;};
649
650 };
651
653 {
654 private:
658
662
663 protected:
665
670 virtual bool control(
ScriptImage *img,
char **args);
671 virtual void down(void);
673
674 public:
678
680 static void shutdown(void);
682 };
683
685 {
686 public:
688 };
689
691 {
692 public:
694 };
695
697 {
698 public:
703
708
717
726
735
744
755
765
775
785
795
805
807
809
811
813
815
817
819
821
823
825
827
829
831
833
835
837
839
841
843
845
847
849
851
853
855
857
859
861
863
865
867
869
871
873
875
877
879
881
883
885 };
886
895 {
896 private:
899
900 protected:
903 };
904
915 {
916 protected:
918
928
930 {
931 public:
933 } *ilist;
934
936
944 {return cmds->getHandler(keyword);};
945
946 public:
953 void *getMemory(size_t size);
954
962
967
974 {return current;};
975
981 void addSelect(Line *line);
982
988 void addRegistration(Line *line);
989
996
1003 void addRoute(Line *line, unsigned pri);
1004
1011 {return select;};
1012
1019 {return registration;};
1020
1027 {return advertising[pri];};
1028
1033 {return instance;};
1034
1044
1049
1053 void purge(void);
1054
1060 void commit(void);
1061
1068
1076 void initial(const char *keyword, const char *value, unsigned size = 0);
1077
1084 virtual Name *getScript(const char *name);
1085
1092 {return cmds;};
1093
1100 {return cmds->ripple;};
1101
1110 unsigned gather(const char *suffix, Name **array, unsigned size);
1111
1116 {++refcount;};
1117
1122 {--refcount;};
1123
1130 {return (bool)(refcount > 0);};
1131
1139 };
1140
1151 {
1152 protected:
1161 const char *incfiles[256];
1162
1169
1171
1173
1174 virtual bool checkSegment(
Name *scr);
1175
1176 public:
1177 char *getToken(char **pre = NULL);
1178
1183
1193
1201 Name *include(
const char *name);
1202
1211 int compile(const char *file);
1212
1221 int compile(const char *file, char *name);
1222
1230 int compileDefinitions(const char *file);
1231
1240 int compile(std::istream *stream, char *name, const char *file = NULL);
1241
1247 void commit(void);
1248
1255 virtual const char *getDefined(const char *token);
1256
1263 const char *preproc(const char *token);
1264
1272 {return (std::istream *)&scrSource;};
1273 };
1274
1276 {
1277 protected:
1281
1282 public:
1284 {
1285 public:
1295 unsigned decimal : 4;
1297 };
1298
1299 static long getRealValue(double val, unsigned prec);
1300 static double getDouble(long value, unsigned prec);
1301 static long getInteger(long value, unsigned prec);
1302 static long getTens(unsigned prec);
1303 long getIntValue(
const char *text,
unsigned prec,
ScriptProperty *property = NULL);
1304 int numericExpression(
long *list,
int max,
unsigned prec,
ScriptProperty *property = NULL);
1305 bool conditionalExpression(void);
1306 bool conditional(void);
1307
1308 protected:
1321
1322 public:
1323 virtual unsigned getId(void);
1324
1326 {return sequence;};
1327
1329 {return logname;};
1330
1332
1333 virtual const char *getExternal(const char *opt);
1334
1336 {return image;};
1337
1338 protected:
1340
1342
1343 public:
1344 const char *getMember(void);
1345 const char *getKeyword(const char *kw);
1346 const char *getKeyoption(const char *kw);
1347 const char *getValue(const char *def = NULL);
1348 const char *getOption(const char *def = NULL);
1349 const char *hasOption(void);
1350 const char *getContent(const char *opt);
1351 const char *getSymContent(const char *opt);
1352 Symbol *getKeysymbol(const char *kw, unsigned size = 0);
1353 Symbol *getSymbol(unsigned short size = 0);
1354 char getPackToken(void);
1355
1356 protected:
1360 void initRuntime(Name *name);
1361
1366 virtual void initialize(void);
1367
1368 public:
1370 {return &frame[stack];};
1371
1373 {
return frame[stack].
line;};
1374
1375 void setFrame(void);
1376
1378 {return frame[stack].script;};
1379
1381 {return trace;};
1382
1390 bool execute(Method method);
1391
1392 protected:
1398 bool push(void);
1399
1405 bool pull(void);
1406
1410 void clearStack(void);
1411
1415 void advance(void);
1416
1420 void skip(void);
1421
1429
1440 bool scriptEvent(const char *name, bool inhereted = true);
1441
1447 void gotoEvent(NamedEvent *event);
1448
1456 void trap(unsigned id);
1457
1464 bool tryCatch(const char *id);
1465
1472 void trap(const char *name);
1473
1474 public:
1475 virtual void logmissing(const char *id, const char *level = "undefined", const char *group = "symbol");
1476 virtual void logerror(const char *msg, const char *name = NULL);
1477
1478 Symbol *mapSymbol(const char *id, unsigned short = 0);
1479 Symbol *mapDirect(const char *id, unsigned short = 0);
1480
1481 protected:
1482 virtual bool isLocked(const char *id);
1483 virtual const char *remapLocal(void);
1484 virtual bool exit(void);
1486 virtual void exitThread(const char *msg);
1487 virtual void waitThread(void);
1488 virtual void startThread(void);
1489
1490 bool eventThread(const char *evt, bool flag = true);
1491
1492 bool redirect(const char *scr);
1493
1494 void ripple(void);
1495
1496 bool redirect(bool evflag);
1497
1498 unsigned long getMask(void);
1499
1500 public:
1501 bool setNumber(const char *id, const char *value = NULL, unsigned dec = 0);
1502 bool setSymbol(const char *id, const char *value = NULL, unsigned short size = 0);
1503 bool setConst(const char *id, const char *value);
1504 bool putSymbol(const char *id, const char *value, unsigned short size = 0);
1505 bool getSymbol(const char *id, char *buffer, unsigned short max);
1506 bool catSymbol(const char *id, const char *value, unsigned short size = 0);
1507
1508 const char *getSymbol(const char *id);
1509
1510 Name *getScript(const char *name);
1511
1513
1514 bool step(void);
1516 void detach(void);
1518
1522 void release(void);
1523
1533 bool signal(const char *name);
1534
1542 bool signal(unsigned id);
1543
1544 bool done(void);
1545
1547
1553 virtual void branching(void);
1554
1556 {return (image != NULL) && initialized;};
1557
1559 {return exiting;};
1560
1561 char *getTemp(void);
1562
1563 unsigned getTempSize(void);
1564 };
1565
1567 {
1568 public:
1569 bool scrNop(void);
1570 bool scrError(void);
1571 bool scrExit(void);
1572 bool scrDecimal(void);
1573 bool scrDefine(void);
1574 bool scrVar(void);
1575 bool scrType(void);
1576 bool scrNumber(void);
1577 bool scrSlog(void);
1578 bool scrExpr(void);
1579 bool scrIndex(void);
1580 bool scrOffset(void);
1581 bool scrRef(void);
1582 bool scrRestart(void);
1583 bool scrInit(void);
1584 bool intGoto(void);
1585 bool scrGoto(void);
1586 bool scrCall(void);
1587 bool scrReturn(void);
1588 bool scrBegin(void);
1589 bool scrEnd(void);
1590 bool scrConst(void);
1591 bool scrSequence(void);
1592 bool scrSet(void);
1593 bool scrArray(void);
1594 bool scrClear(void);
1595 bool scrConstruct(void);
1596 bool scrDeconstruct(void);
1597 bool scrPack(void);
1598 bool scrUnpack(void);
1599 bool scrLock(void);
1600 bool scrSession(void);
1601 bool scrSignal(void);
1602 bool scrThrow(void);
1603 bool scrInvoke(void);
1604 bool scrCounter(void);
1605 bool scrTimer(void);
1606 bool scrCase(void);
1607 bool scrEndcase(void);
1608 bool scrRemove(void);
1609 bool scrDo(void);
1610 bool scrRepeat(void);
1611 bool scrFor(void);
1612 bool scrForeach(void);
1613 bool scrLoop(void);
1614 bool scrContinue(void);
1615 bool scrBreak(void);
1616 bool scrIf(void);
1617 bool scrIfThen(void);
1618 bool scrThen(void);
1619 bool scrElse(void);
1620 bool scrEndif(void);
1621 };
1622
1624 {
1625 private:
1628
1629 protected:
1631
1633
1634 void exit(const char *errmsg = NULL);
1635
1636 void exitEvent(const char *evt, bool inherited = true);
1637
1639 {return exiting;};
1640
1641 inline bool putSymbol(
const char *
id,
const char *value,
unsigned short size = 0)
1642 {return interp->putSymbol(id, value, size);};
1643
1644 inline bool getSymbol(
const char *
id,
char *buffer,
unsigned short max)
1645 {return interp->getSymbol(id, buffer, max);};
1646
1647 inline bool addSymbol(
const char *
id,
char *buffer,
unsigned short max)
1648 {return interp->getSymbol(id, buffer, max);};
1649
1650 void block(void);
1651
1652 void unblock(void);
1653
1654 void lock(void);
1655
1656 void release(void);
1657
1658 public:
1660
1662 {return stacksize;};
1663
1666 };
1667
1677 {
1678 public:
1683 };
1684
1693 {
1694 private:
1696
1700
1701 public:
1709 virtual void set(const char *data, char *temp, unsigned size) = 0;
1710
1716 virtual unsigned prec(void);
1717
1725 virtual void setValue(char *data, unsigned short size, long value);
1726
1733 virtual bool isProperty(const char *data);
1734
1742 virtual void clear(char *data, unsigned size = 0);
1743
1749 virtual char token(void);
1750
1758 virtual void adjust(char *data, size_t size, long adjustment);
1759
1766 virtual long adjustValue(long value);
1767
1774 virtual long getValue(const char *data);
1775
1778
1780 };
1781
1782 }
1783
1784 #endif
1785
const char * cstring(const char *str)
unsigned getCount(void)
Get count of active traps.
std::istream * getSource(void)
Used by embedded interpreters to fetch script from the current source file.
static bool use_definitions
static const char * apps_prefix
class __EXPORT ScriptSymbols
bool putSymbol(const char *id, const char *value, unsigned short size=0)
#define SCRIPT_INDEX_SIZE
Memory management, configuration keydata objects and string tokenizer.
ScriptImage * getImage(void)
virtual const char * getLogname(void)
unsigned long getSequence(void)
__EXPORT AppLog & error(AppLog &sl)
Manipulator for error level.
Method getHandler(const char *keyword)
Get the interpreter method pointer for a given keyword.
static unsigned fastStepping
This class is used for DSO modules that impliment property extensions for scripting objects...
#define SCRIPT_STACK_SIZE
This class is used for registering scripts with an external registry.
ScriptRegistry * registry
The Mutex class is used to protect a section of code so that at any given time only a single thread c...
Files and dynamic loader services.
This class is used to associate (object) pointers with named strings.
Line * getSelect(void)
Get the selection list from the image.
__EXPORT char * find(const char *cs, char *str, size_t len=0)
static ScriptProperty * first
Name * getCurrent(void)
Get current entity being compiled...
unsigned long getInstance(void)
Get the session instance of the image.
bool addSymbol(const char *id, char *buffer, unsigned short max)
A derivable class to hold compiled script images for active processes.
class __EXPORT ScriptThread
bool getSymbol(const char *id, char *buffer, unsigned short max)
Keydata objects are used to load and hold "configuration" data for a given application.
static unsigned autoStepping
A linkable list of objects that can be destroyed when a script image is removed from memory...
#define SCRIPT_ROUTE_SLOTS
A derivable class to hold compiled script images for active processes.
static const char * exec_token
static const char * apps_extensions
#define SCRIPT_TEMP_SPACE
Somewhat generic queue processing class to establish a producer consumer queue.
static unsigned long serial
static const char * plugins
static const char * exec_extensions
static const char * exit_token
Generic script class to hold master data types and various useful class encpasulated friend functions...
static const char * access_host
class __EXPORT ScriptCommand
static const char * access_user
unsigned getActivity(void)
Get activity counter.
bool isRipple(void)
Get the ripple flag for the current image.
static const char * etc_prefix
static const char * log_prefix
ScriptCommand * getCommand(void)
Get the command object associated with the image.
const char *(ScriptCommand::* Check)(Line *line, ScriptImage *img)
static const char * altplugins
object passing services between threads.
The DSO dynamic loader class is used to load object files.
static const char * var_prefix
Every thread of execution in an application is created by instantiating an object of a class derived ...
bool isRef(void)
See if the image is referenced...
struct timespec * getTimeout(struct timespec *spec, timeout_t timeout)
ScriptImage * getActive(void)
Get the active image from command.
char * dupString(const char *src, size_t size=0)
Timer ports are used to provide synchronized timing events when managed under a "service thread" such...
class __EXPORT ScriptCompiler
class __EXPORT ScriptProperty
Line * getRegistration(void)
Get the registration list from the image.
void decRef(void)
dec the reference count.
class __EXPORT ScriptInterp
void incRef(void)
inc the reference count.
ScriptImage * getActive(void)
Get the active script.
Line * getRoute(unsigned pri)
Get an advertised priority record from the image.
static ScriptBinder * first
This class holds the bound keyword set for a given Bayonne style script interpreter.
class __EXPORT ScriptImage
static ScriptCommand * runtime
static const char * access_pass
static const char * exec_prefix