public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
passenger / ext / apache2 / Application.h
100644 78 lines (62 sloc) 1.356 kb
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
#ifndef _PASSENGER_APPLICATION_H_
#define _PASSENGER_APPLICATION_H_
 
#include <sys/types.h>
#include <boost/shared_ptr.hpp>
#include <string>
#include "Utils.h"
 
namespace Passenger {
 
using namespace std;
using namespace boost;
 
// TODO: write better documentation
class Application {
private:
  string appRoot;
  pid_t pid;
  int reader, writer;
public:
  Application(const string &theAppRoot, pid_t pid, int reader, int writer) {
    appRoot = theAppRoot;
    this->pid = pid;
    this->reader = reader;
    this->writer = writer;
    P_TRACE("Application " << this << ": created.");
  }
  
  ~Application() {
    closeReader();
    closeWriter();
    P_TRACE("Application " << this << ": destroyed.");
  }
  
  void detachCommunicationChannels() {
    reader = -1;
    writer = -1;
  }
  
  string getAppRoot() const {
    return appRoot;
  }
  
  pid_t getPid() const {
    return pid;
  }
  
  int getReader() const {
    return reader;
  }
  
  int getWriter() const {
    return writer;
  }
  
  void closeReader() {
    if (reader != -1) {
      close(reader);
      reader = -1;
      P_TRACE("Application " << this << ": reader closed.");
    }
  }
  
  void closeWriter() {
    if (writer != -1) {
      close(writer);
      writer = -1;
      P_TRACE("Application " << this << ": writer closed.");
    }
  }
};
 
typedef shared_ptr<Application> ApplicationPtr;
 
} // namespace Passenger
 
#endif /* _PASSENGER_APPLICATION_H_ */