Move things round a bit.
[dcpomatic.git] / src / lib / server.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file src/server.cc
21  *  @brief Class to describe a server to which we can send
22  *  encoding work.
23  */
24
25 #include <string>
26 #include <vector>
27 #include <sstream>
28 #include <boost/algorithm/string.hpp>
29 #include "server.h"
30
31 using namespace std;
32 using namespace boost;
33
34 /** Create a server from a string of metadata returned from as_metadata().
35  *  @param v Metadata.
36  *  @return Server, or 0.
37  */
38 Server *
39 Server::create_from_metadata (string v)
40 {
41         vector<string> b;
42         split (b, v, is_any_of (" "));
43
44         if (b.size() != 2) {
45                 return 0;
46         }
47
48         return new Server (b[0], atoi (b[1].c_str ()));
49 }
50
51 /** @return Description of this server as text */
52 string
53 Server::as_metadata () const
54 {
55         stringstream s;
56         s << _host_name << " " << _threads;
57         return s.str ();
58 }