Module cCallInterfaceHelper_mixin.pkg

     1Use Windows.pkg
     2Use Flexml.pkg
     3Use cCallInterface.pkg
     4
     5{ ClassLibrary=WebApp ClassType=Mixin }
     6Class cCallInterfaceHelper_mixin is a mixin
     7
     8    { Visibility=Private }
     9    Procedure DefineCallInterfaceHelper_mixin
    10
    11       { Visibility=Private }
    12       property boolean pbConvertXML False
    13       { Visibility=Private }
    14       property handle  phoCallInterface 0
    15
    16       Object oCallInterface Is A cCallInterface
    17       End_Object
    18
    19       // The WSO or WBO will use this as its call interface object
    20       Set phoCallInterface to oCallInterface
    21
    22       // Web services by default are performed in the web service object.
    23       // By setting the property phoWebServiceImplementor services are handled in the WBPO
    24       Set phoWebServiceImplementor of oCallInterface To self
    25
    26    End_Procedure
    27
    28    // extract and return pData pointer from passed pointer to VDFISData
    29    // This is not a copy operation - just find pData.
    30    { Visibility=Private }
    31    Function VDFISData_pData Address pVDFISData Returns Address
    32        Function_Return (DeRefDW(pVDFISData, VDFISData.pData))
    33    End_Function
    34
    35    // extract Length pData pointer from passed pointer to VDFISData
    36    { Visibility=Private }
    37    Function VDFISData_iDataLen Address pVDFISData Returns Address
    38        Function_Return (DeRefDW(pVDFISData, VDFISData.iDataLen))
    39    End_Function
    40
    41
    42    // Alloc or reAlloc space for VDFISData.pData.
    43    // Pass: pVDFISData and length.
    44    //       Alloc mem and set .pData and .iDataLen values in structure
    45    // Ret:  .pData
    46    //
    47    { Visibility=Private }
    48    Function AllocVDFISData_pData Address pVDFISData Integer iLen Returns Address
    49        Address pData
    50        Integer bOK  bKeepAlive
    51
    52        If (pVDFISData=0) Begin
    53            Send LogErrorEvent DFERR_WEBAPP_BAD_PARAMETER C_$pVDFISDataIsNull
    54            Function_Return 0
    55        End
    56
    57        Get VDFISData_pData pVDFISData To pData
    58        Move (DeRefDW(pVDFISData, VDFISData.bKeepAlive)) To bKeepAlive
    59        If ( (pData=0) Or (bKeepAlive)) ;
    60            Move (Alloc(iLen)) To pData
    61        Else ;
    62            Move (ReAlloc(pData,iLen)) To pData
    63
    64        If (pData=0) Begin
    65            Send LogErrorEvent DFERR_PROGRAM C_$CouldNotAllocatepData // this should never happen
    66            Function_Return 0
    67        End
    68
    69        Move (StoreDW(pVDFISData, VDFISData.pData,    pData)) To bOK // store new data pointer
    70        Move (StoreDW(pVDFISData, VDFISData.iDataLen, iLen))  To bOK // store new data length
    71        Function_Return pData
    72    End_Function
    73
    74
    75    // must create a new string and copy contents from pValue into it
    76    // Pass: pValue points to VDFISData
    77    //
    78    { Visibility=Private }
    79    Function Copy_VDFISDATAtoString Address pVDFISData Returns String
    80        String  sValue
    81        Address pData
    82
    83        If (pVDFISData=0) Begin
    84            Send LogErrorEvent DFERR_WEBAPP_BAD_PARAMETER C_$pVDFISDataIsNull
    85            Function_Return 0
    86        End
    87
    88        Get VDFISData_pData pVDFISData To pData
    89        If (pData<>0) ;
    90            Move pData To sValue
    91        Function_Return sValue
    92    End_Function
    93
    94    // must alloc new pData space and copy string to this space.
    95    // Pass: Pointer to VDFISData, String.
    96    // Pass by ref to avoid extra copy of string
    97    { Visibility=Private }
    98    Function Copy_StringtoVDFISData String sValue Address pVDFISData Returns Address
    99        Integer iLen
   100        Address pData
   101        // make sure this is a C string. 0 byte needed for copy
   102        Move ((Length(sValue))+1) To iLen
   103        Get AllocVDFISData_pData pVDFISData iLen To pData
   104        Move sValue To pData
   105        Function_Return pData
   106    End_Function
   107
   108    // add message to interface. Old vdf 2 message (was called RegisterInterface). use extended version below
   109    { Visibility=Private Obsolete=True }
   110    Procedure RegisterSimpleInterface Integer iMsg String sMsgName String sParams String sComment
   111        Send RegisterSimpleInterface To oCallInterface iMsg sMsgName sParams sComment
   112    End_Procedure
   113
   114    // add extended interface.
   115    Procedure RegisterInterface Integer iMsg String sMsgName String sParams String sComment
   116        Send RegisterInterface of (phoCallInterface(self)) iMsg sMsgName sParams sComment
   117    End_Procedure
   118
   119
   120    Procedure RemoveInterface Integer iMsg
   121        Send RemoveInterface To (phoCallInterface(self)) iMsg
   122    End_Procedure
   123
   124    Procedure RegisterStandardInterface
   125    End_Procedure
   126
   127
   128
   129    // Find message Id for passed message name ret: 0 if not found, else object Id of message
   130    { Visibility=Private }
   131    Function FindMessageId String sMsg Returns Integer
   132        Function_Return (FindMessageId(phoCallInterface(self),sMsg))
   133    End_Function
   134
   135    // Find message item for passed message name ret: -1 if not found, else item of message.
   136    // The following messages use this item to retrieve data.
   137    { Visibility=Private }
   138    Function FindMessageItem String sMsg Returns Integer
   139        Function_Return (FindMessageItem(phoCallInterface(self),sMsg))
   140    End_Function
   141
   142    { Visibility=Private }
   143    Function InterfaceMessageCount Returns Integer
   144        Function_Return (InterfaceMessageCount(phoCallInterface(self)))
   145    End_Function
   146
   147    // retrieve interface Name (w/ proper casing), Id, Params, and Comments based on passed ID.
   148    { Visibility=Private }
   149    Function InterfaceMessageName Integer iItem Returns String
   150        Function_Return (InterfaceMessageName(phoCallInterface(self),iItem))
   151    End_Function
   152
   153    { Visibility=Private }
   154    Function InterfaceMessageId Integer iItem Returns String
   155        Function_Return (InterfaceMessageId(phoCallInterface(self),iItem))
   156    End_Function
   157
   158    { Visibility=Private }
   159    Function InterfaceMessageParams Integer iItem Returns String
   160        Function_Return (InterfaceMessageParams(phoCallInterface(self),iItem))
   161    End_Function
   162
   163    { Visibility=Private }
   164    Function InterfaceMessageComment Integer iItem Returns String
   165        Function_Return (InterfaceMessageComment(phoCallInterface(self),iItem))
   166    End_Function
   167
   168    { Visibility=Private }
   169    Function InterfaceMessageParamCount Integer iItem Returns Integer
   170        Function_Return (InterfaceMessageParamCount(phoCallInterface(self),iItem))
   171    End_Function
   172
   173    { Visibility=Private }
   174    Function InterfaceMessageParamType Integer iItem Integer iParam Returns Integer
   175        Integer iParamType
   176        Get InterfaceMessageParamType of (phoCallInterface(self)) iItem iParam to iParamType
   177        Function_Return iParamType
   178    End_Function
   179
   180    { Visibility=Private }
   181    Function InterfaceMessageParamTypeName Integer iItem Integer iParam Returns String
   182        String sParamTypeName
   183        Get InterfaceMessageParamTypeName of (phoCallInterface(self)) iItem iParam to sParamTypeName
   184        Function_Return sParamTypeName
   185    End_Function
   186
   187    { Visibility=Private }
   188    Function InterfaceMessageParamDimCount Integer iItem Integer iParam Returns Integer
   189        Integer iParamDimCount
   190        Get InterfaceMessageParamDimCount of (phoCallInterface(self)) iItem iParam to iParamDimCount
   191        Function_Return iParamDimCount
   192    End_Function
   193
   194    { Visibility=Private }
   195    Function InterfaceMessageParamName Integer iItem Integer iParam Returns String
   196        String sParamName
   197        Get InterfaceMessageParamName of (phoCallInterface(self)) iItem iParam to sParamName
   198        Function_Return sParamName
   199    End_Function
   200
   201    { Visibility=Private }
   202    Function InterfaceMessageParamByRef Integer iItem Integer iParam Returns Integer
   203        Integer iParamByRef
   204        Get InterfaceMessageParamByRef of (phoCallInterface(self)) iItem iParam to iParamByRef
   205        Function_Return iParamByRef
   206    End_Function
   207
   208    { Visibility=Private }
   209    Function InterfaceTypeDefinitions string sNSPre string sNsURI Returns String
   210        String sTypes
   211        Get InterfaceTypeDefinitions of (phoCallInterface(self)) sNsPre sNsURI to sTypes
   212        Function_Return sTypes
   213    End_Function
   214
   215    { Visibility=Private }
   216    Function WebRequestServiceName Address pVdfISData Returns String
   217        String sName
   218        Get WebRequestServiceName of (phoCallInterface(Self)) pVdfISData to sName
   219        Function_Return sName
   220    End_Function
   221
   222    // Is message extended. Determines how sParams is parsed
   223    { Visibility=Private }
   224    Function InterfaceMessageIsExtended Integer iItem Returns Integer
   225        Function_Return (InterfaceMessageIsExtended(phoCallInterface(self),iItem))
   226    End_Function
   227
   228
   229    // Uses new runtime class for call parsing
   230    //
   231    //  Note: There are no more parsing errors, since there is no parsing.
   232    //        There are four possible errors:
   233    //          1. We receive a completely bad parameter block
   234    //              (dwError is set in structure or offset to service name is outside of range)
   235    //
   236    //             #REPLACE  DFERR_WEBAPP_WEBSERVICE_BAD_PARAMETER_BLOCK,    |CI4376
   237    //
   238    //          2. We receive a call for a webservice that we don't have registered.
   239    //
   240    //             #REPLACE  DFERR_WEBAPP_WEBSERVICE_NOT_FOUND,              |CI4375
   241    //
   242    //          3. We receive a call for a webservice, but it doesn't have a valid message number
   243    //             attached. Message number is zero.
   244    //
   245    //             #REPLACE  DFERR_WEBAPP_WEBSERVICE_BAD_REGISTRATION       |CI4374
   246    //
   247    //          4. More than 16 arguments were passed. 16 arguments is the maximum for a webservice.
   248    //
   249    //             #REPLACE  DFERR_WEBAPP_WEBSERVICE_TOO_MANY_ARGUMENTS,    |CI4387
   250    //
   251
   252    { Visibility=Private }
   253    Function DoCall Address pVDFISData Returns Integer
   254        Integer iErr
   255        String  sErrMsg sMsgName
   256        string sName
   257        Boolean bConvert
   258        Get pbConvertXML to bConvert // should we apply an XML conversion - only done with Web Services
   259        //  must get name before DoCall. DoCall changes pData in pVDFISData
   260        Get WebRequestServiceName pVdfISData to sMsgName
   261        // note that this passes 2 params (and not 1 as above). Note to self: We need to remember to not
   262        // use this in an expression.
   263        Get DoCall Of oCallInterface pVdfISData bConvert To iErr
   264        // Handle possible errors
   265        If (iErr<>0 and iErr<>DFERR_WEBSERVICE_EXCEPTION) Begin
   266            Case Begin
   267                // for now we are mapping the error numbers so they match what we had in WebApp/2 and
   268                // what we have in the Linux WebApp. If we change this, we must change the Linux err
   269                // numbers as well.
   270                Case (iErr = DFERR_WEBAPP_WEBSERVICE_NOT_FOUND)
   271                    Move (SFormat(C_$CallErrorMessageNotRegistered, sMsgName)) To sErrMsg
   272                    Case Break
   273                Case (iErr = DFERR_WEBAPP_WEBSERVICE_BAD_REGISTRATION)
   274                    Move (SFormat(C_$CallErrorMessageNotDefined, sMsgName)) To sErrMsg
   275                    Case Break
   276                Case (iErr = DFERR_WEBAPP_WEBSERVICE_TOO_MANY_ARGUMENTS)
   277                    Move (SFormat(C_$CallErrorTooManyParams, sMsgName)) To sErrMsg
   278                    Case Break
   279                Case (iErr = DFERR_WEBAPP_WEBSERVICE_BAD_PARAMETER_BLOCK)
   280                    // this should never happen in a webApp
   281                    Move C_$CallErrorBadParameterBlock To sErrMsg
   282                    Case Break
   283                Case Else
   284                    // this should never happen in a webApp
   285                    Move C_$CallErrorUnknown To sErrMsg
   286            Case End
   287            // generate the error.
   288            Error iErr sErrMsg
   289        End
   290        Function_Return iErr
   291    End_Function
   292
   293End_Class
   294