[SVN-NetXMS] revision 3294

From: NetXMS.org SVN Server <svn_at_DOMAIN_REMOVED>
Date: Wed, 4 Jun 2008 20:54:04 +0300

* { font-family: Consolas, Lucida Console, Courier New; font-size: 100%; }
h1 { font-size: 150%; }
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 100%; width: 100%; }
.highlight span { width: 100%; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .il { color: #009999 } /* Literal.Number.Integer.Long */

Info

Revision:3294
Author:victor

Date:2008-06-04 20:54:03 +0300 (Wed, 04 Jun 2008)

Comment:Improved script support in event message templates; started work on arrays in NXSL

Changes
U trunk/src/libnxsl/instruction.cpp
U trunk/src/libnxsl/libnxsl.h
U trunk/src/libnxsl/parser.l
U trunk/src/libnxsl/parser.y
U trunk/src/libnxsl/program.cpp
U trunk/src/server/core/dcitem.cpp
U trunk/src/server/core/events.cpp
U trunk/src/server/core/nxcore.dsp
U trunk/src/server/include/nms_script.h

Diff
Modified: trunk/src/libnxsl/instruction.cpp
===================================================================
--- trunk/src/libnxsl/instruction.cpp 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/libnxsl/instruction.cpp 2008-06-04 17:54:03 UTC (rev 3294)
@@ -1,7 +1,7 @@
 /*
 ** NetXMS - Network Management System
 ** NetXMS Scripting Language Interpreter
-** Copyright (C) 2005 Victor Kirhenshtein
+** Copyright (C) 2005, 2006, 2007, 2008 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: instruction.cpp
+** File: instruction.cpp
 **
 **/
 
@@ -87,6 +87,7 @@
       case OPCODE_SET:
       case OPCODE_CALL_EXTERNAL:
       case OPCODE_BIND:
+ case OPCODE_ARRAY:
       case OPCODE_INC:
       case OPCODE_DEC:
       case OPCODE_INCP:
@@ -113,6 +114,7 @@
       case OPCODE_CALL_EXTERNAL:
       case OPCODE_SET:
       case OPCODE_BIND:
+ case OPCODE_ARRAY:
       case OPCODE_INC:
       case OPCODE_DEC:
       case OPCODE_INCP:

Modified: trunk/src/libnxsl/libnxsl.h
===================================================================
--- trunk/src/libnxsl/libnxsl.h 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/libnxsl/libnxsl.h 2008-06-04 17:54:03 UTC (rev 3294)
@@ -102,6 +102,7 @@
 #define OPCODE_MATCH 45
 #define OPCODE_IMATCH 46
 #define OPCODE_CASE 47
+#define OPCODE_ARRAY 48
 
 
 //
@@ -151,6 +152,7 @@
    NXSL_Lexer *m_pLexer;
    NXSL_Stack *m_pAddrStack;
         NXSL_Stack *m_pBreakStack;
+ int m_idOpCode;
 
 public:
    NXSL_Compiler(void);
@@ -169,6 +171,9 @@
         void CloseBreakLevel(NXSL_Program *pScript);
         BOOL CanUseBreak(void) { return m_pBreakStack-&gt;Size() &gt; 0; }
         void NewBreakLevel(void) { m_pBreakStack-&gt;Push(new Queue); }
+
+ void SetIdentifierOperation(int opcode) { m_idOpCode = opcode; }
+ int GetIdentifierOperation(void) { return m_idOpCode; }
 };
 
 

Modified: trunk/src/libnxsl/parser.l
===================================================================
--- trunk/src/libnxsl/parser.l 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/libnxsl/parser.l 2008-06-04 17:54:03 UTC (rev 3294)
@@ -30,6 +30,7 @@
 
 %%
 
+&lt;INITIAL&gt;&quot;array&quot; return T_ARRAY;
 &lt;INITIAL&gt;&quot;break&quot; return T_BREAK;
 &lt;INITIAL&gt;&quot;case&quot; return T_CASE;
 &lt;INITIAL&gt;&quot;continue&quot; return T_CONTINUE;

Modified: trunk/src/libnxsl/parser.y
===================================================================
--- trunk/src/libnxsl/parser.y 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/libnxsl/parser.y 2008-06-04 17:54:03 UTC (rev 3294)
@@ -36,6 +36,7 @@
         NXSL_Instruction *pInstruction;
 }
 
