/*
 * Delegates.cs --
 *
 * Copyright (c) 2007-2012 by Joe Mistachkin.  All rights reserved.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @(#) $Id: $
 */

using System;
using System.Collections.Generic;
using System.Globalization;

#if NETWORK
using System.Net;
#endif

#if SHELL
using System.Text;
#endif

using Eagle._Attributes;
using Eagle._Containers.Public;
using Eagle._Interfaces.Public;

namespace Eagle._Components.Public.Delegates
{
    #region Multi-Purpose Delegates
    //
    // NOTE: Used by clients of the library for free() style native functions.
    //
    [ObjectId("a39742e2-79ea-4ba1-84f1-f8f0df2b9aca")]
    public delegate void FreeCallback(IntPtr data);
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Interactive Debugger / Shell Related Delegates
    //
    // NOTE: This is used by the Debugger class when it needs to break into
    //       the interactive loop.
    //
    [ObjectId("5d85f38d-bc7b-4e30-9fa3-34eb64e3ada2")]
    public delegate ReturnCode InteractiveLoopCallback(
        Interpreter interpreter,
        bool debug,
        IEnumerable<string> args,
        ReturnCode code,
        BreakpointType breakpointType,
        string breakpointName,
        IToken token,
        ITraceInfo traceInfo,
        EngineFlags engineFlags,
        SubstitutionFlags substitutionFlags,
        EventFlags eventFlags,
        ExpressionFlags expressionFlags,
        HeaderFlags headerFlags,
        IClientData clientData,
        ArgumentList arguments,
        ref bool exit,
        ref Result result
    );

    ///////////////////////////////////////////////////////////////////////////

#if SHELL
    [ObjectId("3d8f4e8b-6bcb-4117-9cf8-9c0264c8e0d6")]
    public delegate ReturnCode EvaluateScriptCallback(
        Interpreter interpreter,
        string text,
        ref Result result,
        ref int errorLine
    );

    ///////////////////////////////////////////////////////////////////////////

    [ObjectId("1cfdbf5e-c6f6-4304-899c-f4d81fd08b2d")]
    public delegate ReturnCode EvaluateFileCallback(
        Interpreter interpreter,
        string fileName,
        ref Result result,
        ref int errorLine
    );

    ///////////////////////////////////////////////////////////////////////////

    [ObjectId("fdfcc53e-2241-4d7d-bf0b-b9f6aa5aef6c")]
    public delegate ReturnCode EvaluateEncodedFileCallback(
        Interpreter interpreter,
        Encoding encoding,
        string fileName,
        ref Result result,
        ref int errorLine
    );

    ///////////////////////////////////////////////////////////////////////////

    //
    // NOTE: This is used by the ShellMainCore method when it encounters an
    //       argument it cannot handle.
    //
    [ObjectId("dad9e62e-eeeb-4043-b474-4a21955f369a")]
    public delegate ReturnCode ArgumentCallback(
        Interpreter interpreter,
        IInteractiveHost interactiveHost,
        IClientData clientData,
        int count,
        string arg,
        ref IList<string> argv,
        ref Result result
    );
#endif
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Script Binder Related Delegates
    //
    // NOTE: Used by the script binder and marshaller to convert a string to
    //       a System.Type object.
    //
    [ObjectId("95efe170-9c6d-4325-84fa-6e86c6b42449")]
    public delegate Type GetTypeCallback(
        string typeName,
        bool throwOnError,
        bool ignoreCase
    );

    ///////////////////////////////////////////////////////////////////////////

