source: chevmsgr/trunk/msg.hpp@ 4

Last change on this file since 4 was 4, checked in by cheese, 9 years ago

자 이제 시작이야 (졸작을)

File size: 1.8 KB
Line 
1#pragma once
2
3#include "cf/logger.h"
4
5#include "json.h"
6
7#include <iostream>
8#include <string>
9#include <vector>
10
11#define LOG(message) log(__FILE__,__func__,__LINE__,message)
12
13static void log(const std::string & file,
14 const std::string & func,
15 const int line,
16 const std::string & message)
17{
18 static cf::logger * logger = NULL;
19
20 if (!logger)
21 {
22 logger = cf::logger::getInstance();
23 logger->init(".");
24 logger->setLevel(1);
25 logger->add("messenger", 1, "INFO", 0);
26 }
27
28 logger->write(1, message);
29 std::cerr << "[" << file << ":" << line << "][" << func << "] "
30 << message << std::endl;
31}
32
33// --------------------------------------------------------------
34namespace Message
35{
36 class Parser
37 {
38 private:
39 json::Object mObject;
40
41 public:
42 void parse(const std::string & message);
43
44 template<typename T>
45 inline T get(const std::string & key) const
46 {
47 return (T)mObject[key];
48 }
49
50 std::string type() const;
51 };
52
53 class IMessage
54 {
55 public:
56 virtual void makeTemplate(json::Object & obj, const std::string & type) const = 0;
57 };
58
59 class Request : public IMessage
60 {
61 private:
62 std::string mID;
63
64 public:
65 void setUserID(const std::string & id);
66
67 const std::string & getUserID();
68
69 void makeTemplate(json::Object & obj, const std::string & type) const;
70
71 std::string command(const std::string & cmd) const;
72
73 std::string login(const std::string & pw) const;
74
75 std::string Request::chat(const std::string & to, const std::string & sessid, const std::string & message) const;
76
77 std::string friendList() const;
78 };
79
80 class Response : public IMessage
81 {
82 public:
83 typedef struct friendInfo
84 {
85 std::string id;
86 std::string name;
87 } friendInfo;
88
89 public:
90 void makeTemplate(json::Object & obj, const std::string & type) const;
91
92 std::string result(const bool status) const;
93 };
94};
Note: See TracBrowser for help on using the repository browser.