Changeset 8 in chevmsgr


Ignore:
Timestamp:
08/30/15 00:01:12 (9 years ago)
Author:
cheese
Message:

클라 UI 쪼끔 수정
프로토콜 메시지 좀 수정
클라 메시지 핸들링 추가

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/msg.cpp

    r6 r8  
    44    json::Object _obj;                          \
    55    makeTemplate(_obj, _type);                  \
    6 
    7 #define DELIMITER   "$"
    86
    97namespace Protocol
     
    1816    {
    1917        return get<std::string>("type");
     18    }
     19
     20    std::vector<SFriend> Message::getFriendList() const
     21    {
     22        json::Array ar = mObject[ProtocolType::FRIEND_LIST];
     23
     24        std::vector<SFriend> friendList;
     25
     26        std::vector<json::Value>::iterator iter;
     27        for (iter = ar.begin(); iter != ar.end(); iter++)
     28        {
     29            SFriend fr;
     30
     31            fr.id   = (*iter)[ProtocolType::ID  ];
     32            fr.name = (*iter)[ProtocolType::NAME];
     33
     34            friendList.push_back(fr);
     35        }
     36
     37        return friendList;
    2038    }
    2139
     
    3351    void Request::makeTemplate(json::Object & obj, const std::string & type) const
    3452    {
    35         obj[ProtocolType::ID  ] = mID;
     53        obj[ProtocolType::ID] = mID;
    3654        obj[ProtocolType::TYPE] = type;
    3755    }
     
    5068        DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::JOIN);
    5169
    52         obj[ProtocolType::ID ] = id;
    53         obj[ProtocolType::PW ] = pw;
     70        obj[ProtocolType::ID] = id;
     71        obj[ProtocolType::PW] = pw;
    5472        obj[ProtocolType::SMS] = sms;
    5573
     
    88106        DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::CHAT);
    89107
    90         obj[ProtocolType::FROM      ] = mID;
     108        obj[ProtocolType::FROM] = mID;
    91109        obj[ProtocolType::SESSION_ID] = sessid;
    92         obj[ProtocolType::MESSAGE   ] = message;
    93         obj[ProtocolType::SENSITIVE ] = sensitive;
     110        obj[ProtocolType::MESSAGE] = message;
     111        obj[ProtocolType::SENSITIVE] = sensitive;
    94112
    95113        return json::Serialize(obj);
     
    117135        return json::Serialize(obj);
    118136    }
     137
     138    std::string Response::friendList(const std::vector<SFriend> & friendList) const
     139    {
     140        DECLARE_TEMPLATE_OBJECT(obj, ProtocolType::FRIEND_LIST);
     141
     142        json::Array ar;
     143        std::vector<SFriend>::const_iterator iter;
     144        for (iter = friendList.begin() ; iter != friendList.end() ; iter++)
     145        {
     146            json::Object fr;
     147
     148            fr[ProtocolType::ID  ] = iter->id;
     149            fr[ProtocolType::NAME] = iter->name;
     150
     151            ar.push_back(fr);
     152        }
     153
     154        obj[ProtocolType::FRIEND_LIST] = ar;
     155
     156        return json::Serialize(obj);
     157    }
    119158};
  • trunk/msg.hpp

    r6 r8  
    1515} SFriend;
    1616
     17#define DELIMITER   "$"
     18
    1719// --------------------------------------------------------------
    1820
     
    2325    DECLARE_KEY(ID);
    2426    DECLARE_KEY(TYPE);
     27    DECLARE_KEY(NAME);
    2528    DECLARE_KEY(SMS);
    2629    DECLARE_KEY(PHONE);
     
    3740    DECLARE_KEY(SENSITIVE);
    3841    DECLARE_KEY(GET_FRIEND_LIST);
     42    DECLARE_KEY(FRIEND_LIST);
    3943    DECLARE_KEY(RESULT);
    4044}
     
    5559            return (T)mObject[key];
    5660        }
     61
     62        inline std::vector<SFriend> getFriendList() const;
    5763
    5864        std::string type() const;
  • trunk/msgclnt.cpp

    r6 r8  
    22#include "msgclnt.h"
    33#include "msg.hpp"
     4
     5#include <algorithm>
    46
    57#include <stdlib.h>
     
    182184std::vector<SFriend> chev::getFriendList()
    183185{
     186    std::vector<SFriend> friendList;
     187
    184188    try
    185189    {
    186190        socket.send(request.getFriendList());
    187     }
    188     catch (cf::exception & e)
    189     {
    190         LOG(e.what());
    191     }
    192     return std::vector<SFriend>();
    193 }
    194 
    195 std::string chev::getSessionID(const std::vector<std::string> & idList)
    196 {
    197     try
    198     {
     191
     192        friendList = messageQ.pop(ProtocolType::FRIEND_LIST).getFriendList();
     193    }
     194    catch (cf::exception & e)
     195    {
     196        LOG(e.what());
     197    }
     198
     199    return friendList;
     200}
     201
     202std::string chev::getSessionID(std::vector<std::string> & idList)
     203{
     204    try
     205    {
     206        if (idList.size() == 2)
     207            std::sort(idList.begin(), idList.end());
     208
    199209        std::string concat = idList[0];
    200210
    201         for (int iter = 1 ; iter < idList.size() ; iter++)
    202             concat += "," + idList[iter];
     211        for (int iter = 1; iter < idList.size(); iter++)
     212            concat += DELIMITER + idList[iter];
    203213
    204214        if (sessionMap.find(concat) == sessionMap.end())
     
    206216            socket.send(request.openSession(concat));
    207217
    208             std::string response = socket.receive().toString();
    209             Protocol::Message parser;
    210             parser.parse(response);
    211 
    212             if (!parser.get<bool>("result"))
     218            Protocol::Message message = messageQ.pop(ProtocolType::SESSION_ID);
     219
     220            if (!message.get<bool>(ProtocolType::RESULT))
    213221                THROW_EXCEPTION("failed to open session id");
    214222
    215             sessionMap[concat] = parser.get<std::string>("sess-id");
     223            sessionMap[concat] = message.get<std::string>(ProtocolType::SESSION_ID);
    216224        }
    217225
     
    247255{
    248256    SConversation c;
    249     Protocol::Message parser = messageQ.pop(ProtocolType::CHAT);
    250 
    251     c.sessid    = parser.get<std::string>(ProtocolType::SESSION_ID);
    252     c.message   = parser.get<std::string>(ProtocolType::MESSAGE);
    253     c.sensitive = parser.get<int>(ProtocolType::SENSITIVE);
    254     c.isError   = parser.get<bool>(ProtocolType::RESULT);
    255 
    256     c.from      = parser.get<std::string>(ProtocolType::FROM);
     257    Protocol::Message message = messageQ.pop(ProtocolType::CHAT);
     258
     259    c.sessid    = message.get<std::string>(ProtocolType::SESSION_ID);
     260    c.message   = message.get<std::string>(ProtocolType::MESSAGE);
     261    c.sensitive = message.get<int>(ProtocolType::SENSITIVE);
     262    c.isError   = message.get<bool>(ProtocolType::RESULT);
     263
     264    c.from      = message.get<std::string>(ProtocolType::FROM);
    257265
    258266    return c;
  • trunk/msgclnt.h

    r6 r8  
    6464    std::vector<SFriend> getFriendList();
    6565
    66     std::string getSessionID(const std::vector<std::string> & idList);
     66    std::string getSessionID(std::vector<std::string> & idList);
    6767
    6868    bool tell(const SConversation & conversation);
  • trunk/msvc14/ChevMsgrClient_MFC/ChevMsgrClient_MFC.vcxproj

    r4 r8  
    218218  <ImportGroup Label="ExtensionTargets">
    219219  </ImportGroup>
     220  <ProjectExtensions>
     221    <VisualStudio>
     222      <UserProperties RESOURCE_FILE="ChevMsgrClient_MFC.rc" />
     223    </VisualStudio>
     224  </ProjectExtensions>
    220225</Project>
Note: See TracChangeset for help on using the changeset viewer.