Community articleImplementing your custom functions
Added by IBM contributorIBM on May 3, 2012
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

No abstract provided.



Implement your custom functions as part of the extension.
  • The function defined previously as FCISimpleFunctions implements the behavior of your custom functions.
  • FCISimpleFunctions can be passed several commands by the Forms driver. When a function call in a form is to be evaluated, FCISimpleFunctions will be passed the command FCICOMMAND_RUN as a value for the parameter theCommand.
  • This function must ensure that proper error checking is implemented. The function should check that the package and function names have been properly defined, and that the package name supplied by the Forms driver matches the package name specified in your extension. If you plan to write a multi-thread function, you should also check that the application using the function is thread safe (using MUGetThreadSafeFlag).
  • In the following example, the Multiply function is implemented as part of FCISimpleFunctions in fciExtension.c:
  • #ifndef OLD_STYLE_PARAMS
    PRE_FUNCTION_DECL r_short POST_FUNCTION_DECL FCISimpleFunctions(FunctionCall 
       *theObject, 
     
    r_charP thePackageName, r_charP theFunctionName, r_u_long theFunctionID, 
       r_long theFunctionInstance, 
    r_short theCommand, formNodeP theForm, formNodeP theComputeNode, IFSUserData 
     
    **theFunctionDataPtr, IFSUserData **theFunctionInstanceDataPtr, formNodeP 
       *theArgList, r_long 
    theArgListSize, formNodeP theResult)
    #else
    PRE_FUNCTION_DECL r_short POST_FUNCTION_DECL FCISimpleFunctions(theObject, 
    thePackageName, theFunctionName,theFunctionID, theFunctionInstance,theCommand, 
       theForm, 
    theComputeNode, theArgList, theArgListSize, theResult)
    FunctionCallManager *theObject;
    r_charP thePackageName;
    r_charP theFunctionName;
    r_u_long theFunctionID;
    r_long theFunctionInstance;
    r_short theCommand;
    formNodeP theForm;
    formNodeP theComputeNode;
    IFSUserData **theFunctionDataPtr;
    IFSUserData **theFunctionInstanceDataPtr;
    formNodeP *theArgList;
    r_long *theArgListSize;
    formNodeP theResult;
    #endif
    {
    r_charP theFirstParam;
    double firstNum;
    r_charP theSecondParam;
    double secondNum;
    r_short theError;
    double theMultiplyResult;
    char theLiteralBuffer [50]; 
    /*    Verify the input parameters */
          if ((thePackageName == NULL) || (theFunctionName == NULL))
          {
             MessageBox(NULL, "Invalid parameters", "Error", MB_OK);
             return(NOTOK);
          }
    /*    Make sure that the package is the one we are expecting. */
          if (cp_strcmp(thePackageName, PACKAGE_NAME) != OK)
          {
             MessageBox(NULL, "This function was called with the wrong
                package name", "Error", MB_OK);
             return(NOTOK);
          }
    /*    First switch based on the command */
          switch (theCommand)
          {
             case FCICOMMAND_RUN:
    /*    Now switch based on the function name */
                switch (theFunctionID)
                {
    /*    The "multiply" function. */
                   case FCI_MULTIPLY_ID:
                
                      if ((theError = UFLGetLiteralEx(theArgList [0],
                         NULL, &theFirstParam)) != OK)
                      {
                         MessageBox(NULL, "Unable to get the first
                            parameter.", "Error", MB_OK);
                         return(theError);
                      }
                      if ((theError = UFLGetLiteralEx(theArgList [1],
                         NULL, &theSecondParam)) != OK)
                      {
                         MessageBox(NULL, "Unable to get the first
                            parameter.", "Error", MB_OK);
                         return(theError);
                      }
                
    /*    Since the literal can be NULL, we make sure that it isn't */
                      if (theFirstParam == NULL)
                         theFirstParam = "";
                      if (theSecondParam == NULL)
                         theSecondParam = "";
          
    /*    Convert the literal into a number */
                      firstNum = atof(theFirstParam);
                      secondNum = atof(theSecondParam);
    /*    Now multiply the numbers */
                      theMultiplyResult = firstNum * secondNum;
                      sprintf(theLiteralBuffer, "%f", theMultiplyResult);
                      UFLSetLiteralEx(theResult, NULL, theLiteralBuffer);
                      break;
    /*    Error if the function is unknown. */
                   default:
                      MessageBox(NULL, "The function was called with an
                         unrecognized function", "Error", MB_OK);
                   return(NOTOK);
                }
                break;
             case FCICOMMAND_INSTANCEREGISTER:
                break;
             case FCICOMMAND_INSTANCEDEREGISTER:
                break;
             case FCICOMMAND_REGISTER:
                break;
             case FCICOMMAND_DEREGISTER:
                break;
             default:
                break;
          }
    /*    Finished */
          return(OK);
    }