示例#1
0
bool BleBox::UpdateNode(const int id, const std::string &name, const std::string &IPAddress)
{
	std::string deviceApiName = IdentifyDevice(IPAddress);
	if (deviceApiName.empty())
		return false;

	int deviceTypeID = GetDeviceTypeByApiName(deviceApiName);
	if (deviceTypeID == -1)
		return false;

	STR_DEVICE deviceType = DevicesType[deviceTypeID];

	std::string szIdx = IPToHex(IPAddress, deviceType.deviceID);

	m_sql.safe_query("UPDATE DeviceStatus SET DeviceID='%q', Unit='%d', Type='%d', SubType='%d', SwitchType='%d', Name='%q' WHERE (HardwareID=='%d') AND (ID=='%d')", 
		szIdx.c_str(), deviceType.unit, deviceType.deviceID, deviceType.subType, deviceType.switchType, name.c_str(), m_HwdID, id);

	ReloadNodes();
	return true;
}
示例#2
0
void BleBox::AddNode(const std::string &name, const std::string &IPAddress)
{
	std::string deviceApiName = IdentifyDevice(IPAddress);
	if (deviceApiName.empty())
		return;

	int deviceTypeID = GetDeviceTypeByApiName(deviceApiName);
	if (deviceTypeID == -1)
		return;

	STR_DEVICE deviceType = DevicesType[deviceTypeID];

	std::string szIdx = IPToHex(IPAddress, deviceType.deviceID);

	m_sql.safe_query(
		"INSERT INTO DeviceStatus (HardwareID, DeviceID, Unit, Type, SubType, SwitchType, Used, SignalLevel, BatteryLevel, Name, nValue, sValue) "
		"VALUES (%d, '%q', %d, %d, %d, %d, 1, 12, 255, '%q', 0, 'Unavailable')",
		m_HwdID, szIdx.c_str(), deviceType.unit, deviceType.deviceID, deviceType.subType, deviceType.switchType, name.c_str());

	ReloadNodes();
}
示例#3
0
//======================================
// ScanServer: PCI/AGP hardware scan
//--------------------------------------
void ScanServer::Scan(void) {
	PciData *first = PciGetData();
	map<int,ServerData> pci;
	map<int,ServerData> graphics;
	map<int,ServerData> equals;
	map<int,ServerData> save;
	map<int,Identity>   config;
	int algorithm;
	int count = 0;
	int n     = 0;
	int mapnr = 0;

	// delete the scanserverstuff file if it exist
	// ---------------------------------------------
	unlink(SERVER_STUFF_DATA);
 
	// save the complete PCI/AGP stuff into
	// a local map called [ pci ]
	// ---------------------------
	for(PciData* p=first; p; p=p->next) {
		ServerData data;

		data.cls  = p->cls;
		data.bus  = p->bus;
		data.slot = p->slot;
		data.func = p->func;
		data.vid  = p->vid;
		data.did  = p->did;

		if (p->bus == 0) {
			data.bustype = "PCI";
		} else {
			data.bustype = "AGP";
		}

		data.subvendor = p->svid;
		data.subdevice = p->sdid;
		pci[count] = data;  
		count++;
	}

	// import the Identity.map, the data will be used
	// on several points up to this point
	// -----------------------------------
	SPReadFile<Identity> configI;
	configI.SetFile(IDENTITY);
	configI.ImportIdentity();
	for (int i = configI.Count(); i > 0; i--) {
		config[n] = configI.Pop();
		n++;
	}

	// identify the graphics cards in the pool 
	// of cards
	// ---------
	n = 0;
	for (int i=0;i<count;i++) {
	if ((pci[i].cls == 0x300) || (pci[i].cls == 0x0001)) {
		graphics[n] = pci[i];
		n++;
	} else {
		mapnr = IdentifyDevice (
			config,
			pci[i].vid,pci[i].did,
			pci[i].subvendor,pci[i].subdevice,
			NO_FLAG_QUESTION,NO_FLAG_QUESTION
		);
		if (mapnr >= 0) {
			graphics[n] = pci[i];
			n++;
		}
	}
	}

	// check how many cards we found...
	// ---------------------------------
	if (n == 0) {
		// ...
		// Ooops we didn`t find any PCI/AGP card;
		// assuming unclassified device
		// ---
		ServerData data;
		data.bustype   = "NUL";     // no bus location detected
		data.subvendor = 0x0000;
		data.subdevice = 0x0000;
		data.vid       = UNCVID;
		data.did       = UNCDID;
		data.bus       = 0x0;       // there is a profile
		data.slot      = 0x1;       // called nobus which will
		data.func      = 0x2;       // remove the wrong BusID entry
		if (! haveFBdev()) {
		if (! haveVesaBIOS()) {
			data.module = "vga";
		} else {
			data.module = "vesa";
		}
		}
		pci[n]         = data;
		graphics[n]    = pci[n];
		n = 1;
	}
	// ...
	// check for special devices which comes with more 
	// than one chip on a single device. 
	// --> equal BUS and SLOT number
	//
	// check algorithm:
	// -----------------
	// 1) look if we can assign the function 0 device to a driver module
	//    if yes this is it and all other non function 0 devices
	//    will be removed
	//
	// 2) if the function 0 device is unknown look at the rest 
	//    stuff and try to identify them, the result remains in the
	//    pci stuff all other stuff including the function 0 device
	//    will be removed
	// --
	int bus   = 0;
	int slot  = 0;
	int group = 0;
	int card  = 0;
	for (int i=0;i<n;i++) {
		if (graphics[i].bus == -1) {
			continue;
		} 
		equals[group] = graphics[i];
		bus  = graphics[i].bus;
		slot = graphics[i].slot;

		for(int k=0;k<n;k++) {
		if ((k != i) && (graphics[k].bus==bus) && (graphics[k].slot==slot)) {
			group++;
			equals[group] = graphics[k];
			graphics[k].bus = -1;
		}
		} 
		if (group == 0) {
			// ...
			// no multiple devices found...
			// -----------------------------
			save[card] = graphics[i]; card++;
		} else {
			// ...
			// multiple device found:
			// start check algorithm...
			// -------------------------- 
			algorithm = 0;
			// 1)
			for (int k=0;k<=group;k++) {
			if (equals[k].func == 0x0) {
				mapnr = IdentifyDevice (
					config,
					equals[k].vid,equals[k].did,
					equals[k].subvendor,equals[k].subdevice,
					NO_FLAG_QUESTION,NO_FLAG_QUESTION
				);
				if (mapnr >= 0) {
					save[card] = equals[k]; card++;
					algorithm  = 1;
					break;
				}
			}
			}
			// 2)
			if (algorithm == 0) {
			for (int k=0;k<=group;k++) {
			if (equals[k].func != 0x0) {
				mapnr = IdentifyDevice (
					config,
					equals[k].vid,equals[k].did,
					equals[k].subvendor,equals[k].subdevice,
					NO_FLAG_QUESTION,NO_FLAG_QUESTION
				);
				if (mapnr >= 0) {
					save[card] = equals[k]; card++;
				}
			}
			}
			}
		}
		equals.clear();
		group = 0;
	}
	// ...
	// save the detected number of cards and remap
	// data to graphics...
	// --------------------
	graphics.clear();
	card = save.size();
	for (int k=0;k<card;k++) {
		save[k].detected = card; graphics[k] = save[k];
	}
	// ...
	// check the moduleme options, if the module is set
	// manually here we will not overwrite it
	// --------------------------------------
	int modsize = moduleme.size();
	if (modsize > 0) {
	map <int,string>::iterator pos;
	for (int i=0;i<=modsize;i++) {
		pos = moduleme.find(i);
		if (pos != moduleme.end()) {
			graphics[i].module = moduleme[i];
		}
	}
	} 
	// ...
	// check the scanme options, this could change the order 
	// and amount of cards to use for configuration
	// ---------
	save.clear();
	int optcard = 0;
	int nr      = 0;
	int optsize = scanme.size();
	if (optsize > 0) {
		ServerDataMap::iterator pos;
		for (int i=0;i<optsize;i++) {
			optcard = scanme.front();
			scanme.pop_front();
			pos = graphics.find(optcard);
			if (pos != graphics.end()) {
				ServerData data = graphics[optcard];
				save[nr] = data;
				nr++;
			} else {
				// ...
				// Card is not defined... skip
				// ---
			}
		}
		card = nr;
		graphics.clear();
		graphics = save;
	}
	// ...
	// identify the card(s) fully using the 
	// Identity.map
	// ---
	int askid = -1;
	for (int i=0;i<card;i++) {
		askid = ask;
		// ...
		// do not ask and use the DEFAULT 
		// flag if vga/fbdev/vesa is set
		// ---
		int cardnumber = card;
		if (
			( graphics[i].module == "vga" )   || 
			( graphics[i].module == "fbdev" ) ||
			( graphics[i].module == "vesa" )
		) {
			cardnumber = NO_FLAG_QUESTION;
		}
		mapnr = IdentifyDevice (
			config,
			graphics[i].vid,graphics[i].did,
			graphics[i].subvendor,graphics[i].subdevice,
			cardnumber,askid,i
		);
		if (mapnr >= 0) {
		//======================================
		// get identification...
		//--------------------------------------
		graphics[i].vendor    = config[mapnr].name;
		graphics[i].device    = config[mapnr].device;
		graphics[i].flag      = config[mapnr].flag;
		graphics[i].profile   = config[mapnr].profile;
		graphics[i].raw       = config[mapnr].raw;
		graphics[i].option    = config[mapnr].option;
		graphics[i].extension = config[mapnr].extension;
		graphics[i].script3d  = config[mapnr].script3d;
		graphics[i].package3d = config[mapnr].package3d;
		} else {
		//======================================
		// did not get identification, 
		// set defaults...
		//--------------------------------------
		graphics[i].vendor    = "VESA";
		graphics[i].device    = "Framebuffer Graphics";
		graphics[i].flag      = "DEFAULT";
		graphics[i].profile   = "";
		graphics[i].raw       = "";
		graphics[i].option    = "";
		graphics[i].extension = "";
		graphics[i].script3d  = "";
		graphics[i].package3d = "";

		if (
			(graphics[i].module == "") || 
			((graphics[i].vid == UNCVID) && (graphics[i].did == UNCDID) )
		) {
			if ( haveFBdev() ) {
				graphics[i].module   = "fbdev";
			} else {
			if ( haveVesaBIOS() ) {
				graphics[i].module   = "vesa";
				graphics[i].vendor   = "VESA";
				graphics[i].device   = "Vesa-BIOS Graphics";
			} else {
				graphics[i].module   = "vga";
				graphics[i].vendor   = "Unclassified";
				graphics[i].device   = "Graphics";
			}
			}
		}
		if (checkPCIVendor) {
			// ...
			// we did not get any identification to this card, but
			// the option --pcivendor was set. We will look at the
			// vendor -> driver table and try to set a driver in this
			// case
			// ---
			str vid_str;
			RcData vendorMap;
			SPReadFile<RcData> rcVendor;
			rcVendor.SetFile (VENDOR_MAP);
			vendorMap = rcVendor.ImportVendorMap();
			sprintf(vid_str, "0x%04x",graphics[i].vid);
			string vid = vid_str;
			if (vendorMap[vid].c_str()) {
				graphics[i].module = vendorMap[vid].c_str();
			}
		}
		}
		if (graphics[i].module == "") {
			graphics[i].module  = config[mapnr].server;
		}
	}
	// ...
	// Start TestServer if:
	// - primary card check is needed (multihead environment)
	// - scanme card option is set
	// - vmware driver is used
	// ---
	if (
		((card > 1) && (optsize <= 0) && (pcheck == 1)) ||
		((graphics[0].module == "vmware") && (pcheck == 1))
	) {
		str file;
		sprintf(file,"%s-%d",TMP_CONFIG,getpid());
		// ...
		// open startup config...
		// ---
		ofstream handle(file);
		if (! handle) {
			cout << "ScanServer: could not create file: ";
			cout << TMP_CONFIG << endl;
			return;
		}
		map<int,string> section;
		XF86ConfigFile cfg;
		ScanMouse mouse;
		// ...
		// scan the mouse...
		// ---
		mouse.Scan(); MouseData mdata = mouse.Pop();
		cfg.SetMouseProperties(mdata.protocol,mdata.device);
		// ...
		// create base sections...
		// ------------------------
		section[0] = cfg.DoFilesSection();
		section[1] = cfg.DoModuleSection();
		section[2] = cfg.DoInputDeviceSection();

		cfg.SetSectionID(card);
		section[3] = cfg.DoServerLayoutSection();
		// ...
		// create dynamic sections...
		// ---------------------------
		for (int n=0;n<card;n++) {
			cfg.SetSectionID(n);
			if ((cfg.SetDriver(graphics[n].module)) == 1) {
				cout << "SaX: sorry could not open /dev/fb0... abort" << endl;
				exit(1);
			}
			cfg.SetBus (
				graphics[n].bus,graphics[n].slot,graphics[n].func
			);

			section[4] = section[4] + "\n" + cfg.DoMonitorSection();
			section[5] = section[5] + "\n" + cfg.DoScreenSection();
			section[6] = section[6] + "\n" + cfg.DoDeviceSection();
			section[7] = section[7] + "\n" + cfg.DoServerFlagsSection();
		}
		// ...
		// write sections to file...
		// ---------------------------
		handle << section[0] << endl;
		handle << section[1] << endl;
		handle << section[7] << endl;
		handle << section[2] << endl;
		handle << section[4] << endl;
		handle << section[5] << endl;
		handle << section[6] << endl;
		handle << section[3] << endl;
		handle.close();

		// ...
		// call CallXF86Loader...
		// ---
		cfg.CallXF86Loader(file);
		cfg.SetFile(SERVER_STUFF_DATA);
		ParseData parse;

		try {
			parse = cfg.Pop();
		} catch (...) {
			// ...
		}
		unlink(file);

		// check the primary device...
		// ----------------------------
		if (parse.primary != "") {
			int pbus  = parse.pbus;
			int pslot = parse.pslot;
			int pfunc = parse.pfunc;
			int id    = 0;

			for (int i=0;i<card;i++) {
				int bus  = graphics[i].bus;
				int slot = graphics[i].slot;
				int func = graphics[i].func;
				if ((bus == pbus) && (slot == pslot) && (func == pfunc)) {
					id = i; break;
				}
			}

			if (id != 0) {
				save.clear();
				save[0] = graphics[id];
				int n   = 1;
				for (int i=0;i<card;i++) {
					if (i == id) {
						continue;
					} 
					save[n] = graphics[i];
					n++;
				}
				graphics.clear();
				graphics = save;
			}
		}
		cfg.Save();
	}
	// ...
	// save the result to the object data
	// ---
	for (int i=0;i<card;i++) {
		Push(graphics[i]);
	}
}