void PollSelect::set(int fd, natural waitFor, const Timeout &tm, void* userData) { if (fd < 0) throw InvalidParamException(THISLOCATION,1,"Invalid descriptor (negative value)"); natural fdindex = (natural)fd; if (fdindex > 1024 && fdindex > socketMap.length() * 4) throw InvalidParamException(THISLOCATION,1,"Invalid descriptor (too high value)"); if (fdindex >= socketMap.length()) { const FdInfo *oldMap = socketMap.data(); socketMap.resize(fdindex+1); FdInfo *newMap = socketMap.data(); if (oldMap != newMap) { //because items was moved to new address, we have to recalculate addresses of timeout map for (natural i = 0; i < timeoutMap.length(); i++) { natural ofs = timeoutMap[i].owner - oldMap; timeoutMap(i).owner = newMap + ofs; } } } FdInfo &fdinfo = socketMap(fdindex); removeOldTm(&fdinfo); fdinfo.timeout = tm; fdinfo.waitFor = waitFor; fdinfo.userData = userData; addNewTm(&fdinfo); if (waitFor == 0) { removeFromPool(fdinfo.poolpos); } else { POLLFD ev; ev.fd = fd; ev.events = (((waitFor & INetworkResource::waitForInput) != 0)?POLL_IN:0) | (((waitFor & INetworkResource::waitForOutput) != 0)?POLL_OUT:0) | (((waitFor & INetworkResource::waitForException) != 0)?POLL_PRI:0) ; ev.revents = 0; if (fdinfo.poolpos ==naturalNull) { fdinfo.poolpos = curpool.length(); curpool.add(ev); } else { curpool(fdinfo.poolpos) = ev; } } }
void AtomSpace_setTruthValue( AtomSpace* this_ptr , UUID handle , TruthValueType type , double* parameters ) { Handle h(handle); if(!h) throw InvalidParamException(TRACE_INFO, "Invalid Handler parameter."); switch(type) { case SIMPLE_TRUTH_VALUE: { double count = SimpleTruthValue::confidenceToCount(parameters[1]); h->setTruthValue(SimpleTruthValue::createTV(parameters[0],count)); break; } case COUNT_TRUTH_VALUE: { h->setTruthValue(CountTruthValue::createTV(parameters[0] ,parameters[2] ,parameters[1])); break; } case INDEFINITE_TRUTH_VALUE: { IndefiniteTruthValuePtr iptr = IndefiniteTruthValue::createITV(parameters[1] ,parameters[2] ,parameters[3]); iptr->setMean(parameters[0]); iptr->setDiff(parameters[4]); h->setTruthValue(std::static_pointer_cast<TruthValue>(iptr)); break; } case FUZZY_TRUTH_VALUE: { double count = FuzzyTruthValue::confidenceToCount(parameters[1]); h->setTruthValue(FuzzyTruthValue::createTV(parameters[0],count)); break; } case PROBABILISTIC_TRUTH_VALUE: { h->setTruthValue(ProbabilisticTruthValue::createTV(parameters[0] ,parameters[2] ,parameters[1])); break; } default: throw InvalidParamException(TRACE_INFO, "Invalid TruthValue Type parameter."); break; } }
UUID AtomSpace_addNode( AtomSpace* this_ptr , const char* type , const char* name ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); return this_ptr->add_node(t,std::string(name)).value(); }
int AtomSpace_getNode( AtomSpace* this_ptr , const char* type , const char* name , UUID* uuid_out ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); Handle h = this_ptr->get_node(t,std::string(name)); *uuid_out = h.value(); return h == Handle::UNDEFINED; }
UUID AtomSpace_addLink( AtomSpace* this_ptr , const char* type , const UUID* outgoing , int size ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); HandleSeq oset; for(int i=0;i<size;i++) oset.push_back(Handle(outgoing[i])); return this_ptr->add_link(t,oset).value(); }
void IHTTPSettings::setProxy(ProxyMode md, ConstStrA addrport) { if (md != pmManual) { setProxy(md,String(),0); } else { TextParser<char, SmallAlloc<1024> > parser; if (parser("%1:%u2",addrport)) { setProxy(md,parser[1].str(),(natural)parser[2]); } else { throw InvalidParamException(THISLOCATION,2,"Proxy address must be in format <domain>:<port>"); } } }
int AtomSpace_getLink( AtomSpace* this_ptr , const char* type , const UUID* outgoing , int size , UUID* uuid_out ) { Type t = classserver().getType(std::string(type)); if(t == NOTYPE) throw InvalidParamException(TRACE_INFO, "Invalid AtomType parameter '%s'.",type); HandleSeq oset; for(int i=0;i<size;i++) oset.push_back(Handle(outgoing[i])); Handle h = this_ptr->get_link(t,oset); *uuid_out = h.value(); return h == Handle::UNDEFINED; }
TruthValueType AtomSpace_getTruthValue( AtomSpace* this_ptr , UUID handle , double* parameters ) { Handle h(handle); if(!h) throw InvalidParamException(TRACE_INFO, "Invalid Handler parameter."); TruthValuePtr tv = h->getTruthValue(); switch(tv->getType()) { case SIMPLE_TRUTH_VALUE: { parameters[0]=tv->getMean(); parameters[1]=tv->getConfidence(); break; } case COUNT_TRUTH_VALUE: { parameters[0]=tv->getMean(); parameters[1]=tv->getCount(); parameters[2]=tv->getConfidence(); break; } case INDEFINITE_TRUTH_VALUE: { IndefiniteTruthValuePtr itv = std::static_pointer_cast<IndefiniteTruthValue>(tv); parameters[0]=itv->getMean(); parameters[1]=itv->getL(); parameters[2]=itv->getU(); parameters[3]=itv->getConfidenceLevel(); parameters[4]=itv->getDiff(); break; } case FUZZY_TRUTH_VALUE: { parameters[0]=tv->getMean(); parameters[1]=tv->getConfidence(); break; } case PROBABILISTIC_TRUTH_VALUE: { parameters[0]=tv->getMean(); parameters[1]=tv->getCount(); parameters[2]=tv->getConfidence(); break; } default: throw RuntimeException(TRACE_INFO, "Invalid TruthValue Type."); break; } return tv->getType(); }
int AtomSpace_getAtomByHandle( AtomSpace* this_ptr , UUID handle , char** type , char** name , UUID** out , int* out_len) { Handle h(handle); if(!h) throw InvalidParamException(TRACE_INFO, "Invalid Handler parameter."); const std::string &str = classserver().getTypeName(h->getType()); (*type) = (char*) malloc(sizeof(char) * (str.length()+1)); if(!(*type)) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*type, str.c_str()); NodePtr ptr = NodeCast(h); if(ptr){//It is a node. const std::string &str = ptr->getName(); (*name) = (char*) malloc(sizeof(char) * (str.length()+1)); if(!(*name)) throw RuntimeException(TRACE_INFO,"Failed malloc."); std::strcpy(*name, str.c_str()); return 1; }else{//It is a link. LinkPtr lnk = LinkCast(h); if(!lnk) throw RuntimeException(TRACE_INFO,"Error in cast Link."); *out_len=lnk->getArity(); (*out) = (UUID*) malloc(sizeof(UUID) * (*out_len)); if(!(*out)) throw RuntimeException(TRACE_INFO,"Failed malloc."); int i; for(i=0;i<(*out_len);i++) (*out)[i]=lnk->getOutgoingAtom(i).value(); return 0; } }
void setValueToRef(Value refVariable, Value newValue) { if (refVariable == nil) throw InvalidParamException(THISLOCATION, 1, "Argument is nil"); if (newValue == nil) throw InvalidParamException(THISLOCATION, 2, "Argument is nil"); BoundVar &bv = refVariable->getIfc<BoundVar>(); bv.setValue(newValue); }