38 |
{ |
{ |
39 |
bool error = false; |
bool error = false; |
40 |
lock(); |
lock(); |
41 |
std::string file = getSpoolFilename(); |
std::string file = findSpoolFilename(); |
42 |
std::ofstream out(file.c_str()); |
std::ofstream out(file.c_str()); |
43 |
if (out) { |
if (out) { |
44 |
out << recipient << "\n" << message; |
out << recipient << "\n" << message; |
50 |
|
|
51 |
if (error) |
if (error) |
52 |
throw std::runtime_error("Could not create spoolfile"); |
throw std::runtime_error("Could not create spoolfile"); |
53 |
|
this->filename = file; |
54 |
} |
} |
55 |
|
|
56 |
std::string Spooler::dequeue() |
std::string Spooler::dequeue() |
87 |
|
|
88 |
unlock(); |
unlock(); |
89 |
|
|
90 |
|
this->filename = file; |
91 |
|
|
92 |
if (file != "") |
if (file != "") |
93 |
return message; |
return message; |
94 |
else |
else |
95 |
throw filenotfoundexception(); |
throw filenotfoundexception(); |
96 |
} |
} |
97 |
|
|
98 |
std::string Spooler::getSpoolFilename() |
std::string Spooler::findSpoolFilename() |
99 |
{ |
{ |
100 |
std::string file; |
std::string file; |
101 |
std::stringstream ss; |
std::stringstream ss; |
147 |
{ |
{ |
148 |
flock(fd, LOCK_UN); |
flock(fd, LOCK_UN); |
149 |
} |
} |
150 |
|
|
151 |
|
string Spooler::getFilename() |
152 |
|
{ |
153 |
|
return filename; |
154 |
|
} |