Exemplo n.º 1
0
bool 
UserManager::ChangePassword( ValueSet &requestParms, SsapiResponder *pResponder ){

	DesignatorId				id;
	UnicodeString				oldPassword, newPassword, password;
	bool						rc = true;
	ManagedObject				*pManagedObject;
	
	if( !requestParms.GetGenericValue( (char *)&id, sizeof(id), SSAPI_USER_MANAGER_CHANGE_PASSWORD_OBJECT_ID ) )
		rc = false;
	else if( !requestParms.GetString( SSAPI_USER_MANAGER_CHANGE_PASSWORD_OLD_PASSWORD, &oldPassword ) )
		rc = false;
	else if(!requestParms.GetString( SSAPI_USER_MANAGER_CHANGE_PASSWORD_NEW_PASSWORD, &newPassword ) )
		rc = false;

	if( !rc )
		return pResponder->RespondToRequest( SSAPI_EXCEPTION_INVALID_PARAMETER, CTS_SSAPI_INVALID_PARAM_EXCEPTION );

	if( !( pManagedObject = GetManagedObject( &id ) ) )
		return pResponder->RespondToRequest( SSAPI_EXCEPTION_INVALID_PARAMETER, CTS_SSAPI_OBJECT_DOES_NOT_EXIST_EXCEPTION );
	
	pManagedObject->BuildYourValueSet();
	pManagedObject->GetString( SSAPI_USER_FID_PASSWORD, &password );
	pManagedObject->Clear();
	if( (password == oldPassword) == false )
		return pResponder->RespondToRequest( SSAPI_EXCEPTION_SECURITY, CTS_SSAPI_SECURITY_INVALID_PASSWORD );

	User *pUser = new User(0);
	pUser->AddString( &newPassword, SSAPI_USER_FID_PASSWORD );
	pUser->AddGenericValue( (char *)&id, sizeof(id), SSAPI_OBJECT_FID_ID );
	rc = ModifyUser( pUser, pResponder );
	delete pUser;

	return rc;
}
Exemplo n.º 2
0
 /*! assign (named) vec3i parameter to an object */
 void ISPCDevice::setVec3i(OSPObject _object,
                           const char *bufName,
                           const vec3i &v)
 {
   ManagedObject *object = (ManagedObject *)_object;
   object->setParam(bufName, v);
 }
Exemplo n.º 3
0
static bool is_valid_object(jvmtiEnv* env, jobject handle)
{
    SuspendEnabledChecker sec;

    if (NULL == handle)
        return true;

    tmn_suspend_disable();

    ManagedObject *obj = ((ObjectHandle) handle)->object;

    if (obj < (ManagedObject *)VM_Global_State::loader_env->heap_base ||
        obj > (ManagedObject *)VM_Global_State::loader_env->heap_end)
    {
        tmn_suspend_enable();
        return false;
    }

    Class *clss = obj->vt()->clss;
    ManagedObject *clsObj = struct_Class_to_java_lang_Class(clss);
    // ppervov: FIXME: there is an assertion in the above function which
    // is exactly the same as in the following if. So, this code will only
    // work in release and just assert in debug.
    if (clsObj->vt()->clss != VM_Global_State::loader_env->JavaLangClass_Class) {
        tmn_suspend_enable();
        return false;
    }

    tmn_suspend_enable();
    return true;
}
Exemplo n.º 4
0
 /*! assign (named) float parameter to an object */
 void ISPCDevice::setBool(OSPObject _object,
                          const char *bufName,
                          const bool b)
 {
   ManagedObject *object = (ManagedObject *)_object;
   object->setParam(bufName, b);
 }
Exemplo n.º 5
0
 /*! assign (named) float parameter to an object */
 void ISPCDevice::setFloat(OSPObject _object,
                           const char *bufName,
                           const float f)
 {
   ManagedObject *object = (ManagedObject *)_object;
   object->setParam(bufName, f);
 }
Exemplo n.º 6
0
 /*! assign (named) string parameter to an object */
 void ISPCDevice::setVoidPtr(OSPObject _object,
                              const char *bufName,
                              void *v)
 {
   ManagedObject *object = (ManagedObject *)_object;
   object->setParam(bufName, v);
 }
