• 简易框架


    //方法一:多继承
    /*
    //class mainop:public CSocketProtocol, public CEncDesProtocol{
    
    }*/
    
    //方法二:组合,在类里面组合对象
    class mainop{
    public:
        mainop(){
            this->sp = NULL;
            this->ed = NULL;
        }
        mainop(CSocketProtocol *sp, CEncDesProtocol *ed){
            this->sp = sp;
            this->ed = ed;
        }
        //注入接口
        setEd(CSocketProtocol *ed)
        {
            this->ed = ed;
        }
        //注入接口
        setSp(CSocketProtocol *sp)
        {
            this->sp = sp;
        }
        
        //业务框架
        int SckSendAndRec_EncDec(unsign char *in, int inlen, unsign char *out, int outlen)
        {
            int ret = 0;
            unsign char data[4096] = {0};
            int datalen;
            
            int ret = sp->cltSocketInit();
            if (ret != 0){
                return ret;
            }
            
            ret = ed->Encdata(in, inlen, data, &datalen);
            if (ret != 0){
                goto end;
            }
            
            ret = sp->cltSocketSend(data, datalen);
            if (ret != 0){
                goto end;
            }
            
            ret = sp->cltSocketRec(data, &datalen);
            if (ret != 0){
                goto end;
            }
            
            ret = ed->Desdata(data, datalen, out, outlen);
            if (ret != 0){
                goto end;
            }
            
        end:
            sp->cltSocketdestory();
        }
        
        CSocketProtocol *sp;
        CEncDesProtocol *ed;
        
    
    }
    int main(){
        int ret = 0;
        unsign char in[4096] = {0};
        unsign char out[4096] = {0};
        int inlen = 0;
        out outlen = 0;
        
        strcpy(in, "11111111111");
        int inlen = strlen(in);
        
        mainop *mymainop = new mainop();
        CSocketProtocol *sp = new CSckFactory1();
        CEncDesProtocol *ed = new CHwEncDes();
        mainop->setsp(sp);
        mainop->setEd(ed);
        
        ret = mymainop->SckSendAndRec_EncDec(sp, ed, in, inlen, out, &outlen);
        if (ret != 0) {
            
            return ret;
        }
        
        delete sp;
        delete ed;
        delete mymainop;
        
        return 0;
    }
    /*业务框架,多态的平台
    int SckSendAndRec_EncDec(CSocketProtocol *sp, CEncDesProtocol *ed, unsign char *in, int inlen, unsign char *out, int outlen)
    {
        int ret = 0;
        unsign char data[4096] = {0};
        int datalen;
        
        int ret = sp->cltSocketInit();
        if (ret != 0){
            return ret;
        }
        
        ret = ed->Encdata(in, inlen, data, &datalen);
        if (ret != 0){
            goto end;
        }
        
        ret = sp->cltSocketSend(data, datalen);
        if (ret != 0){
            goto end;
        }
        
        ret = sp->cltSocketRec(data, &datalen);
        if (ret != 0){
            goto end;
        }
        
        ret = ed->Desdata(data, datalen, out, outlen);
        if (ret != 0){
            goto end;
        }
        
    end:
        sp->cltSocketdestory();
    }
    int main(){
        int ret = 0;
        unsign char in[4096] = {0};
        unsign char out[4096] = {0};
        int inlen = 0;
        out outlen = 0;
        
        strcpy(in, "11111111111");
        int inlen = strlen(in);
        
        CSocketProtocol *sp = new CSocketProtocol();
        CEncDesProtocol *ed = new CEncDesProtocol();
        
        ret = SckSendAndRec_EncDec(sp, ed, in, inlen, out, &outlen);
        if (ret != 0) {
            
            return ret;
        }
        
        delete sp;
        delete ed;
        
        return 0;
    }*/
  • 相关阅读:
    一种解决h5页面背景音乐不能自动播放的方案
    VUE中的v-if与v-show
    setInterval(code, time)中code传递参数办法
    CSS——图片替换方法比较
    JSON(三)——java中对于JSON格式数据的解析之json-lib与jackson
    JSON(二)——JavaScript中js对象与JSON格式字符串的相互转换
    JSON(一)——JSON与JavaScript的关系
    详解Ajax请求(四)——多个异步请求的执行顺序
    详解Ajax请求(三)——jQuery对Ajax的实现及serialize()函数对于表单域控件参数提交的使用技巧
    详解Ajax请求(二)——异步请求原理的分析
  • 原文地址:https://www.cnblogs.com/jly594761082/p/10550365.html
Copyright © 2020-2023  润新知