streamCallBack - Maple Help

Online Help

All Products    Maple    MapleSim


EngineCallBacks.streamCallBack

handles stream calls

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

String streamCallBack( Object data, String name, String args[] ) throws MapleException

Parameters

data

-

arbitrary data that was passed into the Engine constructor

name

-

name of the stream on which the stream call occurred, without the "INTERFACE_" prefix

args

-

array of the line printed arguments passed into the stream call

Description

• 

streamCallBack is a member function of the com.maplesoft.openmaple.EngineCallBacks interface.  The streamCallBack function handles stream calls that are not handled by the Maple engine or other call back functions.

• 

For more information on streams in OpenMaple, see OpenMaple,C,streamCallBack.

• 

The streamCallBack function must return a syntactically valid Maple command string, or a NULL string.  A NULL string indicates no output is generated by the function.

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;

    Algebraic a;

    mapleArgs = new String[1];

    mapleArgs[0] = "java";

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

    a = engine.evaluate( "print(INTERFACE_PINE( 1,2,3,4 ));" );

    System.out.println( a );

    a = engine.evaluate( "print(INTERFACE_ELM( int(x,x) ));" );

    System.out.println( a );

    a = engine.evaluate( "print(INTERFACE_OAK( 1/3*Pi ));" );

    System.out.println( a );

    }

}

Executing this code produces the following output.

PINE( 1 2 3 4 )

Text: 1

1

ELM( 1/2*x^2 )

Text: 1/2*x^2

1/2*x^2

OAK( 1/3*Pi )

Text: 1/3*Pi

1/3*Pi

See Also

ExternalCalling/Java/MapleException

OpenMaple

OpenMaple/C/streamCallBack

OpenMaple/Java/Engine

OpenMaple/Java/Engine/Engine

OpenMaple/Java/EngineCallBacks

OpenMaple/Java/EngineCallBacksDefault

OpenMaple/Java/EngineCallBacksDefault/streamCallBack