Exemplo n.º 7
0
bool File::Delete(const String &path)
{
	ManagedObject<FileStream> file = File::Open(path, 
												FileMode::OpenExist, 
												FileAccess::NT_DELETE);
    return file.IsNull() ? false : file->Delete();
}
Exemplo n.º 8
0
 /*! assign (named) data item as a parameter to an object */
 void ISPCDevice::setObject(OSPObject _target,
                            const char *bufName,
                            OSPObject _value)
 {
   ManagedObject *target = (ManagedObject *)_target;
   ManagedObject *value  = (ManagedObject *)_value;
   target->setParam(bufName, value);
 }
Exemplo n.º 9
0
 void ISPCDevice::removeParam(OSPObject _object, const char *name)
 {
   ManagedObject *object = (ManagedObject *)_object;
   // ManagedObjects have to be decref before removing them
   ManagedObject *existing = object->getParam<ManagedObject*>(name, nullptr);
   if (existing)
       existing->refDec();
   object->removeParam(name);
 }
Exemplo n.º 10
0
FileStream *File::Create(const String &path,
						 FileMode mode /* = FileMode::CreateOnly */, 
						 FileAccess access /* = FileAccess::ReadWrite */, 
						 FileAttributes attr /* = FileAttributes::Normal */, 
						 FileShare share /* = FileShare::None */, 
						 FileOptions options /* = FileOptions::None */)
{
	ManagedObject<FileStream> file = new FileStream;
	if (file.IsNull()) {
		Exception::SetLastException(STATUS_NO_MEMORY, false);
		return nullptr;
	} //if

	  // converts to full nt path
	TCHAR fullpath[RLIB_MAX_PATH];
	StringCopyToW(Path::ToNtPath(path), fullpath);

	UNICODE_STRING us_path;
	RtlInitUnicodeString(&us_path, fullpath);

	// others parameters
	OBJECT_ATTRIBUTES obj_attr;
	InitializeObjectAttributes(&obj_attr, &us_path, OBJ_KERNEL_HANDLE | OBJ_CASE_INSENSITIVE,
							   NULL, NULL);

	IO_STATUS_BLOCK io_stat;
	NTSTATUS status = NtCreateFile(&file->m_native_handle,
								   static_cast<ACCESS_MASK>(access), 
								   &obj_attr, 
								   &io_stat, 
								   NULL,
								   static_cast<ULONG>(attr), 
								   static_cast<ULONG>(share),
								   static_cast<ULONG>(mode != FileMode::AppendAlways ? mode : FileMode::OpenOrCreate),
								   static_cast<ULONG>(options), 
								   NULL,
								   NULL);
	if (status == STATUS_SUCCESS) {
		if (mode == FileMode::AppendAlways) {
			file->Position = file->Length;
		} //if
		return file.SuppressFinalize();
	} //if

	file->m_native_handle = INVALID_HANDLE_VALUE;
	Exception::SetLastException(status);

    return nullptr;
}
Exemplo n.º 11
0
  void Renderer::commit()
  {
    autoEpsilon = getParam1i("autoEpsilon", true);
    epsilon = getParam1f("epsilon", 1e-6f);
    spp = std::max(1, getParam1i("spp", 1));
    const int32 maxDepth = getParam1i("maxDepth", 20);
    const float minContribution = getParam1f("minContribution", 0.001f);
    errorThreshold = getParam1f("varianceThreshold", 0.f);
    maxDepthTexture = (Texture2D*)getParamObject("maxDepthTexture", nullptr);
    model = (Model*)getParamObject("model", getParamObject("world"));

    if (maxDepthTexture) {
      if (maxDepthTexture->type != OSP_TEXTURE_R32F
          || !(maxDepthTexture->flags & OSP_TEXTURE_FILTER_NEAREST)) {
        static WarnOnce warning("maxDepthTexture provided to the renderer "
                                "needs to be of type OSP_TEXTURE_R32F and have "
                                "the OSP_TEXTURE_FILTER_NEAREST flag");
      }
    }

    vec3f bgColor3 = getParam3f("bgColor", vec3f(getParam1f("bgColor", 0.f)));
    bgColor = getParam4f("bgColor", vec4f(bgColor3, 0.f));

    if (getIE()) {
      ManagedObject* camera = getParamObject("camera");
      if (model) {
        const float diameter = model->bounds.empty() ?
                               1.0f : length(model->bounds.size());
        epsilon *= diameter;
      }

      ispc::Renderer_set(getIE()
          , model ? model->getIE() : nullptr
          , camera ? camera->getIE() : nullptr
          , autoEpsilon
          , epsilon
          , spp
          , maxDepth
          , minContribution
          , (ispc::vec4f&)bgColor
          , maxDepthTexture ? maxDepthTexture->getIE() : nullptr
          );
    }
  }
