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

namespace FObjBase
{
    public interface IFObjSysAsClient
    {
        /// <summary>
        /// 添加OBJ 入 本地OBJSys
        /// </summary>
        /// <param name="obj"></param>
        void ObjAdd(IFObj obj);

        /// <summary>
        /// 获取一个没有被分配的 Obj ID
        /// </summary>
        /// <returns></returns>
        UInt32 GetFreeObjID();

        /// <summary>
        /// 创建了一个远端服务的客户代理， 删除这个代理；
        /// 还需要通知远端，这个代理已经不存在，与它相关的推送，都要关闭
        /// 当没有一个obj 与远端服务连接，socket也会被释放
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="conn"></param>
        void ObjRemove(IFObj obj, IFConn conn);
        /// <summary>
        /// 连接到远端的OBJSys连接
        /// </summary>
        /// <param name="ep">远端地址</param>
        /// <param name="objids">连接成功后，通知这些obj</param>
        /// <returns></returns>
        TCPCConn Connect_to_Another_OBJSys(IPEndPoint ep, params UInt32[] objids);

        /// <summary>
        /// 断开到远端OBJSys的连接
        /// </summary>
        /// <param name="ep">远端地址</param>
        /// <param name="objids">连接成功后，通知这些obj</param>
        /// <returns></returns>
        void Disconnect_to_Another_OBJSys(IPEndPoint ep, params UInt32[] objids);

        /// <summary>
        /// 注册本地obj 为远端obj的敏感对象，得到远端obj的推送消息
        /// </summary>
        /// <param name="s1">远端对应的连接代理 </param>
        /// <param name="objid">远端的ID</param>
        /// <param name="senobjid">本地obj</param>
        /// <param name="sense_mask">注册的敏感源</param>
        /// <param name="action">动作，添加?删除?</param>
        void SenseConfigEx(IFConn s1, UInt32 objid, UInt32 senobjid, UInt32 sense_mask, SENSE_CONFIG action);

        /// <summary>
        /// 对外发送消息
        /// </summary>
        /// <param name="s1">远端对应的连接代理 </param>
        /// <param name="destid">远端的ID</param>
        /// <param name="srcid">本地的ID</param>
        /// <param name="magic">交易码</param>
        /// <param name="info_no">信息码</param>
        /// <param name="info_data">信息内容</param>
        void SendMessageEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt32 magic, UInt16 info_no, byte[] info_data);


        /// <summary>
        /// 向远端GetValue
        /// </summary>
        /// <param name="s1">远端对应的连接代理</param>
        /// <param name="destid">远端的ID</param>
        /// <param name="srcid">本地的ID</param>
        /// <param name="memid">成员ID</param> 
        void GetValueEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 memid);

        /// <summary>
        /// 向远端SetValue
        /// </summary>
        /// <param name="s1">远端对应的连接代理</param>
        /// <param name="destid">远端的ID</param>
        /// <param name="srcid">本地的ID</param>
        /// <param name="memid">成员ID</param>
        /// <param name="value">成员内容</param>
        void SetValueEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 memid, byte[] value);

        /// <summary>
        /// 向远端CallFunction
        /// </summary>
        /// <param name="s1">远端对应的连接代理 </param>
        /// <param name="destid">远端对象ID</param>
        /// <param name="srcid">本地对象ID</param>
        /// <param name="funcid">函数ID</param>
        /// <param name="param">函数参数</param>
        /// <param name="asyncDelegate">在其上调用异步调用的委托对象</param>
        /// <param name="asyncContext">作为 BeginInvoke 方法调用的最后一个参数而提供的对象</param>
        UInt32 CallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 funcid, byte[] param, AsyncCBHandler asyncDelegate, object asyncContext);

        /// <summary>
        /// 向远端CallFunction
        /// </summary>
        /// <param name="s1">远端对应的连接代理 </param>
        /// <param name="destid">远端对象ID</param>
        /// <param name="srcid">本地对象ID</param>
        /// <param name="funcid">函数ID</param>
        /// <param name="param">函数参数</param>
        UInt32 CallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt16 funcid, byte[] param);
    }
    public interface IFObjSysAsServer
    {
        /// <summary>
        /// 添加OBJ 入 本地OBJSys
        /// </summary>
        /// <param name="obj"></param>
        void ObjAdd(IFObj obj);

        /// <summary>
        /// 本地OBJSys 删除指定OBJ
        /// </summary>
        /// <param name="obj"></param>
        void ObjRemove(IFObj obj);
        /// <summary>
        /// 启动本地OBJSys网络
        /// </summary>
        /// <param name="ep">本地地址</param>
        /// <param name="objids">建立成功后，通知这些obj</param>
        void Start_Conn_Server(IPEndPoint ep, params UInt32[] objids);
        /// <summary>
        /// 指定推送到某个远端
        /// </summary>
        /// <param name="srcobj">本地obj</param>
        /// <param name="infoid">信息码</param>
        /// <param name="infodata">信息内容</param>
        /// <param name="s1">连接conn</param>
        /// <param name="destid">目标obj</param>
        void PushObjInfoEx(IFObj srcobj, UInt16 infoid, byte[] infodata, IFConn s1, UInt32 destid);

        /// <summary>
        /// 推送到远端,系统判定根据敏感对象推送
        /// </summary>
        /// <param name="srcobj">本地obj</param>
        /// <param name="infoid">信息码</param>
        /// <param name="infodata">信息内容</param>
        void PushObjInfoEx(IFObj srcobj, UInt16 infoid, byte[] infodata);

        /// <summary>
        /// 推送到远端,系统判定根据敏感对象推送,但不推送给特定某对象
        /// </summary>
        /// <param name="srcobj">本地的obj</param>
        /// <param name="infoid">信息码</param>
        /// <param name="infodata">信息内容</param>
        /// <param name="except_s1">排除在外的连接conn</param>
        /// <param name="except_destid">排除在外的目标obj</param>
        void PushObjInfoEx_except(IFObj srcobj, UInt16 infoid, byte[] infodata, IFConn except_s1, UInt32 except_destid);


        /// <summary>
        /// 回复 客户端的CallFunction
        /// </summary>
        /// <param name="s1">客户端对应的连接代理 </param>
        /// <param name="destid">本地服务端的对象ID</param>
        /// <param name="srcid">客户端的对象ID</param>
        /// <param name="magic">交易码</param>
        /// <param name="funcid">函数ID</param>
        /// <param name="retdata">函数参数</param>
        void PushCallFunctionEx(IFConn s1, UInt32 destid, UInt32 srcid, UInt32 magic, UInt16 funcid, byte[] retdata);
    }
}
