Blender V2.61 - r43446

cycles_server.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include <stdio.h>
00020 
00021 #include "device.h"
00022 
00023 #include "util_args.h"
00024 #include "util_foreach.h"
00025 #include "util_path.h"
00026 #include "util_string.h"
00027 
00028 using namespace ccl;
00029 
00030 int main(int argc, const char **argv)
00031 {
00032     path_init();
00033 
00034     /* device types */
00035     string devices = "";
00036     string devicename = "cpu";
00037     bool list = false;
00038 
00039     vector<DeviceType>& types = Device::available_types();
00040 
00041     foreach(DeviceType type, types) {
00042         if(devices != "")
00043             devices += ", ";
00044 
00045         devices += Device::string_from_type(type);
00046     }
00047 
00048     /* parse options */
00049     ArgParse ap;
00050 
00051     ap.options ("Usage: cycles_server [options]",
00052         "--device %s", &devicename, ("Devices to use: " + devices).c_str(),
00053         "--list-devices", &list, "List information about all available devices",
00054         NULL);
00055 
00056     if(ap.parse(argc, argv) < 0) {
00057         fprintf(stderr, "%s\n", ap.error_message().c_str());
00058         ap.usage();
00059         exit(EXIT_FAILURE);
00060     }
00061     else if(list) {
00062         vector<DeviceInfo>& devices = Device::available_devices();
00063 
00064         printf("Devices:\n");
00065 
00066         foreach(DeviceInfo& info, devices) {
00067             printf("    %s%s\n",
00068                 info.description.c_str(),
00069                 (info.display_device)? " (display)": "");
00070         }
00071 
00072         exit(EXIT_SUCCESS);
00073     }
00074 
00075     /* find matching device */
00076     DeviceType device_type = Device::type_from_string(devicename.c_str());
00077     vector<DeviceInfo>& devices = Device::available_devices();
00078     DeviceInfo device_info;
00079 
00080     foreach(DeviceInfo& device, devices) {
00081         if(device_type == device.type) {
00082             device_info = device;
00083             break;
00084         }
00085     }
00086 
00087     while(1) {
00088         Device *device = Device::create(device_info);
00089         printf("Cycles Server with device: %s\n", device->description().c_str());
00090         device->server_run();
00091         delete device;
00092     }
00093 
00094     return 0;
00095 }
00096