+%token T_ARRAY
 %token T_BREAK
 %token T_CASE
 %token T_CONTINUE
@@ -147,12 +148,13 @@
                         pCompiler-&gt;Error(szErrorText);
                         pLexer-&gt;SetErrorState();
                 }
- free($2);
+ free($2);
+ pCompiler-&gt;SetIdentifierOperation(OPCODE_BIND);
         }
         ParameterDeclaration Block
-{
- pScript-&gt;AddInstruction(new NXSL_Instruction(pLexer-&gt;GetCurrLine(), OPCODE_RET_NULL));
-}
+ {
+ pScript-&gt;AddInstruction(new NXSL_Instruction(pLexer-&gt;GetCurrLine(), OPCODE_RET_NULL));
+ }
 ;
 
 ParameterDeclaration:
@@ -163,13 +165,13 @@
 IdentifierList:
         T_IDENTIFIER
         {
- pScript-&gt;AddInstruction(new NXSL_Instruction(pLexer-&gt;GetCurrLine(), OPCODE_BIND, $1));
+ pScript-&gt;AddInstruction(new NXSL_Instruction(pLexer-&gt;GetCurrLine(), pCompiler-&gt;GetIdentifierOperation(), $1));
         }
         &#39;,&#39; IdentifierList
 | T_IDENTIFIER
-{
- pScript-&gt;AddInstruction(new NXSL_Instruction(pLexer-&gt;GetCurrLine(), OPCODE_BIND, $1));
-}
+ {
+ pScript-&gt;AddInstruction(new NXSL_Instruction(pLexer-&gt;GetCurrLine(), pCompiler-&gt;GetIdentifierOperation(), $1));
+ }
 ;
 
 Block:
@@ -398,6 +400,7 @@
 | DoStatement
 | WhileStatement
 | SwitchStatement
+| ArrayStatement
 | T_BREAK &#39;;&#39;
 {
         if (pCompiler-&gt;CanUseBreak())
@@ -551,6 +554,10 @@
 Default:
         T_DEFAULT &#39;:&#39; StatementList
 |
+;
+
+ArrayStatement:
+ T_ARRAY { pCompiler-&gt;SetIdentifierOperation(OPCODE_ARRAY); } IdentifierList &#39;;&#39;
 ;
 
 FunctionCall:

Modified: trunk/src/libnxsl/program.cpp
===================================================================
--- trunk/src/libnxsl/program.cpp 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/libnxsl/program.cpp 2008-06-04 17:54:03 UTC (rev 3294)
@@ -53,7 +53,7 @@
    &quot;BIND&quot;, &quot;INC&quot;, &quot;DEC&quot;, &quot;NEG&quot;, &quot;NOT&quot;,
    &quot;BITNOT&quot;, &quot;CAST&quot;, &quot;REF&quot;, &quot;INCP&quot;, &quot;DECP&quot;,
    &quot;JNZ&quot;, &quot;LIKE&quot;, &quot;ILIKE&quot;, &quot;MATCH&quot;,
- &quot;IMATCH&quot;, &quot;CASE&quot;
+ &quot;IMATCH&quot;, &quot;CASE&quot;, &quot;ARRAY&quot;
 };
 
 
@@ -337,6 +337,7 @@
          case OPCODE_PUSH_VARIABLE:
          case OPCODE_SET:
          case OPCODE_BIND:
+ case OPCODE_ARRAY:
          case OPCODE_INC:
          case OPCODE_DEC:
          case OPCODE_INCP:

