JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface ) { LOGV( "HIDDeviceConnected() id=%d VID/PID = %.4x/%.4x, interface %d\n", nDeviceID, nVendorId, nProductId, nInterface ); hid_device_info *pInfo = new hid_device_info; memset( pInfo, 0, sizeof( *pInfo ) ); pInfo->path = CreateStringFromJString( env, sIdentifier ); pInfo->vendor_id = nVendorId; pInfo->product_id = nProductId; pInfo->serial_number = CreateWStringFromJString( env, sSerialNumber ); pInfo->release_number = nReleaseNumber; pInfo->manufacturer_string = CreateWStringFromJString( env, sManufacturer ); pInfo->product_string = CreateWStringFromJString( env, sProduct ); pInfo->interface_number = nInterface; hid_device_ref<CHIDDevice> pDevice( new CHIDDevice( nDeviceID, pInfo ) ); hid_mutex_guard l( &g_DevicesMutex ); hid_device_ref<CHIDDevice> pLast, pCurr; for ( pCurr = g_Devices; pCurr; pLast = pCurr, pCurr = pCurr->next ) { continue; } if ( pLast ) { pLast->next = pDevice; } else { g_Devices = pDevice; } }
DLLEXPORT void STDCALL FPDF_FFLDraw(FPDF_FORMHANDLE hHandle, FPDF_BITMAP bitmap, FPDF_PAGE page, int start_x, int start_y, int size_x, int size_y, int rotate, int flags) { if (!hHandle) return; UnderlyingPageType* pPage = UnderlyingFromFPDFPage(page); if (!pPage) return; #ifndef PDF_ENABLE_XFA CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; else options.m_Flags &= ~RENDER_CLEARTYPE; // Grayscale output if (flags & FPDF_GRAYSCALE) { options.m_ColorMode = RENDER_COLOR_GRAY; options.m_ForeColor = 0; options.m_BackColor = 0xffffff; } options.m_AddFlags = flags >> 8; options.m_pOCContext = new CPDF_OCContext(pPage->m_pDocument); #else // PDF_ENABLE_XFA CPDFXFA_Document* pDocument = pPage->GetDocument(); if (!pDocument) return; CPDF_Document* pPDFDoc = pDocument->GetPDFDoc(); if (!pPDFDoc) return; CPDFDoc_Environment* pEnv = (CPDFDoc_Environment*)hHandle; CPDFSDK_Document* pFXDoc = pEnv->GetSDKDocument(); if (!pFXDoc) return; #endif // PDF_ENABLE_XFA CFX_Matrix matrix; pPage->GetDisplayMatrix(matrix, start_x, start_y, size_x, size_y, rotate); FX_RECT clip(start_x, start_y, start_x + size_x, start_y + size_y); #ifdef _SKIA_SUPPORT_ std::unique_ptr<CFX_SkiaDevice> pDevice(new CFX_SkiaDevice); #else std::unique_ptr<CFX_FxgeDevice> pDevice(new CFX_FxgeDevice); #endif pDevice->Attach((CFX_DIBitmap*)bitmap); pDevice->SaveState(); pDevice->SetClip_Rect(clip); #ifndef PDF_ENABLE_XFA if (CPDFSDK_PageView* pPageView = FormHandleToPageView(hHandle, pPage)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options); #else // PDF_ENABLE_XFA CPDF_RenderOptions options; if (flags & FPDF_LCD_TEXT) options.m_Flags |= RENDER_CLEARTYPE; else options.m_Flags &= ~RENDER_CLEARTYPE; // Grayscale output if (flags & FPDF_GRAYSCALE) { options.m_ColorMode = RENDER_COLOR_GRAY; options.m_ForeColor = 0; options.m_BackColor = 0xffffff; } options.m_AddFlags = flags >> 8; options.m_pOCContext = new CPDF_OCContext(pPDFDoc); if (CPDFSDK_PageView* pPageView = pFXDoc->GetPageView(pPage)) pPageView->PageView_OnDraw(pDevice.get(), &matrix, &options, clip); #endif // PDF_ENABLE_XFA pDevice->RestoreState(); delete options.m_pOCContext; #ifdef PDF_ENABLE_XFA options.m_pOCContext = NULL; #endif // PDF_ENABLE_XFA }
int main(int iArgC, char *cArgV[]) { // Set a better exception handler std::set_terminate( __gnu_cxx::__verbose_terminate_handler ); // Disable stdin/printf/etc. sync for a speed boost std::ios_base::sync_with_stdio(false); // Declare the supported options. po::options_description poActions("Actions"); poActions.add_options() ("list,l", "list contents of the address book") ("update,u", po::value<std::string>(), "select an address book entry to change by ID") ("add,a", po::value<std::string>(), "add a new address book entry and select it") ("set,s", po::value<std::string>(), "field:value parameter updates entry selected by earlier -u or -a") ; po::options_description poOptions("Options"); poOptions.add_options() ("type,t", po::value<std::string>(), "specify the MFD type (default is autodetect)") ("user,u", po::value<std::string>(), "username to log in as") ("pass,p", po::value<std::string>(), "password") ; po::options_description poHidden("Hidden parameters"); poHidden.add_options() ("host", "MFD hostname") ("help", "produce help message") ; po::options_description poVisible(""); poVisible.add(poActions).add(poOptions); po::options_description poComplete("Parameters"); poComplete.add(poActions).add(poOptions).add(poHidden); po::variables_map mpArgs; std::string host, user, pass, type; try { po::parsed_options pa = po::parse_command_line(iArgC, cArgV, poComplete); // Parse the global command line options for (std::vector<po::option>::iterator i = pa.options.begin(); i != pa.options.end(); i++) { if (i->string_key.empty()) { // If we've already got an archive filename, complain that a second one // was given (probably a typo.) if (!host.empty()) { std::cerr << "Error: unexpected extra parameter (multiple MFDs " "given?!)" << std::endl; return 1; } assert(i->value.size() > 0); // can't have no values with no name! host = i->value[0]; } else if (i->string_key.compare("help") == 0) { std::cout << "Copyright (C) 2010 Adam Nielsen <*****@*****.**>\n" "This program comes with ABSOLUTELY NO WARRANTY. This is free software,\n" "and you are welcome to change and redistribute it under certain conditions;\n" "see <http://www.gnu.org/licenses/> for details.\n" "\n" "Utility to remotely configure multi-function devices (networked photocopiers.)\n" "Build date " __DATE__ " " __TIME__ << "\n" "\n" "Usage: mfdmgr <hostname> <action> [action...]\n" << poVisible << "\n" << std::endl; return RET_OK; } else if ( (i->string_key.compare("t") == 0) || (i->string_key.compare("type") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --type (-t) requires a parameter." << std::endl; return RET_BADARGS; } type = i->value[0]; } else if ( (i->string_key.compare("u") == 0) || (i->string_key.compare("user") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --user (-u) requires a parameter." << std::endl; return RET_BADARGS; } user = i->value[0]; } else if ( (i->string_key.compare("p") == 0) || (i->string_key.compare("pass") == 0) ) { if (i->value.size() == 0) { std::cerr << PROGNAME ": --pass (-p) requires a parameter." << std::endl; return RET_BADARGS; } pass = i->value[0]; } } if (host.empty()) { std::cerr << "Error: no hostname given" << std::endl; return RET_BADARGS; } std::cout << "Opening " << host << " as type " << (type.empty() ? "<autodetect>" : type) << std::endl; // Get the format handler for this file format boost::shared_ptr<mfd::Manager> pManager(mfd::getManager()); mfd::DeviceTypePtr pDeviceType; if (type.empty()) { // Need to autodetect the file format. mfd::DeviceTypePtr pTestType; int i = 0; while ((pTestType = pManager->getDeviceType(i++))) { mfd::E_CERTAINTY cert = pTestType->isInstance(host); switch (cert) { case mfd::EC_DEFINITELY_NO: // Don't print anything (TODO: Maybe unless verbose?) break; case mfd::EC_DEFINITELY_YES: std::cout << "Device is definitely a " << pTestType->getFriendlyName() << " [" << pTestType->getDeviceCode() << "]" << std::endl; pDeviceType = pTestType; // Don't bother checking any other formats if we got a 100% match goto finishTesting; } } finishTesting: if (!pDeviceType) { std::cerr << "Unable to automatically determine the file type. Use " "the --type option to manually specify the file format." << std::endl; return RET_BE_MORE_SPECIFIC; } } else { mfd::DeviceTypePtr pTestType(pManager->getDeviceTypeByCode(type)); if (!pTestType) { std::cerr << "Unknown device type given to -t/--type: " << type << std::endl; return RET_BADARGS; } pDeviceType = pTestType; } assert(pDeviceType != NULL); // Connect to the device boost::shared_ptr<mfd::Device> pDevice(pDeviceType->open(host, user, pass)); assert(pDevice); int iRet = RET_OK; // ID of previously selected address book item std::string idABSelected; std::map<std::string, std::string> fieldSet; // TODO: enum for field type // Run through the actions on the command line for (std::vector<po::option>::iterator i = pa.options.begin(); i != pa.options.end(); i++) { if (i->string_key.compare("list") == 0) { boost::shared_ptr<mfd::AddressBook> ab = pDevice->getAddressBook(); if (!ab) { std::cerr << "This device type does not have an address book." << std::endl; iRet = RET_BADARGS; continue; } const mfd::AddressBook::VC_ENTRYID& entryIds = ab->getEntryIds(); for (mfd::AddressBook::VC_ENTRYID::const_iterator i = entryIds.begin(); i != entryIds.end(); i++ ) { std::cout << "id is " << *i << std::endl; } mfd::AddressBook::VC_FIELDLIST allEntries; ab->getEntries(entryIds, allEntries); for (mfd::AddressBook::VC_FIELDLIST::iterator i = allEntries.begin(); i != allEntries.end(); i++ ) { mfd::AddressBook::FieldList& fl = *i; for (mfd::AddressBook::FieldList::iterator j = fl.begin(); j != fl.end(); j++ ) { std::cout << j->first << "=" << j->second << "; "; } std::cout << std::endl; } } else if (i->string_key.compare("update") == 0) { idABSelected = i->value[0]; std::cout << "Selected ID " << idABSelected << " for update" << std::endl; fieldSet.clear(); // empty any fields previously set } else if (i->string_key.compare("set") == 0) { if (idABSelected.empty()) { std::cerr << "ERROR: You must use -u or -a before --set/-s" << std::endl; iRet = RET_BADARGS; break; } idABSelected = i->value[0]; std::string fieldName, fieldVal; bool bAltDest = split(i->value[0], ':', &fieldName, &fieldVal); if (!bAltDest) { std::cerr << "ERROR: --set/-s requires a parameter of the form " "field:value" << std::endl; iRet = RET_BADARGS; break; } std::cout << "Set field \"" << fieldName << "\" to \"" << fieldVal << "\"" << std::endl; // Ignore --type/-t } else if (i->string_key.compare("type") == 0) { } else if (i->string_key.compare("t") == 0) { } } // for (all command line elements) } catch (po::unknown_option& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return RET_BADARGS; } catch (po::invalid_command_line_syntax& e) { std::cerr << PROGNAME ": " << e.what() << ". Use --help for help." << std::endl; return RET_BADARGS; } catch (mfd::ECommFailure& e) { std::cerr << PROGNAME ": Communication failure (" << e.what() << ")" << std::endl; return RET_SHOWSTOPPER; } return RET_OK; }
CNdasDevicePtr CNdasDeviceRegistrar::Register( __in_opt DWORD SlotNo, __in const NDAS_DEVICE_ID& DeviceId, __in DWORD RegFlags, __in_opt const NDASID_EXT_DATA* NdasIdExtension) { // // this will lock this class from here // and releases the lock when the function returns; // InstanceAutoLock autolock(this); XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_INFORMATION, "Registering device %s at slot %d\n", CNdasDeviceId(DeviceId).ToStringA(), SlotNo); if (NULL == NdasIdExtension) { NdasIdExtension = &NDAS_ID_EXTENSION_DEFAULT; } // // Only DEFAULT and SEAGATE are currently implemented // if (NDAS_VID_SEAGATE != NdasIdExtension->VID && NDAS_VID_DEFAULT != NdasIdExtension->VID) { XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_ERROR, "Unknown Vendor ID=0x%02X\n", NdasIdExtension->VID); ::SetLastError(NDASSVC_ERROR_UNKNOWN_VENDOR_ID); return CNdasDevicePtr(); } // If SlotNo is zero, automatically assign it. // check slot number if (0 == SlotNo) { SlotNo = LookupEmptySlot(); if (0 == SlotNo) { return CNdasDevicePtr(); } } else if (SlotNo > m_dwMaxSlotNo) { ::SetLastError(NDASSVC_ERROR_INVALID_SLOT_NUMBER); return CNdasDevicePtr(); } // check and see if the slot is occupied if (m_slotbit[SlotNo]) { ::SetLastError(NDASSVC_ERROR_SLOT_ALREADY_OCCUPIED); return CNdasDevicePtr(); } // find an duplicate address { CNdasDevicePtr pExistingDevice = Find(DeviceId); if (0 != pExistingDevice.get()) { ::SetLastError(NDASSVC_ERROR_DUPLICATE_DEVICE_ENTRY); return CNdasDevicePtr(); } } // register CNdasDevicePtr pDevice(new CNdasDevice(SlotNo, DeviceId, RegFlags, NdasIdExtension)); if (0 == pDevice.get()) { // memory allocation failed // No need to set error here! return CNdasDevicePtr(); } BOOL fSuccess = pDevice->Initialize(); if (!fSuccess) { XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_ERROR, "Device initialization failed, error=0x%X\n", GetLastError()); return CNdasDevicePtr(); } m_slotbit[SlotNo] = true; bool insertResult; XTLVERIFY( m_deviceSlotMap.insert(std::make_pair(SlotNo, pDevice)).second ); //DeviceSlotMap::value_type(SlotNo, pDevice)).second; XTLVERIFY( m_deviceIdMap.insert(std::make_pair(DeviceId, pDevice)).second ); //DeviceIdMap::value_type(DeviceId, pDevice)).second; XTLASSERT(m_deviceSlotMap.size() == m_deviceIdMap.size()); // // When NdasIdExtension is NULL, NDAS_ID_EXTENSION_DEFAULT is assigned already // if (RegFlags & NDAS_DEVICE_REG_FLAG_VOLATILE) { } else { XTL::CStaticStringBuffer<30> containerName(_T("Devices\\%04d"), SlotNo); if (0 != memcmp(&NDAS_ID_EXTENSION_DEFAULT, NdasIdExtension, sizeof(NDASID_EXT_DATA))) { NDAS_DEVICE_ID_REG_DATA regData = {0}; regData.DeviceId = DeviceId; regData.NdasIdExtension = *NdasIdExtension; fSuccess = _NdasSystemCfg.SetSecureValueEx( containerName, _T("DeviceID2"), ®Data, sizeof(regData)); } else { fSuccess = _NdasSystemCfg.SetSecureValueEx( containerName, _T("DeviceID"), &DeviceId, sizeof(DeviceId)); } if (!fSuccess) { XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING, "Writing registration entry to the registry failed at %ls, error=0x%X\n", containerName.ToString(), GetLastError()); } fSuccess = _NdasSystemCfg.SetSecureValueEx( containerName, _T("RegFlags"), &RegFlags, sizeof(RegFlags)); if (!fSuccess) { XTLTRACE2(NDASSVC_NDASDEVICEREGISTRAR, TRACE_LEVEL_WARNING, "Writing registration entry to the registry failed at %ls, error=0x%X\n", containerName.ToString(), GetLastError()); } } // // During bootstrapping, we do not publish this event // Bootstrap process will publish an event later // if (!m_fBootstrapping) { (void) m_service.GetEventPublisher().DeviceEntryChanged(); } return pDevice; }