add BLI_strcpy_rlen, replace strcat, which was used in misleading way.
[blender.git] / intern / cycles / app / cycles_server.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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 Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #include <stdio.h>
20
21 #include "device.h"
22
23 #include "util_args.h"
24 #include "util_foreach.h"
25 #include "util_path.h"
26 #include "util_stats.h"
27 #include "util_string.h"
28 #include "util_task.h"
29
30 using namespace ccl;
31
32 int main(int argc, const char **argv)
33 {
34         path_init();
35
36         /* device types */
37         string devicelist = "";
38         string devicename = "cpu";
39         bool list = false;
40
41         vector<DeviceType>& types = Device::available_types();
42
43         foreach(DeviceType type, types) {
44                 if(devicelist != "")
45                         devicelist += ", ";
46
47                 devicelist += Device::string_from_type(type);
48         }
49
50         /* parse options */
51         ArgParse ap;
52
53         ap.options ("Usage: cycles_server [options]",
54                 "--device %s", &devicename, ("Devices to use: " + devicelist).c_str(),
55                 "--list-devices", &list, "List information about all available devices",
56                 NULL);
57
58         if(ap.parse(argc, argv) < 0) {
59                 fprintf(stderr, "%s\n", ap.geterror().c_str());
60                 ap.usage();
61                 exit(EXIT_FAILURE);
62         }
63         else if(list) {
64                 vector<DeviceInfo>& devices = Device::available_devices();
65
66                 printf("Devices:\n");
67
68                 foreach(DeviceInfo& info, devices) {
69                         printf("    %s%s\n",
70                                 info.description.c_str(),
71                                 (info.display_device)? " (display)": "");
72                 }
73
74                 exit(EXIT_SUCCESS);
75         }
76
77         /* find matching device */
78         DeviceType device_type = Device::type_from_string(devicename.c_str());
79         vector<DeviceInfo>& devices = Device::available_devices();
80         DeviceInfo device_info;
81
82         foreach(DeviceInfo& device, devices) {
83                 if(device_type == device.type) {
84                         device_info = device;
85                         break;
86                 }
87         }
88
89         TaskScheduler::init();
90
91         while(1) {
92                 Stats stats;
93                 Device *device = Device::create(device_info, stats);
94                 printf("Cycles Server with device: %s\n", device->info.description.c_str());
95                 device->server_run();
96                 delete device;
97         }
98
99         TaskScheduler::exit();
100
101         return 0;
102 }
103