Modified: trunk/src/server/core/dcitem.cpp
===================================================================
--- trunk/src/server/core/dcitem.cpp 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/server/core/dcitem.cpp 2008-06-04 17:54:03 UTC (rev 3294)
@@ -25,108 +25,6 @@
 
 
 //
-// &quot;NetXMS node&quot; class
-//
-
-class NXSL_NodeClass : public NXSL_Class
-{
-public:
- NXSL_NodeClass();
-
- virtual NXSL_Value *GetAttr(NXSL_Object *pObject, char *pszAttr);
-};
-
-
-//
-// Implementation of &quot;NetXMS node&quot; class
-//
-
-NXSL_NodeClass::NXSL_NodeClass()
- :NXSL_Class()
-{
- strcpy(m_szName, &quot;NetXMS_Node&quot;);
-}
-
-NXSL_Value *NXSL_NodeClass::GetAttr(NXSL_Object *pObject, char *pszAttr)
-{
- Node *pNode;
- NXSL_Value *pValue = NULL;
- char szBuffer[256];
-
- pNode = (Node *)pObject-&gt;Data();
- if (!strcmp(pszAttr, &quot;name&quot;))
- {
- pValue = new NXSL_Value(pNode-&gt;Name());
- }
- else if (!strcmp(pszAttr, &quot;id&quot;))
- {
- pValue = new NXSL_Value(pNode-&gt;Id());
- }
- else if (!strcmp(pszAttr, &quot;ipAddr&quot;))
- {
- IpToStr(pNode-&gt;IpAddr(), szBuffer);
- pValue = new NXSL_Value(szBuffer);
- }
- else if (!strcmp(pszAttr, &quot;isAgent&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_NATIVE_AGENT) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isSNMP&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_SNMP) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isBridge&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_BRIDGE) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isRouter&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_ROUTER) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isPrinter&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_PRINTER) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isCDP&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_CDP) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isSONMP&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_SONMP) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;isLLDP&quot;))
- {
- pValue = new NXSL_Value((LONG)((pNode-&gt;Flags() &amp; NF_IS_LLDP) ? 1 : 0));
- }
- else if (!strcmp(pszAttr, &quot;snmpVersion&quot;))
- {
- pValue = new NXSL_Value((LONG)pNode-&gt;GetSNMPVersion());
- }
- else if (!strcmp(pszAttr, &quot;snmpOID&quot;))
- {
- pValue = new NXSL_Value(pNode-&gt;GetSNMPObjectId());
- }
- else if (!strcmp(pszAttr, &quot;agentVersion&quot;))
- {
- pValue = new NXSL_Value(pNode-&gt;GetAgentVersion());
- }
- else if (!strcmp(pszAttr, &quot;platformName&quot;))
- {
- pValue = new NXSL_Value(pNode-&gt;GetPlatformName());
- }
- return pValue;
-}
-
-
-//
-// &quot;NetXMS node&quot; class object
-//
-
-static NXSL_NodeClass m_nxslNodeClass;
-
-
-//
 // Get DCI value from within transformation script
 // First argument is a node object (passed to script via $node variable),
 // and second is DCI ID
@@ -1126,7 +1024,7 @@
       pEnv = new NXSL_Environment;
       pEnv-&gt;SetLibrary(g_pScriptLibrary);
                 pEnv-&gt;RegisterFunctionSet(sizeof(m_nxslDCIFunctions) / sizeof(NXSL_ExtFunction), m_nxslDCIFunctions);
