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

namespace OBJ_FileBus
{
    public class Server_OBJProxy:FObj
    {
        Server mServer;

        public Server_OBJProxy(int objsys_idx, Server server) :base(objsys_idx)
        {
            ID = FILEBUS_OBJ_INTERFACE.ID;
            mServer = server;
            mServer.SendMessageEvent += new Server.SendMessageEventHandler(mServer_SendMessageEvent);
            
        }

        void mServer_SendMessageEvent(Server.ClientInfo client, byte[] buf)
        {
            CurrObjSys.PushObjInfoEx(this, FILEBUS_OBJ_INTERFACE.PUSH_MSG, buf, client.conn, client.destid);
        }
        #region FLYOBJ 结构

        public override void ConnectNotify(IFConn from)
        {
            if (from.IsConnected == false)
                mServer.ClientRemove(new OBJ_FileBus.Server.ClientInfo() { conn = from });
        }
        public override void CallFunction(IFConn from, uint srcid, UInt32 magic, ushort funcid, byte[] infodata)
        {
            switch (funcid)
            {
                case FILEBUS_OBJ_INTERFACE.CALL_MSG:
                    {
                        byte[] retdata = null;
                        mServer.RequestService(
                            new Server.ClientInfo() { conn = from, destid = srcid },
                                        infodata, out retdata);

                        if (retdata != null)
                        {
                            CurrObjSys.PushCallFunctionEx(from, srcid, ID, magic, funcid, retdata);
                        }
                    } break;
            }
        }

        #endregion
    }
}