using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FObjBase;

namespace OBJ_FileBus
{
    public class Client_OBJProxy:FObj
    {
        private IFConn conn;

        Client mClient;
        public Client_OBJProxy(Client client)
        {
            mClient = client;
            mClient.SendMessageEvent += new Client.SendMessageEventHandler(mClient_SendMessageEvent);
        }

        void mClient_SendMessageEvent(byte[] msg)
        {
            CurrObjSys.CallFunctionEx(
                conn, 
                FILEBUS_OBJ_INTERFACE.ID,
                ID,
                FILEBUS_OBJ_INTERFACE.CALL_MSG,
                msg);
        }

        public override void ConnectNotify(IFConn from)
        {
            conn = from;
            mClient.HasInit = conn.IsConnected;

        }
        public override void PushCallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] retdata, object AsyncDelegate, object AsyncState)
        {
            switch (funcid)
            {
                case FILEBUS_OBJ_INTERFACE.CALL_MSG:
                    mClient.RequestService(retdata);
                    break;
            }
        }
        public override void PushInfo(IFConn from, uint srcid, ushort infoid, byte[] infodata)
        {
            switch (infoid)
            {
                case FILEBUS_OBJ_INTERFACE.PUSH_MSG:
                    mClient.RequestService(infodata);
                    break;
            }
        }
    }
}