- m_pScript-&gt;SetGlobalVariable(_T(&quot;$node&quot;), new NXSL_Value(new NXSL_Object(&amp;m_nxslNodeClass, m_pNode)));
+ m_pScript-&gt;SetGlobalVariable(_T(&quot;$node&quot;), new NXSL_Value(new NXSL_Object(&amp;g_nxslNodeClass, m_pNode)));
         
       if (m_pScript-&gt;Run(pEnv, 1, &amp;pValue) == 0)
       {
@@ -1980,7 +1878,7 @@
                                 pEnv = new NXSL_Environment;
                                 pEnv-&gt;SetLibrary(g_pScriptLibrary);
                                 if (m_pNode != NULL)
- script-&gt;SetGlobalVariable(_T(&quot;$node&quot;), new NXSL_Value(new NXSL_Object(&amp;m_nxslNodeClass, m_pNode)));
+ script-&gt;SetGlobalVariable(_T(&quot;$node&quot;), new NXSL_Value(new NXSL_Object(&amp;g_nxslNodeClass, m_pNode)));
 
                                 if (script-&gt;Run(pEnv) == 0)
                                 {

Modified: trunk/src/server/core/events.cpp
===================================================================
--- trunk/src/server/core/events.cpp 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/server/core/events.cpp 2008-06-04 17:54:03 UTC (rev 3294)
@@ -352,8 +352,9 @@
                                                         {
                                                                 pEnv = new NXSL_Environment;
                                                                 pEnv-&gt;SetLibrary(g_pScriptLibrary);
-// if (m_pNode != NULL)
-// script-&gt;SetGlobalVariable(_T(&quot;$node&quot;), new NXSL_Value(new NXSL_Object(&amp;m_nxslNodeClass, m_pNode)));
+ if (pObject-&gt;Type() == OBJECT_NODE)
+ script-&gt;SetGlobalVariable(_T(&quot;$node&quot;), new NXSL_Value(new NXSL_Object(&amp;g_nxslNodeClass, pObject)));
+ script-&gt;SetGlobalVariable(_T(&quot;$event&quot;), new NXSL_Value(new NXSL_Object(&amp;g_nxslEventClass, this)));
 
                                                                 if (script-&gt;Run(pEnv) == 0)
                                                                 {

Modified: trunk/src/server/core/nxcore.dsp
===================================================================
--- trunk/src/server/core/nxcore.dsp 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/server/core/nxcore.dsp 2008-06-04 17:54:03 UTC (rev 3294)
@@ -358,6 +358,10 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\nxsl_classes.cpp
+# End Source File
+# Begin Source File
+
 SOURCE=.\objects.cpp
 # End Source File
 # Begin Source File

Modified: trunk/src/server/include/nms_script.h
===================================================================
--- trunk/src/server/include/nms_script.h 2008-06-04 07:23:18 UTC (rev 3293)
+++ trunk/src/server/include/nms_script.h 2008-06-04 17:54:03 UTC (rev 3294)
@@ -1,6 +1,6 @@
 /*
 ** NetXMS - Network Management System
-** Copyright (C) 2003, 2004, 2005, 2006 Victor Kirhenshtein
+** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 **
-** $module: nms_script.h
+** File: nms_script.h
 **
 **/
 
@@ -39,6 +39,32 @@
 
 
 //
+// &quot;NetXMS node&quot; class
+//
+
+class NXSL_NodeClass : public NXSL_Class
+{
+public:
+ NXSL_NodeClass();
+
+ virtual NXSL_Value *GetAttr(NXSL_Object *pObject, char *pszAttr);
+};
+
+
+//
+// &quot;NetXMS event&quot; class
+//
+
+class NXSL_EventClass : public NXSL_Class
+{
+public:
+ NXSL_EventClass();
+
+ virtual NXSL_Value *GetAttr(NXSL_Object *pObject, char *pszAttr);
+};
+
+
+//
 // Functions
 //
 
@@ -52,6 +78,8 @@
 //
 
 extern NXSL_Library *g_pScriptLibrary;
+extern NXSL_NodeClass g_nxslNodeClass;
+extern NXSL_EventClass g_nxslEventClass;
 
 
 #endif
Received on Wed Jun 04 2008 - 20:54:04 EEST

This archive was generated by hypermail 2.2.0 : Wed Jun 04 2008 - 20:51:32 EEST