f0d0d7bf2fef0c762f30a1e3d09a732beb4a2266
2 ** NetXMS - Network Management System
3 ** NetXMS Scripting Language Interpreter
4 ** Copyright (C) 2005-2010 Victor Kirhenshtein
6 ** This program is free software; you can redistribute it and/or modify
7 ** it under the terms of the GNU General Public License as published by
8 ** the Free Software Foundation; either version 2 of the License, or
9 ** (at your option) any later version.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 NXSL_Library
::NXSL_Library()
33 m_mutex
= MutexCreate();
35 m_ppScriptList
= NULL
;
45 NXSL_Library
::~NXSL_Library()
49 for(i
= 0; i
< m_dwNumScripts
; i
++)
51 delete m_ppScriptList
[i
];
54 safe_free(m_ppScriptList
);
55 safe_free(m_ppszNames
);
56 safe_free(m_pdwIdList
);
57 MutexDestroy(m_mutex
);
65 BOOL NXSL_Library
::addScript(DWORD dwId
, const TCHAR
*pszName
, NXSL_Program
*pScript
)
69 for(i
= 0; i
< m_dwNumScripts
; i
++)
70 if (!stricmp(m_ppszNames
[i
], pszName
))
74 m_ppScriptList
= (NXSL_Program
**)realloc(m_ppScriptList
, sizeof(NXSL_Program
*) * m_dwNumScripts
);
75 m_ppszNames
= (char **)realloc(m_ppszNames
, sizeof(char *) * m_dwNumScripts
);
76 m_pdwIdList
= (DWORD
*)realloc(m_pdwIdList
, sizeof(DWORD
) * m_dwNumScripts
);
77 m_ppScriptList
[i
] = pScript
;
78 m_ppszNames
[i
] = strdup(pszName
);
79 m_pdwIdList
[i
] = dwId
;
85 // Delete script from list
88 void NXSL_Library
::deleteInternal(int nIndex
)
90 delete m_ppScriptList
[nIndex
];
91 free(m_ppszNames
[nIndex
]);
93 memmove(&m_ppScriptList
[nIndex
], &m_ppScriptList
[nIndex
+ 1],
94 sizeof(NXSL_Program
*) * (m_dwNumScripts
- nIndex
));
95 memmove(&m_ppszNames
[nIndex
], &m_ppszNames
[nIndex
+ 1],
96 sizeof(char *) * (m_dwNumScripts
- nIndex
));
97 memmove(&m_pdwIdList
[nIndex
], &m_pdwIdList
[nIndex
+ 1],
98 sizeof(DWORD
) * (m_dwNumScripts
- nIndex
));
101 void NXSL_Library
::deleteScript(const TCHAR
*pszName
)
105 for(i
= 0; i
< m_dwNumScripts
; i
++)
106 if (!stricmp(m_ppszNames
[i
], pszName
))
113 void NXSL_Library
::deleteScript(DWORD dwId
)
117 for(i
= 0; i
< m_dwNumScripts
; i
++)
118 if (m_pdwIdList
[i
] == dwId
)
127 // Find script by name
130 NXSL_Program
*NXSL_Library
::findScript(const TCHAR
*pszName
)
134 for(i
= 0; i
< m_dwNumScripts
; i
++)
135 if (!stricmp(m_ppszNames
[i
], pszName
))
137 return m_ppScriptList
[i
];
144 // Fill NXCP message with script data
147 void NXSL_Library
::fillMessage(CSCPMessage
*pMsg
)
151 pMsg
->SetVariable(VID_NUM_SCRIPTS
, m_dwNumScripts
);
152 for(i
= 0, dwId
= VID_SCRIPT_LIST_BASE
; i
< m_dwNumScripts
; i
++)
154 pMsg
->SetVariable(dwId
++, m_pdwIdList
[i
]);
155 pMsg
->SetVariable(dwId
++, m_ppszNames
[i
]);