    //
    // NOTE: Used by the script binder to implement dynamic type conversions
    //       from string (always in the context of an interpreter).
    //
    [ObjectId("c9a205cc-d60f-4e67-b5ef-309aebf1b46c")]
    public delegate ReturnCode ChangeTypeCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        Type type,
        string text,
        OptionDictionary options,
        CultureInfo cultureInfo,
        IClientData clientData,
        ref object value,
        ref Result error
    );

    ///////////////////////////////////////////////////////////////////////////

    [ObjectId("817fb51d-ac00-411d-b921-ab9688e68a1b")]
    public delegate ReturnCode ToStringCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        Type type,
        object value,
        OptionDictionary options,
        CultureInfo cultureInfo,
        IClientData clientData,
        ref string text,
        ref Result error
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region String Handling Related Delegates
    //
    // NOTE: This is used by the StringList class to perform a transform on
    //       each element added to the newly created list.
    //
    [ObjectId("eecb9222-2372-4b29-bb03-de84545e5181")]
    public delegate string StringTransformCallback(
        string value
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Namespace Related Delegates
    [ObjectId("b88795f7-2538-4a2c-9bc8-5b04a2f0046e")]
    public delegate ReturnCode NamespaceCallback(
        INamespace @namespace,
        IClientData clientData,
        ref Result error
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Network Related Delegates
#if NETWORK
    [ObjectId("96141ff9-099d-46ca-ab6d-cf46e20dadcb")]
    public delegate WebClient NewWebClientCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        string argument
    );
#endif
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Interpreter Host Related Delegates
    [ObjectId("890b5534-11fe-42ab-8549-fd823257115b")]
    public delegate IHost NewHostCallback(
        IHostData hostData
    );

    ///////////////////////////////////////////////////////////////////////////

    [ObjectId("60472558-0049-40ba-9c08-5e3ac01d5acb")]
    public delegate void WriteLineCallback();

    ///////////////////////////////////////////////////////////////////////////

    [ObjectId("d8feecac-4278-4070-8819-4bd5feb4dc79")]
    public delegate void WriteCharCallback(
        char value
    );

    ///////////////////////////////////////////////////////////////////////////

    [ObjectId("bdf5896b-81ee-48c4-93a1-b8a8c58d9027")]
    public delegate void WriteStringCallback(
        string value
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Script Evaluation Related Delegates
    //
    // NOTE: Generic script evaluation callback (see also IAsynchronousContext
    //       interface).
    //
    [ObjectId("96804ca1-fad9-4e5e-beab-0e4c78c29044")]
    public delegate void AsynchronousCallback(
        IAsynchronousContext context
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Event Manager Related Delegates
    //
    // NOTE: This is used by the EventManager to provide a means of fetching
    //       the current DateTime (which may be "virtual").
    //
    [ObjectId("a495ae22-6f78-483c-a66a-39f084c76021")]
    public delegate DateTime DateTimeNowCallback();

    ///////////////////////////////////////////////////////////////////////////

    //
    // NOTE: Generic interpreter asynchronous event callback.
    //
    [ObjectId("8e5cab46-9887-49e4-8746-39330df59c34")]
    public delegate ReturnCode EventCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        IClientData clientData,
        ref Result result
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Native Tcl Integration Related Delegates
#if NATIVE && TCL && TCL_THREADS
    //
    // NOTE: Generic callback with a return code and result.
    //
    [ObjectId("bc8f729a-3c6e-45c8-acb0-f2548fd44299")]
    public delegate ReturnCode ResultCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        IClientData clientData1,
        IClientData clientData2,
        object data, /* NOTE: Request data, e.g. IEvent, etc. */
        ReturnCode code,
        Result result,
        int errorLine,
        ref Result error
    );
#endif
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Command Execution Related Delegates
    //
    // NOTE: Interpreter command execution callback (see also IExecute
    //       interface).
    //
    [ObjectId("f566bc2c-242c-4a0b-a556-605f6b4b3833")]
    public delegate ReturnCode ExecuteCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        IClientData clientData,
        ArgumentList arguments,
        ref Result result
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Object Disposal Related Delegates
    //
    // NOTE: The interpreter disposal callback (also see the Dispose method
    //       of the Interpreter class).
    //
    [ObjectId("5bb5400d-c094-4eb5-93da-a8ecdff29b07")]
    public delegate void DisposeCallback(
        object @object
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Variable Tracing Related Delegates
    //
    // NOTE: Interpreter variable trace callback.
    //
    [ObjectId("87929871-aaea-44b9-b6e1-fb6fdc9afaf1")]
    public delegate ReturnCode TraceCallback(
        BreakpointType breakpointType,
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        ITraceInfo traceInfo,
        ref Result result
    );
    #endregion

    ///////////////////////////////////////////////////////////////////////////

    #region Notification Related Delegates
#if NOTIFY || NOTIFY_OBJECT
    //
    // NOTE: Interpreter notification callback (see also INotify interface).
    //
    [ObjectId("2b4f0432-8412-4dde-afcc-8e556c37f5c2")]
    public delegate ReturnCode NotifyCallback(
        Interpreter interpreter, // TODO: Change to use the IInterpreter type.
        IScriptEventArgs eventArgs,
        IClientData clientData,
        ArgumentList arguments,
        ref Result result
    );
#endif
    #endregion
}
