Cycles: Code cleanup, spaces around keywords
[blender-staging.git] / intern / cycles / app / cycles_server.cpp
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <stdio.h>
18
19 #include "device.h"
20
21 #include "util_args.h"
22 #include "util_foreach.h"
23 #include "util_path.h"
24 #include "util_stats.h"
25 #include "util_string.h"
26 #include "util_task.h"
27
28 using namespace ccl;
29
30 int main(int argc, const char **argv)
31 {
32         util_logging_init(argv[0]);
33         path_init();
34
35         /* device types */
36         string devicelist = "";
37         string devicename = "cpu";
38         bool list = false, debug = false;
39         int threads = 0, verbosity = 1;
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                 "--threads %d", &threads, "Number of threads to use for CPU device",
57 #ifdef WITH_CYCLES_LOGGING
58                 "--debug", &debug, "Enable debug logging",
59                 "--verbose %d", &verbosity, "Set verbosity of the logger",
60 #endif
61                 NULL);
62
63         if(ap.parse(argc, argv) < 0) {
64                 fprintf(stderr, "%s\n", ap.geterror().c_str());
65                 ap.usage();
66                 exit(EXIT_FAILURE);
67         }
68
69         if(debug) {
70                 util_logging_start();
71                 util_logging_verbosity_set(verbosity);
72         }
73
74         if(list) {
75                 vector<DeviceInfo>& devices = Device::available_devices();
76
77                 printf("Devices:\n");
78
79                 foreach(DeviceInfo& info, devices) {
80                         printf("    %s%s\n",
81                                 info.description.c_str(),
82                                 (info.display_device)? " (display)": "");
83                 }
84
85                 exit(EXIT_SUCCESS);
86         }
87
88         /* find matching device */
89         DeviceType device_type = Device::type_from_string(devicename.c_str());
90         vector<DeviceInfo>& devices = Device::available_devices();
91         DeviceInfo device_info;
92
93         foreach(DeviceInfo& device, devices) {
94                 if(device_type == device.type) {
95                         device_info = device;
96                         break;
97                 }
98         }
99
100         TaskScheduler::init(threads);
101
102         while(1) {
103                 Stats stats;
104                 Device *device = Device::create(device_info, stats, true);
105                 printf("Cycles Server with device: %s\n", device->info.description.c_str());
106                 device->server_run();
107                 delete device;
108         }
109
110         TaskScheduler::exit();
111
112         return 0;
113 }
114