status_t BnCrypto::onTransact( uint32_t code, const Parcel &data, Parcel *reply, uint32_t flags) { switch (code) { case INIT_CHECK: { CHECK_INTERFACE(ICrypto, data, reply); reply->writeInt32(initCheck()); return OK; } case IS_CRYPTO_SUPPORTED: { CHECK_INTERFACE(ICrypto, data, reply); uint8_t uuid[16]; data.read(uuid, sizeof(uuid)); reply->writeInt32(isCryptoSchemeSupported(uuid)); return OK; } case CREATE_PLUGIN: { CHECK_INTERFACE(ICrypto, data, reply); uint8_t uuid[16]; data.read(uuid, sizeof(uuid)); size_t opaqueSize = data.readInt32(); void *opaqueData = NULL; if (opaqueSize > 0) { opaqueData = malloc(opaqueSize); data.read(opaqueData, opaqueSize); } reply->writeInt32(createPlugin(uuid, opaqueData, opaqueSize)); if (opaqueData != NULL) { free(opaqueData); opaqueData = NULL; } return OK; } case DESTROY_PLUGIN: { CHECK_INTERFACE(ICrypto, data, reply); reply->writeInt32(destroyPlugin()); return OK; } case REQUIRES_SECURE_COMPONENT: { CHECK_INTERFACE(ICrypto, data, reply); const char *mime = data.readCString(); reply->writeInt32(requiresSecureDecoderComponent(mime)); return OK; } case DECRYPT: { CHECK_INTERFACE(ICrypto, data, reply); bool secure = data.readInt32() != 0; CryptoPlugin::Mode mode = (CryptoPlugin::Mode)data.readInt32(); uint8_t key[16]; data.read(key, sizeof(key)); uint8_t iv[16]; data.read(iv, sizeof(iv)); size_t totalSize = data.readInt32(); sp<IMemory> sharedBuffer = interface_cast<IMemory>(data.readStrongBinder()); int32_t offset = data.readInt32(); int32_t numSubSamples = data.readInt32(); CryptoPlugin::SubSample *subSamples = new CryptoPlugin::SubSample[numSubSamples]; data.read( subSamples, sizeof(CryptoPlugin::SubSample) * numSubSamples); void *secureBufferId, *dstPtr; if (secure) { secureBufferId = reinterpret_cast<void *>(static_cast<uintptr_t>(data.readInt64())); } else { dstPtr = malloc(totalSize); } AString errorDetailMsg; ssize_t result; if (offset + totalSize > sharedBuffer->size()) { result = -EINVAL; } else { result = decrypt( secure, key, iv, mode, sharedBuffer, offset, subSamples, numSubSamples, secure ? secureBufferId : dstPtr, &errorDetailMsg); } reply->writeInt32(result); if (isCryptoError(result)) { reply->writeCString(errorDetailMsg.c_str()); } if (!secure) { if (result >= 0) { CHECK_LE(result, static_cast<ssize_t>(totalSize)); reply->write(dstPtr, result); } free(dstPtr); dstPtr = NULL; } delete[] subSamples; subSamples = NULL; return OK; } case NOTIFY_RESOLUTION: { CHECK_INTERFACE(ICrypto, data, reply); int32_t width = data.readInt32(); int32_t height = data.readInt32(); notifyResolution(width, height); return OK; } case SET_MEDIADRM_SESSION: { CHECK_INTERFACE(IDrm, data, reply); Vector<uint8_t> sessionId; readVector(data, sessionId); reply->writeInt32(setMediaDrmSession(sessionId)); return OK; } default: return BBinder::onTransact(code, data, reply, flags); } }
PRUoutcome::PRUoutcome(xmlpp::TextReader &reader) { initDefaultValues(); if (reader.has_attributes()) { reader.move_to_first_attribute(); do { if (reader.get_name() == "id") name = reader.get_value(); else if (reader.get_name() == "p") probability = atof(reader.get_value().c_str()); } while (reader.move_to_next_attribute()); reader.move_to_element(); } while(reader.read()) { string name = reader.get_name(); if ((reader.get_node_type() == xmlpp::TextReader::EndElement) && (name == "Outcome")) break; if (reader.get_node_type() != xmlpp::TextReader::Element ) continue; if (name == "Quality") { if (reader.has_attributes()) { reader.move_to_first_attribute(); do { if (reader.get_name() == "kind") quality = reader.get_value(); else if (reader.get_name() == "param") qualityParameter = atof(reader.get_value().c_str()); else if (reader.get_name() == "const") qualityConstant = atof(reader.get_value().c_str()); } while (reader.move_to_next_attribute()); reader.move_to_element(); } } else if (name == "Duration") { if (reader.has_attributes()) { reader.move_to_first_attribute(); do { if (reader.get_name() == "kind") duration = reader.get_value(); else if (reader.get_name() == "param") durationParameter = atof(reader.get_value().c_str()); else if (reader.get_name() == "const") durationConstant = atof(reader.get_value().c_str()); } while (reader.move_to_next_attribute()); reader.move_to_element(); } } else if (name == "Observe") { if (reader.has_value()) observable = reader.get_value(); else observable = reader.read_string(); } else if (name == "SVU") { readVector(stateVariableUpdate,reader); } else if (name == "Final") { isFinal = true; if (reader.has_attributes()) { reader.move_to_first_attribute(); do { if (reader.get_name() == "label") finalLabel = reader.get_value(); } while (reader.move_to_next_attribute()); reader.move_to_element(); } } else if (name == "Next") readVector(nextModules,reader,"\n "); else std::cerr << "Unexpected tag " << name << "!" << std::endl; } // while reader.read() } // PRUoutcome(reader)
void property::update(bitstream &stream) { #ifdef TEST_SKIPPING uint32_t cur = stream.position(); property::skip(stream, prop); uint32_t diff1 = stream.position() - cur; stream.seekBackward(diff1); // assert that seeking backwards worked and we have a clean state assert ( cur == stream.position() ); #endif // TEST_SKIPPING switch (prop->getType()) { // Read Integer case sendprop::T_Int: readInt(stream, this); break; // Read Float case sendprop::T_Float: set(readFloat(stream, this)); break; // Read 3D Vector case sendprop::T_Vector: { std::array<float, 3> vec; readVector(vec, stream, this); set(std::move(vec)); } break; // Read 2D case sendprop::T_VectorXY: { std::array<float, 2> vec; readVectorXY(vec, stream, this); set(std::move(vec)); } break; // Read String case sendprop::T_String: { char str[PROPERTY_MAX_STRING_LENGTH + 1]; uint32_t length = readString(str, stream); set(std::string(str, length)); } break; // Read Array case sendprop::T_Array:{ std::vector<property> vec; readArray(vec, stream, prop); set(std::move(vec)); } break; // Read 64 bit Integer case sendprop::T_Int64: readInt64(stream, this); break; default: BOOST_THROW_EXCEPTION( propertyInvalidType() << (EArgT<1, uint32_t>::info(prop->getType())) ); break; } #ifdef TEST_SKIPPING uint32_t diff2 = stream.position() - cur; if (diff2 != diff1) { std::cout << "Skip failed: " << diff1 << " (skip) " << diff2 << " (read) " << std::endl; std::cout << "Type ID: " << prop->getType() << std::endl; exit(0); } #endif // TEST_SKIPPING }
void processMesh(std::string filename) { Assimp::Importer Importer; const aiScene* scene = Importer.ReadFile(filename.c_str(), aiProcess_Triangulate | aiProcess_GenSmoothNormals | aiProcess_FlipUVs | aiProcess_JoinIdenticalVertices | aiProcess_ImproveCacheLocality); if (!scene) { std::cout << "File " << filename << " not found." << std::endl; return; } for (uint32 meshID = 0; meshID < scene->mNumMeshes; ++meshID) { const aiMesh* mesh = scene->mMeshes[meshID]; mesh_header meshHeader = { 0 }; meshHeader.magicNumber = MESH_MAGIC_NUMBER; skeleton_header skelHeader = { 0 }; skelHeader.magicNumber = SKELETON_MAGIC_NUMBER; std::vector<vec3> positions; std::vector<vec2> texCoords; std::vector<vec3> normals; std::vector<vertex_weight> weights; std::vector<uint16> indices; positions.reserve(mesh->mNumVertices); texCoords.reserve(mesh->mNumVertices); normals.reserve(mesh->mNumVertices); weights.reserve(mesh->mNumVertices); indices.reserve(mesh->mNumFaces); meshHeader.vertexCount = mesh->mNumVertices; meshHeader.indexCount = mesh->mNumFaces * 3; for (uint32 i = 0; i < mesh->mNumVertices; i++) { if (mesh->HasPositions()) { meshHeader.hasPositions = true; const aiVector3D& pos = mesh->mVertices[i]; positions.push_back(vec3(pos.x, pos.y, pos.z)); } if (mesh->HasNormals()) { meshHeader.hasNormals = true; const aiVector3D& nor = mesh->mNormals[i]; normals.push_back(vec3(nor.x, nor.y, nor.z)); } if (mesh->HasTextureCoords(0)) { meshHeader.hasTexCoords = true; const aiVector3D& tex = mesh->mTextureCoords[0][i]; texCoords.push_back(vec2(tex.x, tex.y)); } } for (uint32 i = 0; i < mesh->mNumFaces; i++) { const aiFace &face = mesh->mFaces[i]; assert(face.mNumIndices == 3); indices.push_back((uint16)face.mIndices[0]); indices.push_back((uint16)face.mIndices[1]); indices.push_back((uint16)face.mIndices[2]); } if (mesh->HasBones()) { meshHeader.hasSkeleton = true; vertex_weight defaultWeight = { 0 }; weights.resize(mesh->mNumVertices, defaultWeight); std::map<std::string, bone_idx> boneNames; std::vector<bone_info> boneInfos; uint32 numberOfBones = mesh->mNumBones; for (bone_idx boneID = 0; boneID < (bone_idx)numberOfBones; ++boneID) { const aiBone* bone = mesh->mBones[boneID]; std::string boneName = bone->mName.C_Str(); boneNames[boneName] = boneID; bone_info boneInfo; boneInfo.invBindMatrix = readMatrix(bone->mOffsetMatrix); boneInfo.name = boneName; boneInfos.push_back(boneInfo); for (uint32 weightID = 0; weightID < bone->mNumWeights; ++weightID) { uint32 vertexID = bone->mWeights[weightID].mVertexId; float weight = bone->mWeights[weightID].mWeight; vertex_weight& vWeight = weights[vertexID]; // search first unused for (uint32 i = 0; i < 4; ++i) { if (vWeight.weights[i] == 0.f) { vWeight.joints[i] = boneID; vWeight.weights[i] = weight; break; } } } } // normalize weights -> sum up to 1 for (vertex_weight& vWeight : weights) { vec4 tmp(vWeight.weights[0], vWeight.weights[1], vWeight.weights[2], vWeight.weights[3]); normalize(tmp); vWeight.weights[0] = tmp.x; vWeight.weights[1] = tmp.y; vWeight.weights[2] = tmp.z; vWeight.weights[3] = tmp.w; } readSkeleton(scene->mRootNode, boneNames, boneInfos, NO_PARENT); skelHeader.jointCount = (bone_idx)boneInfos.size(); if (scene->HasAnimations()) { for (uint32 animationID = 0; animationID < scene->mNumAnimations; ++animationID) { std::vector<anim_channel> animChannels; const aiAnimation* animation = scene->mAnimations[animationID]; float ticksPerSecond = (float)animation->mTicksPerSecond; float normalizingFactor = (ticksPerSecond == 0.f) ? 1.f : 1.f / ticksPerSecond; bone_idx numberOfAnimatedBones = animation->mNumChannels; for (bone_idx channelID = 0; channelID < numberOfAnimatedBones; ++channelID) { const aiNodeAnim* channel = animation->mChannels[channelID]; std::string boneName = channel->mNodeName.C_Str(); if (boneNames.find(boneName) != boneNames.end()) { bone_idx boneID = boneNames[boneName]; anim_channel animChannel; animChannel.boneID = boneID; // for now assert(channel->mNumPositionKeys == channel->mNumRotationKeys && channel->mNumPositionKeys == channel->mNumScalingKeys); for (uint32 keyID = 0; keyID < channel->mNumPositionKeys; ++keyID) { key_frame keyframe; keyframe.time = (float)channel->mPositionKeys[keyID].mTime * normalizingFactor; keyframe.sqt.position = readVector(channel->mPositionKeys[keyID]); keyframe.sqt.rotation = readQuaternion(channel->mRotationKeys[keyID]); keyframe.sqt.scale = readVector(channel->mScalingKeys[keyID]).x; animChannel.keyframes.push_back(keyframe); } animChannels.push_back(animChannel); } } animation_header animHeader; animHeader.magicNumber = ANIMATION_MAGIC_NUMBER; animHeader.jointCount = (bone_idx)animChannels.size(); animHeader.length = (float)animation->mDuration * normalizingFactor; animHeader.looping = true; animHeader.skeleton = 0; std::sort(animChannels.begin(), animChannels.end(), [](const anim_channel& a, const anim_channel& b) { return a.boneID < b.boneID; }); // output animations std::string animationFileName; if (animation->mName.length == 0) { animationFileName = std::string("../Game/assets/animations/") + getFileName(filename) + ".anim"; } else { animationFileName = std::string("../Game/assets/animations/") + getAnimationFileName(animation->mName.C_Str()) + ".anim"; } outputAnimation(animationFileName, animHeader, animChannels); } } std::string skeletonFileName = std::string("../Game/assets/skeletons/") + getFileName(filename) + ".skeleton"; outputSkeleton(skeletonFileName, skelHeader, boneInfos); } std::string meshFileName = std::string("../Game/assets/models/") + getFileName(filename) + ".mesh"; outputMesh(meshFileName, meshHeader, positions, texCoords, normals, weights, indices); } }
int main(int argc, char* argv[]) { typedef long Int; typedef double Entry; typedef Kokkos::OpenMP Exe_Space; if(argc < 2) { std::cout <<"Inputs nthreads matrix.mtx (optional rhs.mtx)" << std::endl; return -1; } Int nthreads = atoi(argv[1]); std::string mname = std::string(argv[2]); std::string vname; //Load inital information //Matrix Int m, n, nnz; m = n = nnz = 0; Int *col_ptr, *row_idx; Entry *val; readMatrix(mname, m, n, nnz, &col_ptr, &row_idx, &val); //RHS Int vn, vm; vn = vm = 0; Entry *x, *xhat, *y; vn = n; x = new Entry[n](); xhat = new Entry[n](); if(argc == 4) { vname = std::string(argv[3]); readVector(vname, vm, y); } else { vm = m; y = new Entry[m](); for(Int i = 0; i < vm; i++) { y[i] = (Entry) i; } } //Starting up Kokkos Exe_Space::initialize(nthreads); std::cout << "Kokkos Settings" << std::endl; std::cout << "hwloc aval: " << Kokkos::hwloc::available()<< std::endl; std::cout << "numa count: " << Kokkos::hwloc::get_available_numa_count() << std::endl; std::cout << "thrd numa: " << Kokkos::hwloc::get_available_cores_per_numa() << std::endl; //Start Basker { int result = 0; BaskerNS::Basker<Int, Entry, Exe_Space> mybaker; //---Options mybasker.Options.same_pattern = BASKER_FALSE; mybasker.Options.verbose = BASKER_FALSE; mybasker.Options.verbose_matrix_out = BASKER_FALSE; mybasker.Options.realloc = BASKER_TRUE; mybasker.Options.transpose = BASKER_FALSE; mybasker.Options.symmetric = BASKER_FALSE; mybasker.Options.AtA = BASKER_TRUE; mybasker.Options.A_plu_At = BASKER_TRUE; mybasker.Options.matching = BASKER_TRUE; mybasker.Options.matching_type = BASKER_MATCHING_BN; mybasker.Options.btf = BASKER_TRUE; mybasker.Options.btf_max_percent = BASKER_BTF_MAX_PERCENT; mybasker.Options.btf_large = BASKER_BTF_LARGE; mybasker.Options.no_pivot = BASKER_FALSE; //mybasker.Options.pivot_tol = .001; //mybasker.Options.pivot_bias = .001; //mybasker.Options.btf_prune_size = 2; std::cout << "Setting Threads:" << nthreads << std::endl; mybasker.SetThreads(nthreads); mybasker.Symbolic(m,n,nnz,col_ptr,row_idx,val); mybasker.Factor(m,n,nnz,col_ptr,row_idx,val); mybasker.DEBUG_PRINT(); mybasker.Solve(y,x); //mybasker.GetPerm() mybasker.Finalize(); } Kokkos::finalize(); }//end main
void PhysicObject::loadPhysProperties(FILE* f) { enablePhysics(readChar(f)); if (!isEnabledPhysics()) return; setMass(readFloat(f)); setAngularFactor(readVector(f)); setLinearFactor(readVector(f)); //writeVector(getLinearVelocity(), f); setTrigger(readChar(f)); setCollisionShapeType((CollisionShapeType)readChar(f)); setEnableDeactivation(readChar(f)); setFriction(readFloat(f)); setRestitution(readFloat(f)); setLinearDumping(readFloat(f)); setAngularDumping(readFloat(f)); // load custom collision shape if (getCollisionShapeType() == CST_CUSTOM) { switch ((GOCollisionShapeType)readChar(f)) { case GOCST_COMPOUND_SHAPE: setCollisionShape(new GOCompoundCollisionShape(f)); break; case GOCST_BOX: setCollisionShape(new GOBoxCollisionShape(f)); break; case GOCST_SPHERE: setCollisionShape(new GOSphereCollisionShape(f)); break; case GOCST_CYLINDER: setCollisionShape(new GOCylinderCollisionShape(f)); break; case GOCST_UNDEFINED: setCollisionShape(new GOUndefinedCollisionShape(f)); break; case GOCST_CAPSULE: setCollisionShape(new GOCapsuleCollisionShape(f)); break; case GOCST_CONE: setCollisionShape(new GOConeCollisionShape(f)); break; case GOCST_MESH: setCollisionShape(new GOMeshCollisionShape(f)); break; default: Log::error("PhysicObject::loadPhysProperties(FILE* f): Undefined custom shape type."); } } // load constraints int c_count = readChar(f); for (int i = 0; i < c_count; i++) { GOConstraint* cs; unsigned char type = readChar(f); switch (type) { case GO_P2P_CONSTRAINT: cs = new GOP2PConstraint(f); break; case GO_HINGE_CONSTRAINT: cs = new GOHingeConstraint(f); break; case GO_SLIDER_CONSTRAINT: cs = new GOSliderConstraint(f); break; default: Log::error("PhysicObject::loadPhysProperties(FILE* f): Undefined constraint type."); } addConstraint(cs); } }
int main(int argc, char * * argv) { CipherResult cr; unsigned int cIterations; char * pszCipher; Cipher * pCipher; unsigned int cbBlock, cbKey; octet abKey[MAX_KEY_SIZE]; Key * pKey; octet abInit[MAX_BLOCK_SIZE]; octet abVector[MAX_BLOCK_SIZE]; unsigned int i; clock_t t1, t2, t3, t4; float ta, tb; char what, what2; pszProgramName = argv[0]; if (argc < 4) printUsage(1); what = argv[1][0]; if (what != 't' && what != 'v') printUsage(1); pszCipher = argv[2]; pCipher = findCipher(cipherTable, pszCipher, &cbBlock, &cbKey); assert(pCipher); if (what == 't') { if (argc != 4) printUsage(1); cIterations = atoi(argv[3]); printf("%16s-%04d-%04d: ", pCipher->pszID, cbKey * 8, cbBlock * 8); /* Dummy key. */ for (i = 0; i < cbKey; i++) abKey[i] = i; cr = cryptCreateKey(pCipher, cbBlock, cbKey, abKey, &pKey); assert(!cr); /* Initial test vector. */ for (i = 0; i < cbBlock; i++) abInit[i] = i; memcpy(abVector, abInit, cbBlock); /* Encrypt cIterations times. */ t1 = clock(); for (i = cIterations; i; i--) { pKey->pCipher->encryptBlock(pKey, abVector); } t2 = clock(); /* Decrypt cIterations times. */ t3 = clock(); for (i = cIterations; i; i--) { pKey->pCipher->decryptBlock(pKey, abVector); } t4 = clock(); /* Result should match test vector. */ for (i = 0; i < cbBlock; i++) assert(abInit[i] == abVector[i]); ta = (t2 - t1) / (float) CLOCKS_PER_SEC; tb = (t4 - t3) / (float) CLOCKS_PER_SEC; printf("%8.3f %8.3f %8.3f %8.3f\n", ta, /* time for encryption */ tb, /* time for decryption */ /* encryption speed in Mb/s */ (cbBlock * cIterations) / ta / (1024 * 1024), /* decryption speed in Mb/s */ (cbBlock * cIterations) / tb / (1024 * 1024)); } else if (what == 'v') { if (argc != 6) printUsage(1); what2 = argv[3][0]; if (what2 != 'e' && what2 != 'd') printUsage(1); readVector(argv[4], cbKey, abKey); readVector(argv[5], cbBlock, abVector); cr = cryptCreateKey(pCipher, cbBlock, cbKey, abKey, &pKey); assert(!cr); if (what2 == 'e') pKey->pCipher->encryptBlock(pKey, abVector); else pKey->pCipher->decryptBlock(pKey, abVector); for (i = 0; i < cbBlock; i++) printf("%02x", (int) abVector[i]); printf("\n"); } return 0; }