#include <iostream>
#include <string>
#include "example_shared.h"
class Default_child_process_resolver
{
public:
const mi::IString* resolve_process(
const char* program_name,
const char* )
{
#ifdef MI_PLATFORM_WINDOWS
std::string s = program_name + std::string( ".exe");
#else
std::string s = std::string( "./") + program_name;
#endif
return result;
}
private:
};
int main( int argc, char* argv[])
{
if( argc < 4 || (strcmp( argv[1], "UDP") != 0 && strcmp( argv[1], "TCP") != 0)) {
std::cerr << "Usage: example_node_manager_worker UDP|TCP <nm_address> <base_address> \\\n"
<< " [<key=value> ...]" << std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* mode = argv[1];
const char* node_manager_address = argv[2];
const char* multicast_base_address = argv[3];
check_success( neuray.is_valid_interface());
node_manager_factory->create_worker());
node_manager_factory = 0;
new Default_child_process_resolver( factory.get()));
worker->set_child_process_resolver( child_process_resolver.get());
child_process_resolver = 0;
factory = 0;
for( int i = 4; i < argc; i++) {
const char* equal = strchr( argv[i], '=');
check_success( equal);
std::string key( argv[i],
static_cast<mi::Size>( equal-argv[i]));
std::string value( equal+1);
worker->set_property( key.c_str(), value.c_str());
}
worker->set_multicast_base_address( multicast_base_address);
mi::Sint32 result = worker->start( node_manager_address, strcmp( mode,
"TCP") == 0);
check_success( result == 0);
std::cerr << "Worker node successfully started." << std::endl;
sleep_seconds( 30);
worker->shutdown();
worker = 0;
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
A simple string class.
Definition: istring.h:22
virtual void set_c_str(const char *str)=0
Sets the content via a C-style string.
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Mixin class template for deriving interface implementations.
Definition: interface_implement.h:41
This API component allows the creation, assignment, and cloning of instances of types.
Definition: ifactory.h:35
Factory to create node manager client and worker instances.
Definition: inode_manager.h:1090
Handle<Interface> make_handle_dup(Interface *iptr)
Converts passed-in interface pointer to a handle, without taking interface over.
Definition: handle.h:439
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46
#include <iostream>
#include <string>
#include "example_shared.h"
#include "example_render_target_simple.h"
void dump_properties(
const mi::IMap* properties)
{
for(
mi::Size j = 0; j < n_properties; ++j) {
const char* key = properties->
get_key( j);
std::cerr << " " << key << "=" << value->get_c_str() << std::endl;
}
}
class Accept_all_worker_nodes
{
public:
};
class Accept_all_clusters
{
public:
};
class Worker_node_property_callback
{
public:
void property_callback(
const char* changed_property_name)
{
if( changed_property_name) {
std::cerr << "Worker node " << address->get_c_str() << " changed property \""
<< changed_property_name << "\" to \"" << property->get_c_str() << "\"."
<< std::endl;
} else {
std::cerr << "Worker node " << address->get_c_str() << " communicated its properties:"
<< std::endl;
dump_properties( properties.get());
}
}
};
class Cluster_property_callback
{
public:
void property_callback(
const char* changed_property_name)
{
if( changed_property_name) {
std::cerr << "Cluster " << address->get_c_str() << " changed property \""
<< changed_property_name << "\" to \"" << property->get_c_str() << "\"."
<< std::endl;
} else {
std::cerr << "Cluster " << address->get_c_str() << " communicated its properties:"
<< std::endl;
dump_properties( properties.get());
}
}
};
class Client_node_callback
{
public:
void membership_callback( const char* address, bool flag)
{
std::cerr << "Client node " << address << (flag ? "joined" : "left")
<< " the cluster." << std::endl;
}
};
class Worker_node_callback
{
public:
{
std::cerr << "Worker node " << address->get_c_str() << (flag ? " joined" : " left")
<< " the cluster." << std::endl;
}
};
{
check_success( nc->set_multicast_address( address) == 0);
check_success( rc->add_mdl_path( mdl_path) == 0);
check_success( rc->add_mdl_path( ".") == 0);
}
{
check_success( database.is_valid_interface());
database->get_global_scope());
scope->create_transaction());
check_success( transaction.is_valid_interface());
check_success( import_api.is_valid_interface());
import_api->import_elements( transaction.get(), uri->get_c_str()));
check_success( import_result->get_error_number() == 0);
scene->set_rootgroup( import_result->get_rootgroup());
scene->set_options( import_result->get_options());
scene->set_camera_instance( import_result->get_camera_inst());
transaction->store( scene.get(), "the_scene");
scene->create_render_context( transaction.get(), "iray"));
check_success( render_context.is_valid_interface());
scheduler_mode->set_c_str( "batch");
render_context->set_option( "scheduler_mode", scheduler_mode.get());
scene = 0;
new Render_target( image_api.get(), "Color", 512, 384));
check_success( render_context->render( transaction.get(), render_target.get(), 0) >= 0);
check_success( export_api.is_valid_interface());
export_api->export_canvas( "file:example_node_manager_client.png", canvas.get());
transaction->commit();
}
int main( int argc, char* argv[])
{
if( argc != 6 || (strcmp( argv[1], "UDP") != 0 && strcmp( argv[1], "TCP") != 0)) {
std::cerr << "Usage: example_node_manager_client UDP|TCP <nm_address> <base_address> \\\n"
<< " <scene_file> <mdl_path>" << std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* mode = argv[1];
const char* node_manager_address = argv[2];
const char* multicast_base_address = argv[3];
const char* scene_file = argv[4];
const char* mdl_path = argv[5];
check_success( neuray.is_valid_interface());
node_manager_factory->create_client());
node_manager_factory = 0;
mi::Sint32 result = client->start( node_manager_address, strcmp( mode,
"TCP") == 0);
check_success( result == 0);
std::cerr << "Client node successfully started." << std::endl;
client->set_multicast_base_address( multicast_base_address);
std::cerr << "Currently known worker nodes:" << std::endl;
mi::Size n_workers = client->get_number_of_worker_nodes();
for(
mi::Size i = 0; i < n_workers; ++i) {
client->get_worker_node( i));
if( !desc.is_valid_interface())
continue;
std::cerr << "Address: " << address->get_c_str()
<< ", in cluster: " << (desc->is_in_cluster() ? "yes": "no")
<< ", properties:" << std::endl;
dump_properties( properties.get());
}
Accept_all_clusters accept_all_clusters;
Accept_all_worker_nodes accept_all_worker_nodes;
client->join_or_create_cluster( 1, 1, &accept_all_clusters, &accept_all_worker_nodes,
"example_networking", "UDP %m . ."));
check_success( cluster.is_valid_interface());
check_success( cluster->get_cluster_status()
new Worker_node_callback);
cluster->add_worker_node_callback( worker_node_callback.get());
new Client_node_callback);
cluster->add_client_node_callback( client_node_callback.get());
new Worker_node_property_callback);
cluster->add_worker_property_callback( worker_node_property_callback.get());
new Cluster_property_callback);
cluster->add_cluster_property_callback( cluster_property_callback.get());
{
cluster->get_cluster_descriptor());
configuration( neuray.get(), address->get_c_str(), mdl_path);
check_start_success( result);
rendering( neuray.get(), scene_file);
check_success( neuray->
shutdown() == 0);
}
cluster->shutdown();
cluster = 0;
client->shutdown();
client = 0;
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
virtual const char * get_key(Size index) const =0
Returns the key corresponding to index.
virtual const base::IInterface * get_value(const char *key) const =0
Returns the value for key key.
This interface represents maps, i.e., a key-value based data structure.
Definition: imap.h:41
virtual Size get_length() const =0
Returns the size of the map.
This interface describes a cluster and its properties.
Definition: inode_manager.h:118
virtual const IString * get_multicast_address() const =0
Returns the multicast address reserved for the cluster.
virtual const IMap * get_properties() const =0
Returns the properties of the cluster.
This interface is used to interact with the distributed database.
Definition: idatabase.h:289
This interface is used to export files.
Definition: iexport_api.h:38
This interface provides various utilities related to canvases and buffers.
Definition: iimage_api.h:72
This interface is used to import files.
Definition: iimport_api.h:100
This interface is used to query and change the networking configuration.
Definition: inetwork_configuration.h:33
@ MODE_UDP
Networking is switched to UDP mode with multicast.
Definition: inetwork_configuration.h:53
This is an object representing the Iray library.
Definition: ineuray.h:44
virtual Sint32 shutdown(bool blocking=true)=0
Shuts down the library.
virtual base::IInterface * get_api_component(const base::Uuid &uuid) const =0
Returns an API component from the Iray SDK API.
virtual Sint32 start(bool blocking=true)=0
Starts the operation of the Iray library.
@ CLUSTER_ESTABLISHED
The cluster has been successfully established.
Definition: inode_manager.h:367
This interface is used to load plugins and to query information about loaded plugins.
Definition: iplugin_configuration.h:24
This interface is used to query and change the rendering configuration.
Definition: irendering_configuration.h:109
The scene is the top-level element describing a subset of DB elements to be rendered.
Definition: iscene.h:44
This interface describes a worker node and its properties.
Definition: inode_manager.h:87
virtual const IString * get_address() const =0
Returns the IP address of the worker node.
virtual const IMap * get_properties() const =0
Returns the properties of the worker node.
#define MI_BASE_DLL_FILE_EXT
The operating system specific default filename extension for shared libraries (DLLs)
Definition: config.h:340