EngineCallBacks.textCallBack - Maple Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Programming : OpenMaple : Java Application Programming Interface : EngineCallBacks Interface : OpenMaple/Java/EngineCallBacks/textCallBack

EngineCallBacks.textCallBack

call back function for handling text messages

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

void textCallBack( Object data, int tag, String msg ) throws MapleException

Parameters

data

-

arbitrary data that was passed to the Engine constructor

tag

-

identifies the type of message

msg

-

text of the message

Description

• 

textCallBack is a member function of the com.maplesoft.openmaple.EngineCallBacks interface.  It is called when the Maple session wants to send the user a text message.  For example, to display output from the evaluation of a function or from calls to the printing functions.

• 

The following exports of EngineCallBacks are the possible values for tag.

  

MAPLE\_TEXT\_OUTPUT is used to indicate that the text is output generated from the evaluation of a Maple statement.

  

MAPLE\_TEXT\_DIAG is used to indicate that the text is diagnostic output, for example, from high printlevel or trace output.

  

MAPLE\_TEXT\_MISC is used to indicate that the text is from a miscellaneous source, for example, the Maple printf function.

  

MAPLE\_TEXT\_HELP is used to indicate that the text is the output of a help request.  For a more comprehensive help facility, see getHelp.

  

MAPLE\_TEXT\_QUIT is used to indicate that the text is output generated in response to a quit, done or stop command.

  

MAPLE\_TEXT\_WARNING is used to indicate that the text is output from a warning generated during a computation.

  

MAPLE\_TEXT\_ERROR is used to indicate that the text is output from an error raised during parsing or evaluating.  This will occur only if the errorCallBack function redirects the error message to the textCallBack function.

  

MAPLE\_TEXT\_STATUS is used to indicate that the text is output generated from a kernel status message, (the "bytes used" message).   This will occur only if the statusCallBack function redirects the status messages into the textCallBack function. This is the default behavior when using the EngineCallBacksDefault class.

  

MAPLE\_TEXT\_DEBUG is used to indicate that the text is output generated from the Maple debugger.

Examples

import com.maplesoft.openmaple.*;

import com.maplesoft.externalcall.MapleException;

class Example

{

    static private class CallBacks implements EngineCallBacks

    {

    boolean limitExceeded;

    CallBacks()

    {

        limitExceeded = false;

    }

    public void textCallBack( Object data, int tag, String output )

        throws MapleException

    {

        switch ( tag )

        {

        case MAPLE_TEXT_OUTPUT:

            System.out.print( "Text: " );

            break;

        case MAPLE_TEXT_DIAG:

            System.out.print( "Diag: " );

            break;

        case MAPLE_TEXT_MISC:

            System.out.print( "Misc: " );

            break;

        case MAPLE_TEXT_HELP:

            System.out.print( "Help: " );

            break;

        case MAPLE_TEXT_QUIT:

            System.out.print( "Quit: " );

            break;

        case MAPLE_TEXT_WARNING:

            System.out.print( "Warning: " );

            break;

        case MAPLE_TEXT_DEBUG:

            System.out.print( "Debug: " );

            break;

        }

        System.out.println( output );

    }

    public void errorCallBack( Object data, int offset, String msg )

        throws MapleException

    {

        if ( offset >= 0 )

        {

        throw new MapleException( "Error: "+msg );

        }

        else

        {

        throw new MapleException( "syntax error at offset "+offset+

            ": "+msg );

        }

    }

    public void statusCallBack( Object data, long kbused, long kballoced,

        double timeused )

            throws MapleException

    {

        if ( timeused > 5 )

        {

        limitExceeded = true;

        }

        System.out.println( "Status: used = "+kbused+", alloced = "+

        kballoced+", time = "+timeused );

    }

    public String readLineCallBack( Object data, boolean debug )

        throws MapleException

    {

        return "readline";

    }

    public boolean redirectCallBack( Object data, String output, boolean

append )

        throws MapleException

    {

        System.out.println( "redirect to "+output+" append = "+append );

            return true;

    }

    public String callBackCallBack( Object data, String output )

        throws MapleException

    {

        System.out.println( "callback: "+output );

        return output+";";

    }

    public boolean queryInterrupt( Object data )

        throws MapleException

    {

        return limitExceeded;

    }

    public String streamCallBack( Object data, String name, String args[] )

        throws MapleException

    {

        StringBuffer sbuf;

        int i;

        System.out.print( name+"( " );

        for ( i = 0; i < args.length; i++ )

        {

        System.out.print( args[i]+" " );

        }

        System.out.println( ")" );

        return args[0]+":";

    }

    }

    public static void main( String notused[] ) throws MapleException

    {

    String mapleArgs[];

    Engine engine;

    mapleArgs = new String[1];

    mapleArgs[0] = "java";

    engine = new Engine( mapleArgs, new CallBacks(), null, null );

    engine.evaluate( "192+291;" );

    engine.evaluate( "printf( \%a\, x^n+y^n=z^n );" );

    engine.evaluate( "printlevel:=5;" );

    engine.evaluate( "int(x,x);" );

    engine.evaluate( "printlevel:=1;" );

    engine.evaluate( "WARNING( \be warned!\ );" );

    }

}

Executing this code produces the following output.

Text: 483

Misc: x^n+y^n = z^n

Text: printlevel := 5

Diag: {--> enter int, args = x, x

Text: answer := 1/2*x^2

Text: 1/2*x^2

Diag: <-- exit int (now at top level) = 1/2*x^2}

Text: 1/2*x^2

Text: printlevel := 1

Warning: Warning, be warned!

See Also

ExternalCalling/Java/MapleException

OpenMaple

OpenMaple/Java/Engine

OpenMaple/Java/Engine/Engine

OpenMaple/Java/EngineCallBacks

OpenMaple/Java/EngineCallBacksDefault

OpenMaple/Java/EngineCallBacksDefault/textCallBack

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam