void event_numeric( irc_session_t * session, unsigned int event, const char * origin, const char ** params, unsigned int count )
{
    IRCSessionContext* p_ctx = static_cast< IRCSessionContext* >( irc_get_ctx( session ) );

    // handle /names stuff
    if ( event == LIBIRC_RFC_RPL_NAMREPLY )
    {
        std::vector< std::string > names;
        std::string namestring( params[ 3 ] );
        
        yaf3d::explode( namestring, " ", &names );
        // fill the list
        p_ctx->_p_handler->_nickNames.clear();
        for ( size_t cnt = 0; cnt < names.size(); ++cnt )
            p_ctx->_p_handler->_nickNames.push_back( names[ cnt ] );
    }
    // this signalized the end of name list transmission
    else if ( event == LIBIRC_RFC_RPL_ENDOFNAMES )
    {
        p_ctx->_p_handler->recvMemberList( params[ 1 ] );
    }
    // handle /whois stuff
    else if ( event == LIBIRC_RFC_RPL_WHOISUSER )
    {
        if ( count > 1 )
        {
            std::string header( "WHOIS " );
            header += params[ 1 ];
            p_ctx->_p_handler->recvMessage( p_ctx->_channel, "* ", header );
            for ( unsigned int cnt = 2; cnt < count; cnt ++ )
                p_ctx->_p_handler->recvMessage( p_ctx->_channel, "- ", params[ cnt ] );
        }
    }
    else if ( event == LIBIRC_RFC_RPL_ENDOFWHOIS )
    {
        p_ctx->_p_handler->recvMessage( p_ctx->_channel, "* ", "--------" );
    }
    // just output system message
    else if ( event > 400 )
    {
        std::string msg;

        if ( count > 0 ) 
            msg += std::string( params[ 0 ] );

        if ( count > 1 )
            msg += " " + std::string( params[ 1 ] );

        if ( count > 2 )
            msg += " " + std::string( params[ 2 ] );

        p_ctx->_p_handler->recvSystemMessage( msg );
    }
}
	//! Writes appropriate metadata to the archive for this polymorphic type
	static void writeMetadata(Archive & ar) {
		// Register the polymorphic type name with the archive, and get the id
		char const * name = binding_name<T>::name();
		std::uint32_t id = ar.registerPolymorphicType(name);

		// Serialize the id
		ar(CEREAL_NVP_("polymorphic_id", id));

		// If the msb of the id is 1, then the type name is new, and we should serialize it
		if (id & detail::msb_32bit) {
			std::string namestring(name);
			ar(CEREAL_NVP_("polymorphic_name", namestring));
		}
	}
Ejemplo n.º 3
0
/*
 * Class:     mapnik_MapDefinition
 * Method:    getStyle
 * Signature: (Ljava/lang/String;)Lmapnik/FeatureTypeStyle;
 */
