Writing a Custom Scheduler Rule
On certain CloudSuite Industrial forms, several positions of Scheduler rules are listed as user-defined. For example, positions 24-39 of the Sequence Rule are reserved for user-defined rules. A user-defined rule is a custom piece of logic that you write in one or more custom C++ functions. User-defined rules allow you to model your unique scheduling situations that the standard rules may not address.
For example, the fragment below from the initialization function ucini1 installs a load-ranking function for Sequence Rule 39:
double myrule39(LOAD*); void ucini1() { sedfrk(39, myrule39); /* Install other user-defined rules here. */ } double myrule39(LOAD*) { /* Insert your custom logic for myrule39 here. */ }
For a complete description of each user-callable Scheduler function, see the Scheduling Customization Guide, available for download from our Support site.
Naming Conventions, Arguments, and Return Values
To execute correctly, custom functions must accept the proper arguments and return the proper value for the type of rule. The names of these functions must not conflict with the names of standard user-callable functions. You must make your custom functions accessible to the Scheduler by calling installation functions in the initialization function ucini1. See these topics for these details for the following rules:
Usercode Directory
User code compiled for the Scheduler applies to all alternatives in the database. The install procedure creates a subdirectory named USERCODE that contains the user code support files. You should create a subdirectory beneath this one with the same name as your SQL database to hold your user code source files. The Scheduler also looks for the user code DLL file (USER.DLL) in this directory.
Writing for UNICODE
The Scheduler uses Unicode to support international string issues. To write code that can be conditionally compiled for Unicode, MBCS, or neither, follow these programming guidelines:
- Use the _T macro to code literal strings conditionally to be portable to Unicode. For Example: psqlda = dboptab (_T("MYBOM"), p_ssgvar->sgctrl.scprtds, DB_FETCH)
- When you pass strings, pay attention to whether function arguments require a length in characters or a length in bytes. The difference is important if you're using Unicode strings.
- Use portable versions of
the C run-time string-handling functions. See the section on String
Manipulation in the Microsoft Visual C/C++ documentation for a complete list
and for further information.
For Example:
- _tcscpy instead of strcpy
- _tcsncpy instead of strncpy
- _tcscmp instead of strcmp
- _tcsncmp instead of strncmp
- _tcscat instead of strcat
- _tcsncat instead of strncat
- _tcschr instead of strchr
- _stprintf instead of sprintf
- Use the following data
types for characters and character pointers:
- TCHAR Where you would use char.
- LPTSTR or TCHAR * Where you would use char*.
- LPCTSTR Where you would use const char*.
Integrating the Custom Rules into the Scheduler
After you have written your custom rules, you must link them into the standard system.