Changeset 6 in chevmsgr for trunk/msgclnt.h


Ignore:
Timestamp:
08/29/15 02:20:50 (9 years ago)
Author:
cheese
Message:

modify client interface and message protocol

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/msgclnt.h

    r5 r6  
    99#include "cf/task.h"
    1010
    11 typedef struct SFriend
     11typedef struct SConversation
    1212{
    13     std::string id;
    14     std::string name;
    15 } SFriend;
     13    // tell and listen
     14    std::string sessid;
     15    std::string message;
     16    int sensitive;
     17    bool isError;
    1618
    17 // for callback
     19    // only for listen
     20    std::string from;
     21} SConversation;
    1822
    19 typedef struct SResultResponse
     23class MessageQ
    2024{
    21     bool result;
    22     bool isError;
    23 } SResultResponse;
     25private:
     26    cf::task::mutex                 mutex;
     27    std::vector<Protocol::Message>  messageQ;
    2428
    25 typedef struct SReceivedMessage
    26 {
    27     std::string sessid;
    28     std::string sender;
    29     std::string message;
    30     bool isError;
    31 } SReceivedMessage;
     29public:
     30    void push(const Protocol::Message & parser);
    3231
    33 typedef int (* callback_onResultResponse)(SResultResponse &);
    34 typedef int (* callback_onReceiveMessage)(SReceivedMessage &);
    35 
    36 typedef struct SCallback
    37 {
    38     callback_onResultResponse result;
    39     callback_onReceiveMessage message;
    40 } SCallback;
     32    Protocol::Message pop(const std::string & requestType);
     33};
    4134
    4235class chev
    4336{
    4437private:
    45     Message::Request    request;
     38    Protocol::Request   request;
    4639    std::string         error;
    4740    cf::network::tcp    socket;
    4841    cf::task::thread    listener;
    49     SCallback           callback;
     42
     43    MessageQ            messageQ;
     44
     45    std::map<std::string, std::string>  sessionMap;
    5046
    5147public:
    5248    chev();
     49
     50    ~chev();
     51
     52    const std::string & getLastError() const;
    5353
    5454    bool connect(const std::string & host, unsigned short port);
     
    6464    std::vector<SFriend> getFriendList();
    6565
    66     bool sendMessage(const std::string & friendid, const std::string & sessionID, const std::string & message);
     66    std::string getSessionID(const std::vector<std::string> & idList);
    6767
    68     // call once
    69     bool runReceiver(const SCallback & cb);
     68    bool tell(const SConversation & conversation);
    7069
    71     const std::string & getLastError();
     70    SConversation listen();
    7271};
Note: See TracChangeset for help on using the changeset viewer.