Skip to content

Instantly share code, notes, and snippets.

@jbratu
Last active April 3, 2019 18:22
Show Gist options
  • Save jbratu/6d03f3dfcc57698c1e8e to your computer and use it in GitHub Desktop.
Save jbratu/6d03f3dfcc57698c1e8e to your computer and use it in GitHub Desktop.
Basic OpenInsight function library. Similar to a commuter module but not designed to be called from an event context.
Function OPENINSIGHT_ROUTINE_LIB(inMethod, Param1, Param2, Param3, Param4, Param5, Param6, outValue,outStat)
//To USE: Find and replace OPENINSIGHT_ROUTINE with your routine name
/*
Function: OPENINSIGHT_ROUTINE_LIB
>OPENINSIGHT_ROUTINE_LIB(inMethod, Param1, Param2, Param3, Param4, outValue,outStat)
General purpose library
Parameters:
inMethod - Varies depending On action.
Param1...Param4 - Varies depending On inMethod.
outValue - Unused. Optional Return value by reference.
outStat - Unused. Optional Return status by reference.
Revisions:
- History (Date, Initials, Notes)
-
*/
If Unassigned(inMethod) Then method = '' Else method = inMethod
If Unassigned(Param1) Then Param1 = ''
If Unassigned(Param2) Then Param2 = ''
If Unassigned(Param3) Then Param3 = ''
If Unassigned(Param4) Then Param4 = ''
If Unassigned(Param5) Then Param5 = ''
If Unassigned(Param6) Then Param6 = ''
If Unassigned(outValue) Then outValue = ''
If Unassigned(outStat) Then outStat = ''
RetVal = '' ; Err = ''
*
* Declare System
Declare Function Assigned, Msg, Repository, CS_RLIST_UTIL
Declare Subroutine Msg, Set_Status
*
* Declare App Routines
Declare Function OPENINSIGHT_ROUTINE_LIB, CS_RLIST_UTIL
Declare Subroutine OPENINSIGHT_ROUTINE_LIB
$INSERT Msg_Equates
$Insert Logical
/*
const: someConstant
Description of variable
*/
someConstant = "HI"
moduleName = "OPENINSIGHT_ROUTINE_LIB"
thisname = "OPENINSIGHT_ROUTINE_LIB"
viewName = "" ;* Optional RDK View to pre-create for this module deployment
*
*Main case branch
*
A_CommuterModuleTop:
Begin Case
Case Method _eqc 'methodname' ; Gosub yourMethodName_
Case Method _eqc 'getErrorCodes' ; Gosub getErrorCodes_
Case Method _eqc 'setStatus' ; Gosub setStatus_
Case Method _eqc 'buildModule' ; Gosub buildModule_
Case Otherwise$
A_CommuterModuleOtherwise:
Goto End
End Case
End:
Return RetVal
*
*End of the main branch
*
/*
interface:
>OPENINSIGHT_ROUTINE_LIB('yourMethodName')
Parameters:
Returns:
*/
yourMethodName_:
Return
/*
interface: setStatus
Wrapper around Set_Status that returns specific errors And messages related To this function
>OPENINSIGHT_ROUTINE_LIB('setStatus',ErrNum)
If you want To Return a custom error message:
>OPENINSIGHT_ROUTINE_LIB('setStatus',ErrNum, ErrCustomMsg)
Parameters:
ErrNum - Any error code number. If the error code is from getErrorCodes the message will automatically be included.
ErrCustommsg - A custom message To go along With the error code And standard getErrorCodes message
Returns:
RetVal - None.
*/
setStatus_:
ErrNum = Param1
ErrCustomMsg = Param2
ErrCodes = OPENINSIGHT_ROUTINE_LIB("getErrorCodes")
ErrNumMsg = ''
*For each of the error codes relating to this module
ErrCodesCount = DCOUNT(@FM,ErrCodes)
For i = 1 To ErrCodesCount
*Did the error number provided match a preconfigured error code?
If ErrCodes<i,1> EQ ErrNum Then
*Yes, Found. Break the loop
i = ErrCodesCount
*Get the preconfigured error message for this errnum.
ErrNumMsg = ErrCodes<i,2>
End
Next
If ErrCustomMsg NE '' Then
*We also include a custom error message
Set_Status(-1, ErrNum, ErrNumMsg : " " : ErrCustomMsg)
End Else
*No custom error message
Set_Status(-1, ErrNum, ErrNumMsg)
End
Return
/*
interface: getErrorCodes
Get a list of error codes And messages related To this module
>OPENINSIGHT_ROUTINE_LIB('getErrorCodes')
Parameters:
None.
Returns:
RetVal<x,1> - Error Code
RetVal<x,2> - Error message
*/
getErrorCodes_:
ErrorCodes = '';
ErrorCodes<-1> = "100|Some error code."
Swap "|" With @VM In ErrorCodes
Return
/*
interface: buildModule
Make a module related to this routine.
>run OPENINSIGHT_ROUTINE_LIB 'buildModule'
Parameters:
None.
Returns:
None.
*/
buildModule_:
*
* Before use create a module with the window
* exec rti_module_manager
*
* Create an array of entities to use Module methods against
reposStack = ""
ModuleTables = ''
Swap ',' With @FM In ModuleTables
ModuleRoutines = ''
Swap ',' With @fm In ModuleRoutines
ModuleWindows = ''
Swap ',' With @FM In ModuleWindows
rPos = 0 ; rFlag = ""
Loop
Remove thisEntity From ModuleTables at rPos setting rFlag
K = @appid<1> : "*STPROCINS**" : thisEntity : "_EQUATES"
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
While rFlag
Repeat
rPos = 0 ; rFlag = ""
Loop
Remove thisEntity From ModuleWindows at rPos setting rFlag
*Always deploy this window source and exe
reposStack<-1> = @appid<1> : "*OIWIN**" : thisEntity
reposStack<-1> = @appid<1> : "*OIWINEXE**" : thisEntity
K = @appid<1> : "*STPROC**" : thisEntity : "_EVENTS"
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
K = @appid<1> : "*STPROCINS**" : thisEntity : "_WIN_EQUATES"
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
K = @appid<1> : "*STPROCDBG**" : thisEntity : "_EVENTS"
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
K = @appid<1> : "*STPROCEXE**" : thisEntity : "_EVENTS"
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
*Get all events associated with the window
QUERY = "SELECT SYSREPOSEVENTS WITH ENTITYID = '" : thisEntity : ".' AND WITH APPID = '" : @APPID<1> : "'"
Keys = CS_RLIST_UTIL('getKeys', thisEntity : " events", Query, True$, True$)
KeysCount = DCOUNT (Keys,@FM)
*Loop through all the event keys
For i = 1 To KeysCount
Key = Keys<i>
E = Field(Key,"*", 2) ;*Get the event type from the key
*Verify and add the event EXE
K = @appid<1> : "*OIEVENTEXE*" : E : "*" : thisEntity : "."
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
*Verify and add the event source
K = @appid<1> : "*OIEVENT*" : E : "*" : thisEntity : "."
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
Next i ;* i = ''
While rFlag
Repeat
rPos = 0 ; rFlag = ""
Loop
Remove thisEntity From ModuleRoutines at rPos setting rFlag
K = @appid<1> : "*STPROC**" : thisEntity : ""
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
K = @appid<1> : "*STPROCDBG**" : thisEntity : ""
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
K = @appid<1> : "*STPROCEXE**" : thisEntity : ""
Set_Status(0); If Repository('GET', K) NE '' Then reposStack<-1> = K
While rFlag
Repeat
* Add a Module name to the entities
rPos = 0 ; rFlag = ""
If Xlate('SYSREPOSMODULES', moduleName,'','C') EQ moduleName Then
*Module was not found
call Msg(@WINDOW, "The module does not exist, cannot build:|" : moduleName)
End Else
*Module exists so add the repos entries to it
Loop
Remove thisEntity From reposStack at rPos setting rFlag
Set_Status(0)
var = Repository( "SETMODULE", thisEntity, moduleName )
If Get_Status(Err) then
call msg(@window, 'Error Message returned: ' : Err)
end
While rFlag
Repeat
End
* Create a RDK View Template corresponding to this module
ViewRec = ""
ViewRec<11> = ""
*Read this source record to look for the description
*Use the first /* */ comment block in the header.
ViewDesc = ""
SrcDesc = Xlate("SYSPROCS", thisName : "*" : @APPID<1>, "", "X")
SrcDescLen = Len(SrcDesc)
inComment = False$
For i = 1 To SrcDescLen
C = SrcDesc[i,1]
Begin Case
Case inComment = False$ And C EQ '/'
*Peek ahead
If SrcDesc[i+1,1] EQ "*" Then
*Found the start of first comment block
inComment = True$
i += 1 ;*Skip next character
End
Case inComment = True$ And C EQ '*'
*Peek ahead
If SrcDesc[i+1,1] EQ "/" Then
*Found the end of the comment block
inComment = True$
i = SrcDescLen
End
Case OTHERWISE$
If inComment THen
ViewDesc := C
End
End Case
Next i ; i = ""
Swap @FM With @TM In ViewDesc
If viewName EQ '' Then
ViewRec<1> = moduleName ;* Title
End Else
ViewRec<1> = viewName ;* Title
End
ViewRec<2> = ViewDesc ;* Description
ViewRec<4> = @APPID<1>
Open "SYSREPOSVIEWS" To ViewsTable Else Debug
Write ViewRec To ViewsTable, @APPID<1> : "*" : ViewRec<1> Else Debug
Return
/*
#AUTO_GENERATE_DOCS
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment