get_app_type

Identifies the calling thread as LibC, CLib, or Java.

Library:LibC
Service:Library

Syntax

  #include <library.h> 
   
  int get_app_type (void);
  

Return Values

Returns a combination of the following flags:

Remarks

The get_app_type function is called, usually by a library, to determine if a thread was created by CLib, Java, or LibC. This information can then be used to make decisions on how best to serve the calling thread’s application. For example, the library might choose to call CLib’s printf on behalf of a CLib application rather than LibC’s printf.If a thread’s application type includes CLib (get_app_type() & LIBRARY_CLIB), you should probably consider the thread to be a CLib thread (rather than any other type also present in the value) and choose CLib functions (rather than LibC functions) where a distinct choice needs to be made. CLib threads can, however, make most calls in LibC through gateway functions just as any other type of thread may. This means that if a CLib thread were to call printf in LibC (by going through a library which itself called printf and was linked with libc.nlm), LibC would do it successfully for the thread, but on the console instead of where CLib’s printf call would go. The library writer must determine how important it is to call a CLib versus a LibC function on behalf of its client threads and applications.

The LIBRARY_CLIB and LIBRARY_JAVA flags are more important than LIBRARY_LIBC in that almost every thread will have LIBRARY_LIBC set on it or can put itself in a state that it soon will whereas a thread without LIBRARY_CLIB will never acquire the state without being forced artificially into it (through CLib’s SetThreadGroupID). Thus, you should use a hierarchical progression when checking the flags: check first to determine whether LIBRARY_CLIB is set, then LIBRARY_JAVA, and finally LIBRARY_LIBC. The latter is almost useless information, however, because any NetWare thread that is not running at interrupt time or that has been temporarily pirated by the kernel from a protected address space can be used to call LibC.

For example:

  #include <stdio.h>
  #include <screen.h>
  #include <library.h>
  
  int type = get_app_type();
  if (type & LIBRARY_CLIB)    // caller is CLib-based
     {
        if (!clib_printf)
           clib_printf = ImportPublicObject(gModuleHandle,
                         "printf"); 
        if (clib_printf)     // is printf() available from CLib?
           (*clib_printf)("%s: %s", name, foo_string);
  
        else               // print warning to system console
           consoleprintf("Lib: unable to support"
                         " screen print for CLib"
                         " client %s.\n", name);
     }else               // caller is LibC-based or has no context   {              // this printf() is in LibC
        printf("%s: %s", name, foo_string);
     }
  

See Also