Exemplo n.º 12
0
Class* exn_get_class() {
    // we can check heap references for equality to NULL
    // without disabling gc, because GC wouldn't change
    // null to non-null and vice versa.
    vm_thread_t vm_thread = p_TLS_vmthread;
    if ((NULL == vm_thread->thread_exception.exc_object)
        && (NULL == vm_thread->thread_exception.exc_class)) {
        return NULL;
    }

    Class* result;

    if (NULL != vm_thread->thread_exception.exc_object) {
        tmn_suspend_disable_recursive();
        ManagedObject* exn = vm_thread->thread_exception.exc_object;
        result = exn->vt()->clss;
        tmn_suspend_enable_recursive();
    } else if (NULL != vm_thread->thread_exception.exc_class) {
        result = vm_thread->thread_exception.exc_class;
    } else {
        LDIE(59, "It's impossible internal error in exception handling.");
    }
    return result;
}
Exemplo n.º 13
0
 /*! Note that all objects in ospray are refcounted, so one cannot
   explicitly "delete" any object. Instead, each object is created
   with a refcount of 1, and this refcount will be
   increased/decreased every time another object refers to this
   object resp. releases its hold on it; if the refcount is 0 the
   object will automatically get deleted. For example, you can
   create a new material, assign it to a geometry, and immediately
   after this assignation release it; the material will
   stay 'alive' as long as the given geometry requires it. */
 void ISPCDevice::release(OSPObject _obj)
 {
   if (!_obj) return;
   ManagedObject *obj = (ManagedObject *)_obj;
   obj->refDec();
 }
Exemplo n.º 14
0
 /*! finalize a newly specified model */
 void ISPCDevice::commit(OSPObject _object)
 {
   ManagedObject *object = (ManagedObject *)_object;
   object->commit();
 }
