Variant invoke(const ObjectHandle& object, const IDefinitionManager& definitionManager, const ReflectedMethodParameters& parameters) override { auto pointer = reflectedCast<ClassType>(object.data(), object.type(), definitionManager); TF_ASSERT(pointer != nullptr); return invokeMember( pointer, method_, definitionManager, parameters, std::index_sequence_for<Args...>{} ); }
SysStatus SysVMessagesClient::getCallBackOH(ObjectHandle& oh, void*& blockKey) { ProcessID pid; SysStatus rc; pid = DREFGOBJ(TheProcessRef)->getPID(); if (pid != callBackOH.pid()) { /* either we've never initialized or * this is a fork child and we need * a new call back oh. */ ProcessID serverPID; ObjectHandle serverOH; StubSysVMessages::__Get__metaoh(serverOH); passertMsg(!serverOH.invalid(), "No SysVMessages server\n"); serverPID=serverOH.pid(); /* * make oh to this object for async callback */ rc = giveAccessByServer(callBackOH, serverPID); passertMsg(_SUCCESS(rc), "giveAccessByServer failed %ld\n", rc); } oh = callBackOH; blockKey = (void*)obj; return 0; }
/*static*/ SysStatus FileLinuxPacket::CreateInternal(FileLinuxRef& newSocket, ObjectHandle stubOH, uval clientType, uval oflags, sval domain, sval type, sval protocol) { SysStatus rc; FileLinuxPacket *newp = NULL; ObjectHandle dummy; switch (type) { case SOCK_DGRAM: case SOCK_RAW: switch (domain) { case AF_NETLINK: case AF_INET: newp = new FileLinuxPacket(domain, type, protocol); break; case AF_UNIX: newp = (FileLinuxPacket*) new FileLinuxPacketUnix(domain, type, protocol); break; default: tassertMsg(0, "fixme. Add the domain (%ld) here as well.\n", domain); break; } break; default: tassertMsg(0, "fixme. Add the type (%ld) here as well.\n", type); break; } // using dummy tells init not to make a stubHolder dummy.init(); newp->init(dummy, NULL); newp->local = newp->remote = 0; newp->localLen = newp->remoteLen = 0; newp->sps.setOH(stubOH); switch (clientType) { case TransStreamServer::TRANS_VIRT: newp->stubHolder = new TransVirtStream(stubOH); break; case TransStreamServer::TRANS_PPC: newp->stubHolder = new TransPPCStream(stubOH); break; default: err_printf("Unknown socket client type: %ld\n", clientType); } newSocket = (FileLinuxRef)newp->getRef(); // register object for callback by server rc = newp->registerCallback(); tassert(_SUCCESS(rc), err_printf("do cleanup code\n")); return 0; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double *i_oesgp_object; i_oesgp_object = mxGetPr(prhs[0]); VectorXd prediction; VectorXd prediction_variance; ObjectHandle<OESGP>* handle = ObjectHandle<OESGP>::from_mex_handle(prhs[0]); handle->get_object().predict(prediction, prediction_variance); if (nlhs >= 1) { plhs[0] = mxCreateDoubleMatrix(prediction.rows(), 1, mxREAL); double *output = mxGetPr(plhs[0]); for (unsigned int i=0; i<prediction.rows(); i++) { output[i] = prediction[i]; } } if (nlhs >= 2) { plhs[1] = mxCreateDoubleMatrix(prediction_variance.rows(), 1, mxREAL); double *output = mxGetPr(plhs[1]); for (unsigned int i=0; i<prediction_variance.rows(); i++) { output[i] = prediction_variance[i]; } } }
int main() { NativeProcess(); SysStatus rc; ObjectHandle oh; UsrTstRef ref = UsrTst::Create(); rc = DREF(ref)->giveAccessByServer(oh, _KERNEL_PID); tassert(_SUCCESS(rc), err_printf("woops\n")); printf("testDisabledIPC: calling kernel with oh %lx %lx\n", oh.commID(), oh.xhandle()); Scheduler::Disable(); ALLOW_PRIMITIVE_PPC(); DREFGOBJ(TheProcessRef)->testUserIPC(oh); UN_ALLOW_PRIMITIVE_PPC(); Scheduler::Enable(); printf("testDisabledIPC: done calling kernel\n"); for (uval i = 0; i < 20; i++) { printf("testDisabledIPC: sleeping (%ld)\n", i); Scheduler::DelayMicrosecs(5000); } printf("testDisabledIPC: terminating\n"); return 0; }
RECEIVE(DROP, id, msg, reliable) { ObjectHandle item = Object::construct((string) msg[1]); if (!item) return; item->unserialize(msg[1]); game.world->temporary.push_back(item); }
ReflectedMethodParameterWrapper( const Variant& variant, const IDefinitionManager & definitionManager ) { ObjectHandle handle; value = variant.tryCast<ObjectHandle>( handle ) ? *reflectedCast< Type >(handle.data(), handle.type(), definitionManager ) : variant.cast<Type>(); }
//============================================================================== ObjectHandle SetReflectedPropertyCommand::execute( const ObjectHandle & arguments ) const { ReflectedPropertyCommandArgument * commandArgs = arguments.getBase< ReflectedPropertyCommandArgument >(); auto objManager = definitionManager_.getObjectManager(); assert( objManager != nullptr ); ObjectHandle object = objManager->getObject( commandArgs->getContextId() ); if (!object.isValid()) { return CommandErrorCode::INVALID_ARGUMENTS; } PropertyAccessor property = object.getDefinition( definitionManager_ )->bindProperty( commandArgs->getPropertyPath(), object ); if (property.isValid() == false) { //Can't set return CommandErrorCode::INVALID_ARGUMENTS; } const Variant & data = commandArgs->getPropertyValue(); bool br = property.setValue( data ); if (!br) { return CommandErrorCode::INVALID_VALUE; } // Do not return the object // CommandInstance will hold a reference to the return value // and the CommandInstance is stored in the undo/redo history forever // This is due to a circular reference in CommandManagerImpl::pushFrame return nullptr; }
OSPModel MPIDistributedDevice::newModel() { auto *instance = new DistributedModel; ObjectHandle handle; handle.assign(instance); return (OSPModel)(int64)handle; }
// create a server file object to represent this block file /* virtual */ SysStatus FileSystemK42RamFS::createServerFileBlock(ServerFileRef &fref, FSFile *fsFile) { ObjectHandle oh; SysStatus rc = DREF(tref)->getKptoh(oh); tassertMsg(_SUCCESS(rc) && oh.valid(), "?"); return ServerFileBlockK42RamFS::Create(fref, fsFile, oh); }
inline API_TYPE createDistributedObject(const char *type) { auto *instance = OSPRAY_TYPE::createInstance(type); ObjectHandle handle; handle.assign(instance); return (API_TYPE)(int64)handle; }
OSPFrameBuffer MPIDistributedDevice::frameBufferCreate(const vec2i &size, const OSPFrameBufferFormat mode, const uint32 channels) { ObjectHandle handle; auto *instance = new DistributedFrameBuffer(size, handle, mode, channels, true); handle.assign(instance); return (OSPFrameBuffer)(int64)handle; }
RECEIVE(BUILD, id, msg, reliable) { if (!reliable) return; GridPoint g = ToGridPoint(msg[1]); if (!g.isValid()) return; ObjectHandle structure = Object::construct((string) msg[2]); if (!structure) return; structure->unserialize(msg[2]); game.world->terrain->structures[g] = structure; TO(Structure,structure)->updateTextures(); }
RECEIVE(ITEMINFO, id, msg, reliable) { if (!reliable) return; game.world->temporary.clear(); for (size_t i = 1; i < msg.size(); ++i) { ObjectHandle item = Object::construct((string) msg[i]); if (!item) continue; item->unserialize(msg[i]); game.world->temporary.push_back(item); } }
int MemoryManager::garbageCollect() { register int j; int c=1,f=0; if(noGC) return 0; if (debugging) fprintf(stderr,"\ngarbage collecting ... \n"); for(TObjectTableIterator x = objectTable.begin(), xend = objectTable.end(); x != xend; ++x) x->referenceCount = 0; objectTable[0].referenceCount = 1; /* visit symbols and firstProcess to toggle their referenceCount */ visit(symbols); /* Visit any explicitly held references from the use of ObjectHandle */ ObjectHandle* explicitRef = ObjectHandle::getListHead(); while(explicitRef) { visit(*explicitRef); explicitRef = explicitRef->next(); } /* add new garbage to objectFreeList * toggle referenceCount * count the objects */ for (j=objectTable.size()-1; j>0; j--) { if (objectTable[j].referenceCount == 0) { if(destroyObject(j)) f++; } else { if (0!=(objectTable[j].referenceCount = -objectTable[j].referenceCount)) c++; } } if (debugging) { fprintf(stderr," %d references.\n",ObjectHandle::numTotalHandles()); fprintf(stderr," %d objects - %d freed.\n",c,f); } return f; }
ReflectedMethodParameterWrapper(const Variant& variant, const IDefinitionManager& definitionManager) { if (variant.canCast<ObjectHandle>()) { ObjectHandle handle = variant.cast<ObjectHandle>(); pointer_ = reflectedCast<Type>(handle.data(), handle.type(), definitionManager); } else { pointer_ = &const_cast<Variant&>(variant).cast<Type&>(); } }
/* static */ SysStatus RegionReplicated::_CreateFixedLenExtDyn(uval& regionVaddr, uval regionSize, uval alignmentreq, ObjectHandle frOH, uval fileOffset, uval accessreq, XHandle target, ObjectHandle tsOH, RegionType::Type regionType, __CALLER_PID callerPID) { RegionRef ref; ProcessRef pref=0; SysStatus rc; FCMRef fcmRef; TypeID type; ObjRef objRef; FRRef frRef; rc = RegionDefault::PrefFromTarget(target, callerPID, pref); _IF_FAILURE_RET(rc); rc = XHandleTrans::XHToInternal(frOH.xhandle(), callerPID, MetaObj::attach, objRef, type); tassertWrn(_SUCCESS(rc), "RegionReplicated failed XHToInternal\n"); _IF_FAILURE_RET(rc); // verify that type is of FRComp - we'd really like just FR // FIXMEXX talk to Orran, the brilliant, charming, .. if (!MetaFR::isBaseOf(type)) { tassertWrn(0, "object handle <%lx,%lx> not of correct type\n", frOH.commID(), frOH.xhandle()); return _SERROR(1542, 0, EINVAL); } //FIXME check xobj to make sure it matches our processID frRef = (FRRef)objRef; rc = RegionReplicated::CreateFixedLen( ref, pref, regionVaddr, regionSize, alignmentreq, frRef, fileOffset, (AccessMode::mode)accessreq); // FIXME: Kludge for enabling dyn-switch #if 0 CObjRoot *partitionedFCMRoot = 0; rc = FCMPartitionedTrivial::Create(partitionedFCMRoot, fcmRef, regionSize, /* number of cache lines per rep */ 256, /* associativity of each line */ 4); tassert(_SUCCESS(rc), err_printf("Replicated Trivial fcm create\n")); PMRef pmRef; rc = DREF(pref)->getPM(pmRef); tassert(_SUCCESS(rc), ;);
/* findClass gets a class object, either by finding it already or making it in addition, it makes sure it has a size, by setting the size to zero if it is nil. */ static ObjectHandle findClass(const char* name) { ObjectHandle newObj; newObj = globalSymbol(name); if (newObj == nilobj) { newObj = createAndRegisterNewClass(name); } if (newObj->basicAt(sizeInClass) == nilobj) { newObj->basicAtPut(sizeInClass, newInteger(0)); } return newObj; }
StreamServer::ClientData::ClientData() : stub(StubObj::UNINITIALIZED), blocked(~0ULL) { ici.bytesLeft = 0; ici.ioLen = 0; ici.bufLen = 0; // start out with invalid to avoid race condition until // client has initialized object for upcall available.state = FileLinux::INVALID; mtr = NULL; ObjectHandle oh; oh.initWithCommID((uval)-1,(uval)-1); stub.setOH(oh); }
static bool ReflectionWalkPointer(ReflectionContext* context) { void* address = context->elementAddress; const Field* field = context->field; #ifdef ENABLE_MEMORY_SHARED_PTR if(FieldIsSharedPointer(field)) { std::shared_ptr<Object>* shared = (std::shared_ptr<Object>*) address; address = shared->get(); } else #endif if(FieldIsRefPointer(field)) { RefPtr<Object>* ref = (RefPtr<Object>*) address; address = ref->get(); } else if(FieldIsRawPointer(field)) { address = context->elementAddress; address = *(Object**) address; } else if(FieldIsHandle(field)) { typedef Handle<Object, NullResolve, NullDestroy> ObjectHandle; ObjectHandle* handle = (ObjectHandle*) address; HandleId id = handle->getId(); Class* klass = (Class*) field->type; ReflectionHandleContext hc; if( !ReflectionFindHandleContext(context->handleContextMap, klass, hc) ) { LogDebug("No handle context found for class '%s'", klass->name); return false; } address = (Object*) HandleFind(hc.handles, id); if( !address ) return false; } context->elementAddress = address; context->object = (Object*) context->elementAddress; return true; }
//------------------------------------------------------------------------------ ObjectHandle reflectedCast(const ObjectHandle& other, const TypeId& typeIdDest, const IDefinitionManager& definitionManager) { std::shared_ptr<IObjectHandleStorage> storage = std::make_shared<ObjectHandleStorageReflectedCast>(other.storage(), typeIdDest, definitionManager); return ObjectHandle(storage); }
RECEIVE(PLAYERINFO, id, msg, reliable) { if (!reliable) return; for (size_t i = 1; i < msg.size(); i += 2) { ObjectHandle player = Player(); player->unserialize((string) msg[i+1]); Player *p = TO(Player,player); Player::Id pid = p->id; game.topId = MAX(game.topId,pid) + 1; game.root->children.insert(player); game.players[pid] = player; nodes[(long) msg[i]] = pid; p->updateTextures(); } }
//============================================================================== std::string RPURU::resolveContextObjectPropertyPath(const ObjectHandle& contextObject, const char* propertyPath, IDefinitionManager& definitionManager) { assert(contextObject != nullptr); const auto classDef = contextObject.getDefinition(definitionManager); assert(classDef != nullptr); std::string tmp = propertyPath; std::vector<std::string> paths; paths.push_back(tmp); char* pch; pch = strtok(const_cast<char*>(tmp.c_str()), "."); if (pch != NULL) { pch = strtok(NULL, "."); while (pch != NULL) { paths.push_back(pch); pch = strtok(NULL, "."); } } PropertyAccessor pa; for (auto& path : paths) { resolveProperty(contextObject, *classDef, path.c_str(), pa, definitionManager); if (pa.isValid()) { break; } } return pa.getFullPath(); }
ObjectHandle MoveItemDataCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */ { auto handle = GenericObject::create(*get<IDefinitionManager>()); assert(handle.get() != nullptr); auto& genericObject = (*handle); if (!arguments.isValid()) { genericObject.set("Name", "Invalid"); genericObject.set("Type", "Move"); return ObjectHandle(std::move(handle)); } auto pCommandArgs = arguments.getBase<MoveItemDataCommandArgument>(); if (!MoveItemDataCommand_Detail::isValid(pCommandArgs)) { genericObject.set("Name", "Invalid"); genericObject.set("Type", "Move"); return ObjectHandle(std::move(handle)); } genericObject.set("Name", "Move"); genericObject.set("Type", "Move"); return ObjectHandle(std::move(handle)); }
ObjectHandle SetItemDataCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */ { auto handle = GenericObject::create(*definitionManager_); assert(handle.get() != nullptr); auto& genericObject = (*handle); if (!arguments.isValid()) { genericObject.set("Name", "Invalid"); genericObject.set("Type", "Data"); return ObjectHandle(std::move(handle)); } auto pCommandArgs = arguments.getBase<SetItemDataCommandArgument>(); if (!SetItemDataCommand_Detail::isValid(pCommandArgs)) { genericObject.set("Name", "Invalid"); genericObject.set("Type", "Data"); return ObjectHandle(std::move(handle)); } genericObject.set("Name", "Data"); genericObject.set("Type", "Data"); const auto& oldValue = (pCommandArgs->oldValue_); const auto& newValue = (pCommandArgs->newValue_); genericObject.set("PreValue", oldValue); genericObject.set("PostValue", newValue); return ObjectHandle(std::move(handle)); }
ObjectHandle InsertItemCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */ { auto handle = GenericObject::create(*definitionManager_); assert(handle.get() != nullptr); auto& genericObject = (*handle); if (!arguments.isValid()) { genericObject.set("Name", "Invalid"); genericObject.set("Type", "Insert"); return ObjectHandle(std::move(handle)); } auto pCommandArgs = arguments.getBase<InsertItemCommandArgument>(); if (!InsertItemCommand_Detail::isValid(pCommandArgs)) { genericObject.set("Name", "Invalid"); genericObject.set("Type", "Insert"); return ObjectHandle(std::move(handle)); } genericObject.set("Id", pCommandArgs->key_); genericObject.set("Name", "Insert"); genericObject.set("Type", "Insert"); genericObject.set("PostValue", pCommandArgs->value_); return ObjectHandle(std::move(handle)); }
bool MoveItemDataCommand::redo(const ObjectHandle& arguments) const /* override */ { if (!arguments.isValid()) { return false; } auto pCommandArgs = arguments.getBase<MoveItemDataCommandArgument>(); if (!MoveItemDataCommand_Detail::isValid(pCommandArgs)) { return false; } const auto& dir = (pCommandArgs->direction_); auto& model = (*pCommandArgs->pModel_); const auto& startPos = (pCommandArgs->startPos_); const auto& endPos = (pCommandArgs->endPos_); const auto& count = (pCommandArgs->count_); const auto& startParent = (pCommandArgs->startParent_); const auto& endParent = (pCommandArgs->endParent_); if (dir == MoveItemDataCommandArgument::Direction::ROW) { return model.moveRows(startParent, startPos, count, endParent, endPos); } return false; }
void init_constants(ObjectHandle exports) { Handle<Object> constants = Object::New(); exports->Set(String::NewSymbol("constants"), constants); DEFINE_CONSTANT(constants, DBUS_BUS_SESSION); DEFINE_CONSTANT(constants, DBUS_BUS_SYSTEM); DEFINE_CONSTANT(constants, DBUS_BUS_STARTER); DEFINE_CONSTANT(constants, DBUS_WATCH_READABLE); DEFINE_CONSTANT(constants, DBUS_WATCH_WRITABLE); DEFINE_CONSTANT(constants, DBUS_WATCH_ERROR); DEFINE_CONSTANT(constants, DBUS_WATCH_HANGUP); DEFINE_CONSTANT(constants, DBUS_MESSAGE_TYPE_INVALID); DEFINE_CONSTANT(constants, DBUS_MESSAGE_TYPE_METHOD_CALL); DEFINE_CONSTANT(constants, DBUS_MESSAGE_TYPE_METHOD_RETURN); DEFINE_CONSTANT(constants, DBUS_MESSAGE_TYPE_ERROR); DEFINE_CONSTANT(constants, DBUS_MESSAGE_TYPE_SIGNAL); DEFINE_CONSTANT(constants, DBUS_SERVICE_DBUS); DEFINE_CONSTANT(constants, DBUS_PATH_DBUS); DEFINE_CONSTANT(constants, DBUS_INTERFACE_DBUS); DEFINE_CONSTANT(constants, DBUS_INTERFACE_INTROSPECTABLE); DEFINE_CONSTANT(constants, DBUS_INTERFACE_PROPERTIES); DEFINE_CONSTANT(constants, DBUS_INTERFACE_PEER); DEFINE_CONSTANT(constants, DBUS_DISPATCH_DATA_REMAINS); DEFINE_CONSTANT(constants, DBUS_DISPATCH_COMPLETE); DEFINE_CONSTANT(constants, DBUS_DISPATCH_NEED_MEMORY); }
CommandDescription RemoveItemCommand::getCommandDescription(const ObjectHandle& arguments) const /* override */ { auto object = GenericObject::create(); if (!arguments.isValid()) { object->set("Name", "Invalid"); object->set("Type", "Remove"); } else { auto pCommandArgs = arguments.getBase<RemoveItemCommandArgument>(); if (!RemoveItemCommand_Detail::isValid(pCommandArgs)) { object->set("Name", "Invalid"); object->set("Type", "Remove"); } else { object->set("Id", pCommandArgs->key_); object->set("Name", "Remove"); object->set("Type", "Remove"); object->set("PreValue", pCommandArgs->value_); } } return std::move(object); }
int __k42_linux_msgrcv(int msqid, struct msgbuf *msgp, int msgsz, sval msgtyp, int msgflg) { int ret; SysStatus rc; ObjectHandle oh; void *blockKey; BlockedThreadQueues::Element qe; SYSCALL_ENTER(); if (msgflg&IPC_NOWAIT) { oh.init(); } else { SysVMessagesClient::GetCallBackOH(oh, blockKey); DREFGOBJ(TheBlockedThreadQueuesRef)-> addCurThreadToQueue(&qe, blockKey); } while (1) { rc = StubSysVMessages::Msgrcv(msqid, msgtyp, msgp->mtext, msgsz, msgflg, oh); if (_FAILURE(rc)) { ret = -_SGENCD(rc); } else { ret = (int)_SGETUVAL(rc); } if ((ret == -ENOMSG) & !(msgflg&IPC_NOWAIT)) { SYSCALL_BLOCK(); if (SYSCALL_SIGNALS_PENDING()) { // need to do removeCur.. on the way out, so don't just return ret = -EINTR; break; } } else break; } if(!(msgflg&IPC_NOWAIT)) { DREFGOBJ(TheBlockedThreadQueuesRef)-> removeCurThreadFromQueue(&qe, blockKey); } SYSCALL_EXIT(); return ret; }