JNIEXPORT jobject JNICALL Java_mapnik_MapDefinition_getStyle
  (JNIEnv *env, jobject mapobject, jstring namej)
{
	PREAMBLE;
	mapnik::Map* map=LOAD_MAP_POINTER(mapobject);
	refjavastring name(env, namej);
	std::string namestring(name.stringz);

	boost::optional<mapnik::feature_type_style const&> style=map->find_style(namestring);
	if (!style) return 0;

	mapnik::feature_type_style* stylepinned=new mapnik::feature_type_style(style.get());

	jobject ret=env->NewObject(CLASS_FEATURE_TYPE_STYLE, CTOR_NATIVEOBJECT);
	env->SetLongField(ret, FIELD_PTR, FROM_POINTER(stylepinned));
	return ret;
	TRAILER(0);
}
Ejemplo n.º 4
0
int main(int argc, char** argv)
{
	GLFWwindow* glfwwindow;
	{//OpenGL/GLFW Init
		if (!glfwInit()) {
			std::cerr << "Error: GLFW init failed" << std::endl;
			exit(EXIT_FAILURE);
		}
		glfwwindow = glfwCreateWindow(200, 200, "Nvidia interop bug demo", nullptr, nullptr);
		glfwMakeContextCurrent(glfwwindow);
		glewInit();
		std::cout << "OpenGL Info: " << (char*)glGetString(GL_VENDOR) << " " << (char*)glGetString(GL_RENDERER) << std::endl;
	}
	cl_context clcontext;
	cl_command_queue clqueue;
	{//OpenCL init
		cl_platform_id platform = nullptr;
		{//Platform init
			cl_uint numPlatforms;
			clGetPlatformIDs(0, nullptr, &numPlatforms);
			if (numPlatforms == 0)
			{
				std::cerr << "Error: No OpenCL platforms available" << std::endl;
				return EXIT_FAILURE;
			}
			cl_platform_id* all_platforms = new cl_platform_id[numPlatforms];
			clGetPlatformIDs(numPlatforms, all_platforms, nullptr);
			for (size_t i = 0; i < numPlatforms; i++) //Select Nvidia out of the platforms
			{
				char name[300];
				clGetPlatformInfo(all_platforms[i], CL_PLATFORM_NAME, sizeof(name), &name, nullptr);
				std::string namestring(name);
				if (namestring.find("NVIDIA") != std::string::npos || namestring.find("Nvidia") != std::string::npos)
					platform = all_platforms[i];	
			}
			if (platform == nullptr) {
				std::cerr << "No Nvidia OpenCL platform found, will default to platform 0 ";
				
			}

			delete[] all_platforms;
		}
		{ //Create shared context
			cl_context_properties properties[7];
			properties[0] = CL_CONTEXT_PLATFORM; //This is different for other operating systems than Windows
			properties[1] = (cl_context_properties)platform;
			properties[2] = CL_GL_CONTEXT_KHR;
			properties[3] = (cl_context_properties)wglGetCurrentContext();
			properties[4] = CL_WGL_HDC_KHR;
			properties[5] = (cl_context_properties)wglGetCurrentDC();
			properties[6] = 0;

			clcontext = clCreateContextFromType(properties, CL_DEVICE_TYPE_GPU, nullptr, nullptr, nullptr);
		}
		cl_device_id cldevice;
		{ //Create cldevice
			cl_device_id* devices;
			cl_command_queue commandQueue = nullptr;
			size_t numDevices = 0;

			// First get the size of the devices buffer
			clGetContextInfo(clcontext, CL_CONTEXT_DEVICES, 0, nullptr, &numDevices);

			if (numDevices == 0)
			{
				std::cerr << "Error: No OpenCL devices available" << std::endl;
				return EXIT_FAILURE;
			}
			devices = new cl_device_id[numDevices];
			clGetContextInfo(clcontext, CL_CONTEXT_DEVICES, numDevices, devices, nullptr);
			cldevice = devices[0];
			delete[] devices;
		}
		{ //Create CL command queue
			clqueue = clCreateCommandQueue(clcontext, cldevice, 0, nullptr);
		}
		char platformname[300];
		char devicename[300];
		clGetPlatformInfo(platform, CL_PLATFORM_NAME, sizeof(platformname), &platformname, nullptr);
		clGetDeviceInfo(cldevice, CL_DEVICE_NAME, sizeof(devicename), &devicename, nullptr);
		std::cout << "OpenCL platform " << platformname << " device " << devicename << std::endl;
	}
	size_t size = 200 * 200 * 4; //w=200, h=200, 4 bytes per channel
	char* databuffer = new char[size];
	GLuint glbuffer, gltexture;
	cl_mem unsharedbuffer, sharedbuffer, unsharedtexture, sharedtexture;
	{ //Init test data
		glGenBuffers(1, &glbuffer);
		glBindBuffer(GL_ARRAY_BUFFER, glbuffer);
		glBufferData(GL_ARRAY_BUFFER, size, databuffer, GL_STREAM_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, GL_NONE);

		glGenTextures(1, &gltexture);
		glBindTexture(GL_TEXTURE_2D, gltexture);
		glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 200, 200, 0, GL_RGBA, GL_UNSIGNED_BYTE, databuffer);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //Intel needs this for shared textures
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //Intel needs this for shared textures
		glBindTexture(GL_TEXTURE_2D, GL_NONE);

		sharedtexture = clCreateFromGLTexture(clcontext, CL_MEM_READ_WRITE, GL_TEXTURE_2D, 0, gltexture, nullptr);
		sharedbuffer = clCreateFromGLBuffer(clcontext, CL_MEM_READ_WRITE, glbuffer, nullptr);

		unsharedbuffer = clCreateBuffer(clcontext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, size, databuffer, nullptr);
		cl_image_format imgformat;
		cl_image_desc desc;
		imgformat.image_channel_data_type = CL_UNSIGNED_INT8;
		imgformat.image_channel_order = CL_RGBA;
		desc.image_type = CL_MEM_OBJECT_IMAGE2D;
		desc.image_width = 200;
		desc.image_height = 200;
		desc.image_depth = 1;
		desc.image_array_size = 1;
		desc.image_row_pitch = 0;
		desc.image_slice_pitch = 0;
		desc.num_mip_levels = 0;
		desc.num_samples = 0;
		desc.buffer = nullptr;
		unsharedtexture = clCreateImage(clcontext, CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR, &imgformat, &desc, databuffer, nullptr);
	}
	{
		const size_t origin[3] = { 0, 0, 0 };
		const size_t region[3] = { 200, 200, 1 };
		size_t pitch;
		//
		//MAIN PART BEGINS HERE
		//
		{ //OpenGL buffer
			std::cout << "Mapping buffer with OpenGL: ";
			glBindBuffer(GL_ARRAY_BUFFER, glbuffer);
			void* glmapptr = glMapBuffer(GL_ARRAY_BUFFER, GL_MAP_READ_BIT | GL_MAP_WRITE_BIT);
			glUnmapBuffer(GL_ARRAY_BUFFER);
			glBindBuffer(GL_ARRAY_BUFFER, GL_NONE);
			std::cout << "OK" << std::endl;
			glFinish();
		}
		{ //OpenCL unshared texture
			std::cout << "Mapping unshared texture with OpenCL: ";
			void* unsimgptr = clEnqueueMapImage(clqueue, unsharedtexture, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, origin, region, &pitch, nullptr, 0, nullptr, nullptr, nullptr); //This API call works fine for unshared objects
			clEnqueueUnmapMemObject(clqueue, unsharedtexture, unsimgptr, 0, nullptr, nullptr);
			std::cout << "OK" << std::endl;
		}
		{ //OpenCL shared texture
			std::cout << "Mapping shared texture with OpenCL: ";
			clEnqueueAcquireGLObjects(clqueue, 1, &sharedtexture, 0, nullptr, nullptr);
			void* shdimgptr = clEnqueueMapImage(clqueue, unsharedtexture, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, origin, region, &pitch, nullptr, 0, nullptr, nullptr, nullptr); //This API call works fine shared objects
			clEnqueueUnmapMemObject(clqueue, unsharedtexture, shdimgptr, 0, nullptr, nullptr);
			clEnqueueReleaseGLObjects(clqueue, 1, &sharedtexture, 0, nullptr, nullptr);
			std::cout << "OK" << std::endl;
		}
		{ //OpenCL unshared buffer
			std::cout << "Mapping unshared buffer with OpenCL: ";
			void* unsbufptr = clEnqueueMapBuffer(clqueue, unsharedbuffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, size, 0, nullptr, nullptr, nullptr); //This API call works fine for unshared buffers
			clEnqueueUnmapMemObject(clqueue, unsharedbuffer, unsbufptr, 0, nullptr, nullptr);
			std::cout << "OK" << std::endl;
		}
		{ //OpenCL shared buffer
			std::cout << "Mapping shared buffer with OpenCL (EXPECTING CRASH ON NVIDIA SYSTEMS): " << std::endl;
			clEnqueueAcquireGLObjects(clqueue, 1, &sharedbuffer, 0, nullptr, nullptr);
			//
			//CRITICAL PART BEGINS HERE
			//

			void* shdbufptr = clEnqueueMapBuffer(clqueue, sharedbuffer, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, size, 0, nullptr, nullptr, nullptr);
			//On Nvidia systems when using shared objects, error 0xC0000005 occurs in ntdll.dll: write access violation at position 0xSOMETHING
			//This leaves my application in an unusable state
			//But it works fine everywhere else (tested on ARM, AMD, Intel systems)

			//
			//CRITICAL PART ENDS HERE
			//
			std::cout << "did not fail" << std::endl;
			clEnqueueUnmapMemObject(clqueue, sharedbuffer, shdbufptr, 0, nullptr, nullptr);
			clEnqueueReleaseGLObjects(clqueue, 1, &sharedbuffer, 0, nullptr, nullptr);
			std::cout << "OK" << std::endl;
		}
		//
		//MAIN PART ENDS HERE
		//
	}
	clFinish(clqueue);

	delete[] databuffer;
	clReleaseMemObject(sharedbuffer);
	clReleaseMemObject(unsharedbuffer);
	clReleaseMemObject(sharedtexture);
	clReleaseMemObject(unsharedtexture);

	clReleaseCommandQueue(clqueue);
	clReleaseContext(clcontext);

	glDeleteTextures(1, &gltexture);
	glDeleteBuffers(1, &glbuffer);

	glfwDestroyWindow(glfwwindow);
	glfwTerminate();
	return EXIT_SUCCESS;
}
Ejemplo n.º 5
0
int FixUsersCommand::Execute() {
  LOG << "Runnning FixUsersCommand::Execute";

  initStatusDat(config()->config()->datadir());
  File userFile(config()->config()->datadir(), USER_LST);
	if (!userFile.Exists()) {
    LOG << userFile.full_pathname() << " does not exist.";
    return 1;
	}

	UserManager userMgr(config()->config()->datadir(), sizeof(userrec), 
      config()->config()->config()->maxusers);
  LOG << "Checking USER.LST... found " << userMgr.GetNumberOfUserRecords() << " user records.";
  LOG << "TBD: Check for trashed user recs.";
	if (userMgr.GetNumberOfUserRecords() > config()->config()->config()->maxusers) {
    LOG << "Might be too many.";
    if (!arg("exp").as_bool()) {
      return 1;
    }
	} else {
    LOG << "Reasonable number.";
	}

	std::vector<smalrec> smallrecords;
	std::set<std::string> names;

  const int num_user_records = userMgr.GetNumberOfUserRecords();
	for(int i = 1; i <= num_user_records; i++) {
		User user;
		userMgr.ReadUser(&user, i);
		user.FixUp();
		userMgr.WriteUser(&user, i);
		if (!user.IsUserDeleted() && !user.IsUserInactive()) {
			smalrec sr = { 0 };
			strcpy((char*) sr.name, user.GetName());
			sr.number = static_cast<uint16_t>(i);
			std::string namestring((char*) sr.name);
			if (names.find(namestring) == names.end()) {
				smallrecords.push_back(sr);
				names.insert(namestring);
        if (arg("verbose").as_bool()) {
          LOG << "Keeping user: "******" #" << sr.number ;
        }
			} else {
				LOG << "[skipping duplicate user: "******" #" << sr.number << "]";
			}
		}
	};

	std::sort(smallrecords.begin(), smallrecords.end(), [](const smalrec& a, const smalrec& b) -> bool {
		int equal = strcmp((char*)a.name, (char*)b.name);

		// Sort by user number if names match.
		if (equal == 0) {
			return a.number < b.number;
		}

		// Otherwise sort by name comparison.
		return equal < 0;
	});

	printf("size=%lu %lu\n", smallrecords.size(), sizeof(smalrec) * smallrecords.size());
  LOG << "Checking NAMES.LST";
	File nameFile(config()->config()->datadir(), NAMES_LST);
	if (!nameFile.Exists()) {
    LOG << nameFile.full_pathname() << " does not exist, regenerating with "
         << smallrecords.size() << " names";
		nameFile.Open(File::modeCreateFile | File::modeBinary | File::modeWriteOnly);
		nameFile.Write(&smallrecords[0], sizeof(smalrec) * smallrecords.size());
		nameFile.Close();
	} else {
		if (nameFile.Open(File::modeReadOnly | File::modeBinary)) {
			long size = nameFile.GetLength();
      uint16_t recs = static_cast<uint16_t>(size / sizeof(smalrec));
			if (recs != status.users) {
				status.users = recs;
        LOG << "STATUS.DAT contained an incorrect user count.";
			} else {
        LOG << "STATUS.DAT matches expected user count of " << status.users << " users.";
			}
		}
		nameFile.Close();
	}
  return 0;
}
Ejemplo n.º 6
0
int FixUsersCommand::Execute() {
    std::cout << "Runnning FixUsersCommand::Execute" << std::endl;
    	File userFile(syscfg.datadir, USER_LST);
	if(!userFile.Exists()) {
		Print(NOK, true, "%s does not exist.", userFile.full_pathname().c_str());
		giveUp();
	}

	WUserManager userMgr;
	userMgr.InitializeUserManager(syscfg.datadir, sizeof(userrec), syscfg.maxusers);
	Print(OK, true, "Checking USER.LST... found %d user records.", userMgr.GetNumberOfUserRecords());

	Print(OK, true, "TBD: Check for trashed user recs.");
	if(userMgr.GetNumberOfUserRecords() > syscfg.maxusers) {
		Print(OK, true, "Might be too many.");
			maybeGiveUp();
	} else {
		Print(OK, true, "Reasonable number.");
	}

	std::vector<smalrec> smallrecords;
	std::set<std::string> names;

  const int num_user_records = userMgr.GetNumberOfUserRecords();
	for(int i = 1; i <= num_user_records; i++) {
		WUser user;
		userMgr.ReadUser(&user, i);
		user.FixUp();
		userMgr.WriteUser(&user, i);
		if (!user.IsUserDeleted() && !user.IsUserInactive()) {
			smalrec sr = { 0 };
			strcpy((char*) sr.name, user.GetName());
			sr.number = static_cast<unsigned short>(i);
			std::string namestring((char*) sr.name);
			if (names.find(namestring) == names.end()) {
				smallrecords.push_back(sr);
				names.insert(namestring);
        const std::string msg = StringPrintf("Keeping user: %s #%d", sr.name, sr.number);
        Print(OK, true, msg.c_str());
			}
			else {
				std::cout << "[skipping duplicate user: "******" #" << sr.number << "]";
			}
		}
	};

	std::sort(smallrecords.begin(), smallrecords.end(), [](const smalrec& a, const smalrec& b) -> bool {
		int equal = strcmp((char*)a.name, (char*)b.name);

		// Sort by user number if names match.
		if (equal == 0) {
			return a.number < b.number;
		}

		// Otherwise sort by name comparison.
		return equal < 0;
	});

	printf("size=%lu %lu\n", smallrecords.size(), sizeof(smalrec) * smallrecords.size());

	Print(OK, true, "Checking NAMES.LST");
	File nameFile(syscfg.datadir, NAMES_LST);
	if(!nameFile.Exists()) {
		Print(NOK, true, "%s does not exist, regenerating with %d names", nameFile.full_pathname().c_str(),
			smallrecords.size());
		nameFile.Close();
		nameFile.Open(File::modeCreateFile | File::modeBinary | File::modeWriteOnly);
		nameFile.Write(&smallrecords[0], sizeof(smalrec) * smallrecords.size());
		nameFile.Close();

	} else {
		if(nameFile.Open(File::modeReadOnly | File::modeBinary)) {
			unsigned long size = nameFile.GetLength();
			unsigned short recs = static_cast<unsigned short>(size / sizeof(smalrec));
			if (recs != status.users) {
				status.users = recs;
				Print(NOK, true, "STATUS.DAT contained an incorrect user count.");
			} else {
				Print(OK, true, "STATUS.DAT matches expected user count of %d users.", status.users);
			}
		}
		nameFile.Close();
	}
    return 0;
}