Example #1
0
void WMessageResources::refresh()
{
  defaults_.clear();
  readResourceFile("", defaults_);

  local_.clear();
  std::string locale = wApp->locale();

  for(;;) {
    if (readResourceFile(locale, local_))
      break;

    /* try a lesser specified variant */
    std::string::size_type l = locale.rfind('-');
    if (l != std::string::npos)
      locale.erase(l);
    else
      break;
  }

  loaded_ = true;
}
Example #2
0
int
main(int argc, char **argv)
{
    static char	namebuf[1024];	/* space for tuple */
    static char	namebuf2[1024];	/* space for tuple */
    BUNDLE_AGENT	ba;
    BUNDLE_SPEC	bs;
    BUNDLE_TUPLE	tuple = { { 0, namebuf} , 0 };
    BUNDLE_TUPLE	dst = { { 0, namebuf2}, 0};
    BUNDLE_WAITING	bw;
    BUNDLE_ITERATOR iterator = BUNDLE_ITERATOR_NONE  ;
    uint32_t	reg_cookie = BUNDLE_REG_COOKIE_NONE;

    //
    // Read any defaults of out $HOME/.snd_bundlerc
    //
    readResourceFile();

    //
    // Read off the command arguments
    //
    readCommandLineArgs(argc, argv);

    if ( debug>4 ) {
        writeDefaultsFile(1); // Write to stderr
    }

    //
    // Sanity check parameters
    //
    if ( theSource==0 ) {
        usage("snd_bundle", "-s option is required.");
        exit(EXIT_FAILURE);
    }

    if ( (theSource==2 || theSource==3) && (strlen(fname)==0) ) {
        usage("snd_bundle", "");
        fprintf(stderr, "theSource (%d) specifies sending from file\n", theSource);
        fprintf(stderr, "but no [-f file_name] option given.\n");
        exit(EXIT_FAILURE);
    }

    //
    // Open connection to bundle agent.
    //
    if ( debug>0 ) {
        printf("SND BUNDLE:  ***opening bundle agent on host %s\n", bahost);
    }
    if ((ba = open_agent(bahost)) == NULL) {
        fprintf(stderr, "couldn't contact bundle daemon on %s\n", bahost);
        exit(1);
    }
    if ( debug>1 ) {
        printf("    Bundle agent on host %s open.\n", bahost);
    }

    //
    // Local tuple
    //
    if ( debug>0 ) {
        printf("snd_bundle: building local tuple with localstuff: '%s'\n",
               localstuff);
    }
    //
    // If the user specified a source region and source admin part, use those,
    // otherwise call local_tuple which will use one of our regions (the first
    // it finds in the config file) and our hostname.
    //
    if ( strlen(sourceIntf)>0 ) {
        if ( local_tuple(ba, sourceIntf, localstuff, &tuple) < 0 ) {
            fprintf(stderr, "trouble building local tuple with source (%s, %s)\n",
                    sourceIntf, localstuff);
            exit(EXIT_FAILURE);
        }
    } else {
        if (local_tuple(ba, NULL, localstuff, &tuple) < 0) {
            fprintf(stderr, "trouble building tuple with local stuff %s\n", localstuff);
            exit(EXIT_FAILURE);
        }
    }
    if ( debug>0 ) {
        print_tuple(tuple);
    }


    //
    // Destination tuple
    //
    if ( debug>0 ) {
        printf("snd_bundle: building destination tuple: (%s)\n",
               destTuple);
    }
    if (remote_tuple(destTuple, &dst) < 0) {
        fprintf(stderr, "trouble building destination tuple\n");
        exit(1);
    }
    if ( debug>0 ) {
        print_tuple(dst);
    }

    // Register the local tuple (dest demux string of inbound bundles)
    // in expectation of receiving responses to what we're going to
    // send.
    if ( pollForResponse ) {
        if ( debug>0 ) printf("registering tuple...");
        if (demux_register(ba, tuple, BUNDLE_REG_ABORT, &reg_cookie) < 0) {
            fprintf(stderr, "trouble registering tuple\n");
            exit(1);
        }
        if ( debug>1 ) printf("ok, cookie was 0x%x\n", reg_cookie);
    }

    while ( timesToLoop-->0 ) {
        //
        // Send a bundle from memory
        //
        if ( theSource==1 || theSource==3 ) {
            if ( debug>0 ) {
                printf("sending bundle from memory...\n");
            }
            /* build a bundle spec */
            if (bundle_spec(COS_NORMAL, COS_NONE, tuple, dst, tuple, expire, &bs) < 0) {
                fprintf(stderr, "trouble building bundle_spec\n");
                exit(1);
            }
            /* send the bundle with the spec */
            if (send_bundle_mem(ba, bs, bundle_data, strlen(bundle_data)) < 0) {
                fprintf(stderr, "trouble sending bundle from memory\n");
                exit(1);
            }
        }

        //
        // Send a bundle from a file
        //
        if ( theSource==2 || theSource==3 ) {
            if ( debug>0 ) {
                printf("sending bundle from file...\n");
            }
            if (bundle_spec(COS_NORMAL, COS_NONE, tuple, dst, tuple, expire, &bs) < 0) {
                fprintf(stderr, "trouble building bundle_spec\n");
                exit(EXIT_FAILURE);
            }
            if (send_bundle_file(ba, bs, fname) < 0) {
                fprintf(stderr, "trouble sending bundle from file '%s'\n", fname);
                exit(EXIT_FAILURE);
            }
        }
    }

    //
    // If we were looking for a response, here's how to poll
    //
    if ( pollForResponse ) {
        if ( debug>0 ) printf("Sleeping for a bit...\n");
        sleep(15);
        if ( debug>0 ) {
            printf("polling for tuple:\n");
            print_tuple(tuple);
        }

        while (bundle_poll(ba, tuple, &iterator, &bw) == BUNDLE_SUCCESS) {
            printf("yup, got a bundle at %s\n", bw.filename.filename_val);
            printf("with bundle spec:\n");
            print_bundle_spec(bw.bs);
        }
        printf("no more incoming bundles...\n");
        printf("unregistering tuple...\n");
        if (demux_register_cancel(ba, reg_cookie) < 0) {
            fprintf(stderr, "trouble unregistering tuple\n");
            exit(1);
        }
    }

    if ( debug>0 ) {
        printf("\n***all done (success)\n");
    }
    close_agent(ba);

    if ( writeResourceFile ) {
        writeDefaultsFile(0);
    }
    exit(0);
}
Example #3
0
// All threads start execution here.
int main()
{
	if (__builtin_nyuzi_read_control_reg(0) != 0)
		workerThread();
	
	// Set up resource data
	char *resourceData = readResourceFile();
	const FileHeader *resourceHeader = (FileHeader*) resourceData;
	const TextureEntry *texHeader = (TextureEntry*)(resourceData + sizeof(FileHeader));
	const MeshEntry *meshHeader = (MeshEntry*)(resourceData + sizeof(FileHeader) + resourceHeader->numTextures
		* sizeof(TextureEntry));
	Texture **textures = new Texture*[resourceHeader->numTextures];

	printf("%d textures %d meshes\n", resourceHeader->numTextures, resourceHeader->numMeshes);

	// Create texture objects
	for (unsigned int textureIndex = 0; textureIndex < resourceHeader->numTextures; textureIndex++)
	{
#if TEST_TEXTURE
		textures[textureIndex] = createCheckerboardTexture();
#else
		textures[textureIndex] = new Texture();
		textures[textureIndex]->enableBilinearFiltering(true);
		int offset = texHeader[textureIndex].offset;
		for (unsigned int mipLevel = 0; mipLevel < texHeader[textureIndex].mipLevels; mipLevel++)
		{
			int width = texHeader[textureIndex].width >> mipLevel;
			int height = texHeader[textureIndex].height >> mipLevel;
			Surface *surface = new Surface(width, height, resourceData + offset);
			textures[textureIndex]->setMipSurface(mipLevel, surface);
			offset += width * height * 4;
		}
#endif
	}
	
	// Create Render Buffers
	RenderBuffer *vertexBuffers = new RenderBuffer[resourceHeader->numMeshes];
	RenderBuffer *indexBuffers = new RenderBuffer[resourceHeader->numMeshes];
	for (unsigned int meshIndex = 0; meshIndex < resourceHeader->numMeshes; meshIndex++)
	{
		const MeshEntry &entry = meshHeader[meshIndex];
		vertexBuffers[meshIndex].setData(resourceData + entry.offset, 
			entry.numVertices, sizeof(float) * kAttrsPerVertex);
		indexBuffers[meshIndex].setData(resourceData + entry.offset + entry.numVertices 
			* kAttrsPerVertex * sizeof(float), entry.numIndices, sizeof(int));
	}

	// Set up render state
	RenderContext *context = new RenderContext(0x1000000);
	RenderTarget *renderTarget = new RenderTarget();
	Surface *colorBuffer = new Surface(FB_WIDTH, FB_HEIGHT, (void*) 0x200000);
	Surface *depthBuffer = new Surface(FB_WIDTH, FB_HEIGHT);
	renderTarget->setColorBuffer(colorBuffer);
	renderTarget->setDepthBuffer(depthBuffer);
	context->bindTarget(renderTarget);
	context->enableDepthBuffer(true);
#if SHOW_DEPTH
	context->bindShader(new DepthShader());
#else
	context->bindShader(new TextureShader());
#endif
	context->setClearColor(0.52, 0.80, 0.98);

	Matrix projectionMatrix = Matrix::getProjectionMatrix(FB_WIDTH, FB_HEIGHT);

	TextureUniforms uniforms;
	uniforms.fLightDirection = Vec3(-1, -0.5, 1).normalized();
	uniforms.fDirectional = 0.5f;		
	uniforms.fAmbient = 0.4f;
	float theta = 0.0;

	startAllThreads();

	for (int frame = 0; ; frame++)
	{
		Matrix modelViewMatrix = Matrix::lookAt(Vec3(cos(theta) * 6, 3, sin(theta) * 6), Vec3(0, 3.1, 0), 
			Vec3(0, 1, 0));
		theta = theta + M_PI / 8;
		if (theta > M_PI * 2)
			theta -= M_PI * 2;
		
		uniforms.fMVPMatrix = projectionMatrix * modelViewMatrix;
		uniforms.fNormalMatrix = modelViewMatrix.upper3x3();
		
		context->clearColorBuffer();
		for (unsigned int meshIndex = 0; meshIndex < resourceHeader->numMeshes; meshIndex++)
		{
			const MeshEntry &entry = meshHeader[meshIndex];
			if (entry.textureId != 0xffffffff)
			{
				assert(entry.textureId < resourceHeader->numTextures);
				context->bindTexture(0, textures[entry.textureId]);
				uniforms.fHasTexture = true;
			}
			else
				uniforms.fHasTexture = false;
			
			context->bindUniforms(&uniforms, sizeof(uniforms));
			context->bindVertexAttrs(&vertexBuffers[meshIndex]);
			context->drawElements(&indexBuffers[meshIndex]);
		}

		int startInstructions = __builtin_nyuzi_read_control_reg(6);
		context->finish();
		printf("rendered frame in %d instructions\n", __builtin_nyuzi_read_control_reg(6) 
			- startInstructions);
	}
	
	return 0;
}
Example #4
0
int
main(int argc, char** argv)
{
	static char	namebuf[1024];	/* space for tuple */
	BUNDLE_AGENT	ba;
	BUNDLE_TUPLE	tuple = { { 0, namebuf} , 0 };
	BUNDLE_WAITING	bw;
	int first_time = 1;

	int 		c, ret;
        int 		received_bundle_count = 0;


	//
	// Read any defaults of out $HOME/.polling_rcvrrc
	// 
	readResourceFile();

	//
	// Read off the command arguments
	//
	readCommandLineArgs(argc, argv);

	if ( debug>4 ) {
	  writeDefaultsFile(1); // Write to stderr
	}

	//
	// Sanity check arguments
	//
	if ( strlen(bahost)==0 ) {
	  usage("polling_rcvr", "bundleAgent required");
	  exit(-1);
	}
	if ( strlen(demuxString)==0 ) {
	  usage("polling_rcvr", "demuxString required.\n");
	  exit(-1);
	}

	//
	// Open connection to bundle agent.
	//
	if ( debug>0) {
	  printf("polling_rcvr: ***opening bundle agent on host %s\n", bahost);
	}
	if ((ba = open_agent(bahost)) == NULL) {
		fprintf(stderr, "couldn't contact bundle daemon on %s\n", bahost);
		exit(1);
	}
	if ( debug>1 ) {
	  printf("    Bundle agent open.\n");
	}

	/* API doesn't do mem alloc for us; we must do it */
	if ( strlen(matchstr)>0 ) {
	  	if ( debug>0 ) printf("creating local tuple with name...\n");
		if (local_tuple(ba, matchstr, localstuff, &tuple) < 0) {
			fprintf(stderr, "trouble building tuple with source matchstr %s\n",
					matchstr);
			exit(1);
	        }
	} else {
	        if ( debug>0 ) printf("creating local tuple...\n");
		if (local_tuple(ba, NULL, localstuff, &tuple) < 0) {
			fprintf(stderr, "trouble building tuple with localstuff %s\n", localstuff);
			exit(1);
		}
	}

	if ( debug>0 ) {
	  print_tuple(tuple);
	}

	if ( debug>0 ) {
	  printf("polling for tuple:\n");
	  print_tuple(tuple);
	}

	for (c = 0; c < timesToPoll; c++ ) {
	     if ((ret =
		bundle_poll(ba, tuple, &iterator, &bw)) == BUNDLE_SUCCESS) {
		if (first_time == 1) {
		  if ( debug>0 ) printf("Bundle poll iterator set to %d\n", iterator);
		  first_time = 0;
		}
		received_bundle_count++;
		if ( debug>0 ) {
		  printf("yup, got a bundle[%d] at %s\n", 
			 received_bundle_count, bw.filename.filename_val);
		  //printf("with bundle spec:\n");
		  //print_bundle_spec(bw.bs);
		  //printf("and iterator 0x%x\n", iterator);
		}
	     } else { 
		if (first_time == 1) {
		  if ( debug>0 ) printf("Bundle poll iterator set to %d\n", iterator);
		  first_time = 0;
		}
		if ( debug>0 ) {
		  printf(".");
		  fflush(stdout);
		}
		sleep(1);
	     }

	}
	if ( debug>0 ) {
	  printf("I'm tired of waiting for bundles...\n");
	  printf("\n***all done (success)\n");
	}
	close_agent(ba);
	
	if ( writeResourceFile ) {
	  writeDefaultsFile(0);
	}
	exit(0);
}