File: ControlSocket.h

package info (click to toggle)
ickle 0.3.2-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,600 kB
  • ctags: 1,172
  • sloc: cpp: 9,896; sh: 6,914; perl: 285; makefile: 173
file content (110 lines) | stat: -rw-r--r-- 3,259 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 * Copyright (C) 2002 Dominic Sacr <bugcreator@gmx.de>.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 */

#ifndef CONTROLSOCKET_H
#define CONTROLSOCKET_H

#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <string>
#include <set>

#include <libicq2000/constants.h>

#include "ControlCommands.h"

// ============================================================================
//  ControlSocketBase
// ============================================================================

class ControlSocketBase
{
 public:
  ControlSocketBase (int sd = 0) : m_sd (sd) { }

  int sd () const { return m_sd; }

 protected:
  int m_sd;
};


// ============================================================================
//  ControlSocket
// ============================================================================

class ControlSocket : public ControlSocketBase
{
 public:
  ControlSocket (int sd = 0) : ControlSocketBase (sd) { }

  ControlSocket & operator<< (unsigned int);
  ControlSocket & operator<< (bool);
  ControlSocket & operator<< (const std::string &);
  ControlSocket & operator<< (int v) { return operator<< ((unsigned int)v); }
  ControlSocket & operator<< (const CommandType & v) { return operator<< ((unsigned int&)v); }
  ControlSocket & operator<< (const CommandMessageType & v) { return operator<< ((unsigned int&)v); }
  ControlSocket & operator<< (const ICQ2000::Status & v) { return operator<< ((unsigned int&)v); }

  ControlSocket & operator>> (unsigned int &);
  ControlSocket & operator>> (bool &);
  ControlSocket & operator>> (std::string &);
  ControlSocket & operator>> (int & v) { return operator>> ((unsigned int&)v); }
  ControlSocket & operator>> (CommandMessageType & v) { return operator>> ((unsigned int&)v); }
  ControlSocket & operator>> (CommandType & v) { return operator>> ((unsigned int&)v); }
  ControlSocket & operator>> (ICQ2000::Status & v) { return operator>> ((unsigned int&)v); }

  enum ReadStatus {
    WAITING,
    READ,
    CLOSED
  };

  ReadStatus readStatus ();
};


// ============================================================================
//  ControlSocketServer
// ============================================================================

class ControlSocketServer : public ControlSocketBase
{
 public:
  bool init (const std::string & socket_path);
  void quit ();

  int getConnection ();
  void closeConnection (int sd);

 private:
  sockaddr_un m_saddr;
};


// ============================================================================
//  ControlSocketClient
// ============================================================================

class ControlSocketClient : public ControlSocket
{
 public:
  bool init (const std::string & socket_path, bool quiet = false);
  void quit ();
};

#endif