Exemplo n.º 15
0
void
JIT_execute_method_default(JIT_Handle jh, 
                           jmethodID   methodID,
                           jvalue   *return_value,
                           jvalue   *args)
{
    //assert(("Doesn't compile", 0));
    //abort();
#if 1
    Method *meth = (Method*) methodID;
    assert(!hythread_is_suspend_enabled());
    void *entry_point = meth->get_code_addr();
    int nargs = meth->get_num_args();
    uint64 arg_words[255];
    int double_nargs = 0;
    double double_args[8];
    int num_arg_words = 0;
    int arg_num = 0;
    int num_ref_args = 0;
    Arg_List_Iterator iter = meth->get_argument_list();
    uint64 i64;
    Java_Type typ;
    char msg[300];
    if(!meth->is_static()) {
        ObjectHandle h = (ObjectHandle) args[arg_num++].l;
        // this pointer
        i64 = 0;
        if (h) i64 = (uint64) h->object;
        if (VM_Global_State::loader_env->compress_references) {
            // 20030318 We are in unmanaged code where null is represented by 0/NULL. Convert a null reference
            // to the representation of null in managed code (heap_base).
            if (i64 == 0) {
                i64 = (uint64)VM_Global_State::loader_env->heap_base;
            }
        }
        arg_words[num_arg_words++] = i64;
        num_ref_args++;
    }
    while((typ = curr_arg(iter)) != JAVA_TYPE_END) {
        ObjectHandle h;
        *msg = '\0';
        switch(typ) {
        case JAVA_TYPE_LONG:
            i64 = args[arg_num++].j;
            arg_words[num_arg_words++] = i64;
            break;
        case JAVA_TYPE_CLASS:
        case JAVA_TYPE_ARRAY:
            h = (ObjectHandle) args[arg_num++].l;
            i64 = 0;
            if (h) i64 = (uint64) h->object;
            if (VM_Global_State::loader_env->compress_references) {
                // 20030318 We are in unmanaged code where null is represented by 0/NULL. Convert a null reference
                // to the representation of null in managed code (heap_base).
                if (i64 == 0) {
                    i64 = (uint64)VM_Global_State::loader_env->heap_base;
                }
            }
            arg_words[num_arg_words++] = i64;
            num_ref_args++;
#ifdef _DEBUG
            {
                if (! VM_Global_State::loader_env->compress_references ||
                    i64 != (uint64)VM_Global_State::loader_env->heap_base) {
                    ManagedObject *object = (ManagedObject *)i64;
                    if(object) {
                        Class *clss = object->vt()->clss;
                        sprintf(msg, " of class '%s'", clss->get_name()->bytes);
                    }
                }
            }
#endif
            break;
        case JAVA_TYPE_SHORT:
            i64 = (uint64)args[arg_num++].s;
            arg_words[num_arg_words++] = i64;
            break;
        case JAVA_TYPE_CHAR:
            i64 = (uint64)args[arg_num++].c;
            arg_words[num_arg_words++] = i64;
            break;
        case JAVA_TYPE_BYTE:
            i64 = (uint64)args[arg_num++].b;
            arg_words[num_arg_words++] = i64;
            break;
        case JAVA_TYPE_BOOLEAN:
            i64 = (uint64)args[arg_num++].z;
            arg_words[num_arg_words++] = i64;
            break;
        case JAVA_TYPE_DOUBLE:
            double_args[double_nargs] = args[arg_num++].d;
            double_nargs++;
            break;
        case JAVA_TYPE_FLOAT:
            double_args[double_nargs] = (double)args[arg_num++].f;
            double_nargs++;
            break;
        default:
            i64 = (uint64)args[arg_num++].i;
            arg_words[num_arg_words++] = i64;
            break;
        }
        iter = advance_arg_iterator(iter);
    }

    // assert(nargs <= 8);
    double double_result;

    static void* addr_execute = get_vm_execute_java_method();
    struct{
        void* fun;
        void* gp;
    } fptr;
    fptr.fun = addr_execute;
    fptr.gp = get_vm_gp_value();
        // gashiman - changed _cdecl to __cdecl to work on linux
    uint64 (__cdecl *fpp_exec)(void *entry_point, int nargs, uint64 args[], 
        double *double_result_addr, int double_nargs, double double_args[], 
        void *thread_pointer, uint64 tid) = (uint64 (__cdecl * )(void *entry_point, int nargs, uint64 args[],
        double *double_result_addr, int double_nargs, double double_args[], 
        void *thread_pointer, uint64 tid))&fptr;
    IDATA id = hythread_get_self_id();
    uint64 int_result = (uint64)fpp_exec(entry_point, nargs, arg_words, &double_result,
        double_nargs, double_args, p_TLS_vmthread, id);

    // Save the result
    Java_Type ret_type = meth->get_return_java_type();
    switch(ret_type) {
    case JAVA_TYPE_VOID:
        break;
    case JAVA_TYPE_ARRAY:
    case JAVA_TYPE_CLASS:
        {
            ObjectHandle h = 0;
            if (VM_Global_State::loader_env->compress_references) {
                // 20030318 Convert a null reference in managed code (represented by heap_base)
                // to the representation of null in unmanaged code (0 or NULL).
                if ((uint64)int_result == (uint64)VM_Global_State::loader_env->heap_base) {
                    int_result = 0;
                } 
            }
            if (int_result) {
                h = oh_allocate_local_handle();
                h->object = (ManagedObject*) int_result;
            }
            return_value->l = h;
        }
        break;
    case JAVA_TYPE_LONG:
        return_value->j = int_result;
        break;
    case JAVA_TYPE_INT:
        *((I_32 *)return_value) = (I_32) int_result;
        break;
    case JAVA_TYPE_SHORT:
        *((int16 *)return_value) = (int16) int_result;
        break;
    case JAVA_TYPE_CHAR:
        *((uint16 *)return_value) = (uint16) int_result;
        break;
    case JAVA_TYPE_BYTE:
        *((I_8 *)return_value) = (I_8) int_result;
        break;
    case JAVA_TYPE_BOOLEAN:
        *((U_8 *)return_value) = (U_8) int_result;
        break;
    case JAVA_TYPE_DOUBLE:
        *((double *)return_value) = double_result;
        break;
    case JAVA_TYPE_FLOAT:
        *((float *)return_value) = (float) double_result;
        break;
    default:
#ifdef _DEBUG
        std::clog << "Returned to C from "
               << meth->get_class()->get_name()->bytes << "." << meth->get_name()->bytes
               << meth->get_descriptor()->bytes << "\n";
#endif
        //DIE("Return type ");// <<  (int)ret_type << " is not implemented\n");
        std::clog << "Return type " <<  (int)ret_type << " is not implemented\n";
    }
#endif

} //vm_execute_java_method_array
Exemplo n.º 16
0
    /*! it's up to the proper init
      routine to decide which processes call this function and which
      ones don't. This function will not return. 
      
      \internal We ssume that mpi::worker and mpi::app have already been set up
    */
    void runWorker(int *_ac, const char **_av)
    {
      ospray::init(_ac,&_av);

      // initialize embree. (we need to do this here rather than in
      // ospray::init() because in mpi-mode the latter is also called
      // in the host-stubs, where it shouldn't.
      // std::stringstream embreeConfig;
      // if (debugMode)
      //   embreeConfig << " threads=1";
      // rtcInit(embreeConfig.str().c_str());

      //      assert(rtcGetError() == RTC_NO_ERROR);
      rtcSetErrorFunction(embreeErrorFunc);

      std::stringstream embreeConfig;
      if (debugMode)
        embreeConfig << " threads=1,verbose=2";
      rtcInit(embreeConfig.str().c_str());

      if (rtcGetError() != RTC_NO_ERROR) {
        // why did the error function not get called !?
        std::cerr << "#osp:init: embree internal error number " << (int)rtcGetError() << std::endl;
        assert(rtcGetError() == RTC_NO_ERROR);
      }


      CommandStream cmd;

      char hostname[HOST_NAME_MAX];
      gethostname(hostname,HOST_NAME_MAX);
      printf("#w: running MPI worker process %i/%i on pid %i@%s\n",
             worker.rank,worker.size,getpid(),hostname);
      int rc;


      // TiledLoadBalancer::instance = new mpi::DynamicLoadBalancer_Slave;
      TiledLoadBalancer::instance = new mpi::staticLoadBalancer::Slave;


      while (1) {
        const int command = cmd.get_int32();

        switch (command) {
        case api::MPIDevice::CMD_NEW_RENDERER: {
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new renderer \"" << type << "\" ID " << handle << endl;
          Renderer *renderer = Renderer::createRenderer(type);
          cmd.free(type);
          Assert(renderer);
          handle.assign(renderer);
        } break;
        case api::MPIDevice::CMD_NEW_CAMERA: {
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new camera \"" << type << "\" ID " << (void*)(int64)handle << endl;
          Camera *camera = Camera::createCamera(type);
          cmd.free(type);
          Assert(camera);
          handle.assign(camera);
          //          cout << "#w: new camera " << handle << endl;
        } break;
        case api::MPIDevice::CMD_NEW_VOLUME: {
          // Assert(type != NULL && "invalid volume type identifier");
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new volume \"" << type << "\" ID " << (void*)(int64)handle << endl;
          Volume *volume = Volume::createInstance(type);
          if (!volume) 
            throw std::runtime_error("unknown volume type '"+std::string(type)+"'");
          volume->refInc();
          cmd.free(type);
          Assert(volume);
          handle.assign(volume);
          //          cout << "#w: new volume " << handle << endl;
        } break;
        case api::MPIDevice::CMD_NEW_TRANSFERFUNCTION: {
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new transfer function \"" << type << "\" ID " << (void*)(int64)handle << endl;
          TransferFunction *transferFunction = TransferFunction::createInstance(type);
          if (!transferFunction) {
            throw std::runtime_error("unknown transfer function type '"+std::string(type)+"'");
          }
          transferFunction->refInc();
          cmd.free(type);
          handle.assign(transferFunction);
        } break;
        case api::MPIDevice::CMD_NEW_MATERIAL: {
          // Assert(type != NULL && "invalid volume type identifier");
          const mpi::Handle rendererHandle = cmd.get_handle();
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new material \"" << type << "\" ID " << (void*)(int64)handle << endl;

          Renderer *renderer = (Renderer *)rendererHandle.lookup();
          Material *material = NULL;
          if (renderer) {
            material = renderer->createMaterial(type);
            if (material) {
              material->refInc();
            }
          }
          if (material == NULL) 
            // no renderer present, or renderer didn't intercept this material.
            material = Material::createMaterial(type);
          
          int myFail = (material == NULL);
          int sumFail = 0;
          rc = MPI_Allreduce(&myFail,&sumFail,1,MPI_INT,MPI_SUM,worker.comm);
          if (sumFail == 0) {
            material->refInc();
            cmd.free(type);
            Assert(material);
            handle.assign(material);
            if (worker.rank == 0) {
              if (logLevel > 2)
                cout << "#w: new material " << handle << " " 
                     << material->toString() << endl;
              MPI_Send(&sumFail,1,MPI_INT,0,0,mpi::app.comm);
            }
          } else { 
            // at least one client could not load/create material ...
            if (material) material->refDec();
            if (worker.rank == 0) {
              if (logLevel > 2)
                cout << "#w: could not create material " << handle << " " 
                     << material->toString() << endl;
              MPI_Send(&sumFail,1,MPI_INT,0,0,mpi::app.comm);
            }
          }
        } break;

        case api::MPIDevice::CMD_NEW_LIGHT: {
          const mpi::Handle rendererHandle = cmd.get_handle();
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new light \"" << type << "\" ID " << (void*)(int64)handle << endl;

          Renderer *renderer = (Renderer *)rendererHandle.lookup();
          Light *light = NULL;
          if (renderer) {
            light = renderer->createLight(type);
            if (light) {
              light->refInc();
            }
          }
          if (light == NULL) 
            // no renderer present, or renderer didn't intercept this light.
            light = Light::createLight(type);

          int myFail = (light == NULL);
          int sumFail = 0;
          rc = MPI_Allreduce(&myFail,&sumFail,1,MPI_INT,MPI_SUM,worker.comm);
          if (sumFail == 0) {
            light->refInc();
            cmd.free(type);
            Assert(light);
            handle.assign(light);
            if (worker.rank == 0) {
              if (logLevel > 2)
                cout << "#w: new light " << handle << " " 
                     << light->toString() << endl;
              MPI_Send(&sumFail,1,MPI_INT,0,0,mpi::app.comm);
            }
          } else { 
            // at least one client could not load/create light ...
            if (light) light->refDec();
            if (worker.rank == 0) {
              if (logLevel > 2)
                cout << "#w: could not create light " << handle << " " 
                     << light->toString() << endl;
              MPI_Send(&sumFail,1,MPI_INT,0,0,mpi::app.comm);
            }
          }
        } break;

        case api::MPIDevice::CMD_NEW_GEOMETRY: {
          // Assert(type != NULL && "invalid volume type identifier");
          const mpi::Handle handle = cmd.get_handle();
          const char *type = cmd.get_charPtr();
          if (worker.rank == 0)
            if (logLevel > 2)
              cout << "creating new geometry \"" << type << "\" ID " << (void*)(int64)handle << endl;
          Geometry *geometry = Geometry::createGeometry(type);
          if (!geometry) 
            throw std::runtime_error("unknown geometry type '"+std::string(type)+"'");
          geometry->refInc();
          cmd.free(type);
          Assert(geometry);
          handle.assign(geometry);
          if (worker.rank == 0)
            if (logLevel > 2)
	      cout << "#w: new geometry " << handle << " " << geometry->toString() << endl;
        } break;

        case api::MPIDevice::CMD_FRAMEBUFFER_CREATE: {
          const mpi::Handle handle = cmd.get_handle();
          const vec2i  size               = cmd.get_vec2i();
          const OSPFrameBufferFormat mode = (OSPFrameBufferFormat)cmd.get_int32();
          const uint32 channelFlags       = cmd.get_int32();
          bool hasDepthBuffer = (channelFlags & OSP_FB_DEPTH);
          bool hasAccumBuffer = (channelFlags & OSP_FB_ACCUM);
          FrameBuffer *fb = new LocalFrameBuffer(size,mode,hasDepthBuffer,hasAccumBuffer);
          handle.assign(fb);
        } break;
        case api::MPIDevice::CMD_FRAMEBUFFER_CLEAR: {
          const mpi::Handle handle = cmd.get_handle();
          const uint32 channelFlags       = cmd.get_int32();
          FrameBuffer *fb = (FrameBuffer*)handle.lookup();
          fb->clear(channelFlags);
        } break;
        case api::MPIDevice::CMD_RENDER_FRAME: {
          const mpi::Handle  fbHandle = cmd.get_handle();
          // const mpi::Handle  swapChainHandle = cmd.get_handle();
          const mpi::Handle  rendererHandle  = cmd.get_handle();
          const uint32 channelFlags          = cmd.get_int32();
          FrameBuffer *fb = (FrameBuffer*)fbHandle.lookup();
          // SwapChain *sc = (SwapChain*)swapChainHandle.lookup();
          // Assert(sc);
          Renderer *renderer = (Renderer*)rendererHandle.lookup();
          Assert(renderer);
          renderer->renderFrame(fb,channelFlags); //sc->getBackBuffer());
          // sc->advance();
        } break;
        case api::MPIDevice::CMD_FRAMEBUFFER_MAP: {
          FATAL("should never get called on worker!?");
          // const mpi::Handle handle = cmd.get_handle();
          // FrameBuffer *fb = (FrameBuffer*)handle.lookup();
          // // SwapChain *sc = (SwapChain*)handle.lookup();
          // // Assert(sc);
          // if (worker.rank == 0) {
          //   // FrameBuffer *fb = sc->getBackBuffer();
          //   void *ptr = (void*)fb->map();
          //   // void *ptr = (void*)sc->map();
          //   rc = MPI_Send(ptr,fb->size.x*fb->size.y,MPI_INT,0,0,mpi::app.comm);
          //   Assert(rc == MPI_SUCCESS);
          //   fb->unmap(ptr);
          // }
        } break;
        case api::MPIDevice::CMD_NEW_MODEL: {
          const mpi::Handle handle = cmd.get_handle();
          Model *model = new Model;
          Assert(model);
          handle.assign(model);
          if (logLevel > 2)
            cout << "#w: new model " << handle << endl;
        } break;
        case api::MPIDevice::CMD_NEW_TRIANGLEMESH: {
          const mpi::Handle handle = cmd.get_handle();
          TriangleMesh *triangleMesh = new TriangleMesh;
          Assert(triangleMesh);
          handle.assign(triangleMesh);
        } break;
        case api::MPIDevice::CMD_NEW_DATA: {
          const mpi::Handle handle = cmd.get_handle();
          Data *data = NULL;
          size_t nitems      = cmd.get_size_t();
          OSPDataType format = (OSPDataType)cmd.get_int32();
          int flags          = cmd.get_int32();
          data = new Data(nitems,format,NULL,flags & ~OSP_DATA_SHARED_BUFFER);
          Assert(data);
          handle.assign(data);

          size_t hasInitData = cmd.get_size_t();
          if (hasInitData) {
            cmd.get_data(nitems*sizeOf(format),data->data);
            if (format==OSP_OBJECT) {
              /* translating handles to managedobject pointers: if a
                 data array has 'object' or 'data' entry types, then
                 what the host sends are _handles_, not pointers, but
                 what the core expects are pointers; to make the core
                 happy we translate all data items back to pointers at
                 this stage */
              mpi::Handle    *asHandle = (mpi::Handle    *)data->data;
              ManagedObject **asObjPtr = (ManagedObject **)data->data;
              for (int i=0;i<nitems;i++) {
                if (asHandle[i] != NULL_HANDLE) {
                  asObjPtr[i] = asHandle[i].lookup();
                  asObjPtr[i]->refInc();
                }
              }
            }
          }
        } break;

        case api::MPIDevice::CMD_NEW_TEXTURE2D: {
          const mpi::Handle handle = cmd.get_handle();
          Texture2D *texture2D = NULL;

          int32 width = cmd.get_int32();
          int32 height = cmd.get_int32();
          int32 type = cmd.get_int32();
          int32 flags = cmd.get_int32();
          size_t size = cmd.get_size_t();
          
          void *data = malloc(size);
          cmd.get_data(size,data);

          texture2D = Texture2D::createTexture(width,height,(OSPDataType)type,data,flags);
          assert(texture2D);
          handle.assign(texture2D);
        } break;

        case api::MPIDevice::CMD_ADD_GEOMETRY: {
          const mpi::Handle modelHandle = cmd.get_handle();
          const mpi::Handle geomHandle = cmd.get_handle();
          Model *model = (Model*)modelHandle.lookup();
          Assert(model);
          Geometry *geom = (Geometry*)geomHandle.lookup();
          Assert(geom);
          model->geometry.push_back(geom);
        } break;

        case api::MPIDevice::CMD_ADD_VOLUME: {
          const mpi::Handle modelHandle = cmd.get_handle();
          const mpi::Handle volumeHandle = cmd.get_handle();
          Model *model = (Model *) modelHandle.lookup();
          Assert(model);
          Volume *volume = (Volume *) volumeHandle.lookup();
          Assert(volume);
          model->volumes.push_back(volume);
        } break;

        case api::MPIDevice::CMD_COMMIT: {
          const mpi::Handle handle = cmd.get_handle();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          // printf("#w%i:c%i obj %lx\n",worker.rank,(int)handle,obj);
          if (logLevel > 2)
            cout << "#w: committing " << handle << " " << obj->toString() << endl;
          obj->commit();

          // hack, to stay compatible with earlier version
          Model *model = dynamic_cast<Model *>(obj);
          if (model)
            model->finalize();
        } break;
        case api::MPIDevice::CMD_SET_OBJECT: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const mpi::Handle val = cmd.get_handle();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->setParam(name,val.lookup());
          cmd.free(name);
        } break;
        case api::MPIDevice::CMD_RELEASE: {
          const mpi::Handle handle = cmd.get_handle();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          handle.freeObject();
        } break;
        case api::MPIDevice::CMD_SET_MATERIAL: {
          const mpi::Handle geoHandle = cmd.get_handle();
          const mpi::Handle matHandle = cmd.get_handle();
          Geometry *geo = (Geometry*)geoHandle.lookup();
          Material *mat = (Material*)matHandle.lookup();
          geo->setMaterial(mat);
        } break;
        case api::MPIDevice::CMD_SET_STRING: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const char *val  = cmd.get_charPtr();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->findParam(name,1)->set(val);
          cmd.free(name);
          cmd.free(val);
        } break;
        case api::MPIDevice::CMD_SET_INT: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const int val = cmd.get_int();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->findParam(name,1)->set(val);
          cmd.free(name);
        } break;
        case api::MPIDevice::CMD_SET_FLOAT: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const float val = cmd.get_float();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->findParam(name,1)->set(val);
          cmd.free(name);
        } break;
        case api::MPIDevice::CMD_SET_VEC3F: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const vec3f val = cmd.get_vec3f();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->findParam(name,1)->set(val);
          cmd.free(name);
        } break;
        case api::MPIDevice::CMD_SET_VEC2F: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const vec2f val = cmd.get_vec2f();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->findParam(name,1)->set(val);
          cmd.free(name);
        } break;
        case api::MPIDevice::CMD_SET_VEC3I: {
          const mpi::Handle handle = cmd.get_handle();
          const char *name = cmd.get_charPtr();
          const vec3i val = cmd.get_vec3i();
          ManagedObject *obj = handle.lookup();
          Assert(obj);
          obj->findParam(name,1)->set(val);
          cmd.free(name);
        } break;
        case api::MPIDevice::CMD_LOAD_MODULE: {
          const char *name = cmd.get_charPtr();

#if THIS_IS_MIC
          // embree automatically puts this into "lib<name>.so" format
          std::string libName = "ospray_module_"+std::string(name)+"_mic";
#else
          std::string libName = "ospray_module_"+std::string(name)+"";
#endif
          loadLibrary(libName);
      
          std::string initSymName = "ospray_init_module_"+std::string(name);
          void*initSym = getSymbol(initSymName);
          if (!initSym)
            throw std::runtime_error("could not find module initializer "+initSymName);
          void (*initMethod)() = (void(*)())initSym;
          initMethod();

          cmd.free(name);
        } break;
        default: 
          std::stringstream err;
          err << "unknown cmd tag " << command;
          throw std::runtime_error(err.str());
        }
      };
    }