void NuPlayer::Decoder::configure(const sp<AMessage> &format) { CHECK(mCodec == NULL); AString mime; CHECK(format->findString("mime", &mime)); sp<AMessage> notifyMsg = new AMessage(kWhatCodecNotify, id()); mCSDIndex = 0; for (size_t i = 0;; ++i) { sp<ABuffer> csd; if (!format->findBuffer(StringPrintf("csd-%d", i).c_str(), &csd)) { break; } mCSD.push(csd); } #ifdef QCOM_HARDWARE sp<ABuffer> extendedCSD = ExtendedCodec::getRawCodecSpecificData(format); if (extendedCSD != NULL) { ALOGV("pushing extended CSD of size %d", extendedCSD->size()); mCSD.push(extendedCSD); } sp<ABuffer> aacCSD = ExtendedCodec::getAacCodecSpecificData(format); if (aacCSD != NULL) { ALOGV("pushing AAC CSD of size %d", aacCSD->size()); mCSD.push(aacCSD); } #endif if (mNativeWindow != NULL) { format->setObject("native-window", mNativeWindow); } // Current video decoders do not return from OMX_FillThisBuffer // quickly, violating the OpenMAX specs, until that is remedied // we need to invest in an extra looper to free the main event // queue. bool needDedicatedLooper = !strncasecmp(mime.c_str(), "video/", 6); mFormat = format; mCodec = new ACodec; if (needDedicatedLooper && mCodecLooper == NULL) { mCodecLooper = new ALooper; mCodecLooper->setName("NuPlayerDecoder"); mCodecLooper->start(false, false, ANDROID_PRIORITY_AUDIO); } (needDedicatedLooper ? mCodecLooper : looper())->registerHandler(mCodec); mCodec->setNotificationMessage(notifyMsg); mCodec->initiateSetup(format); }
sp<AMessage> DashPlayer::Decoder::makeFormat(const sp<MetaData> &meta) { CHECK(mCSD.isEmpty()); sp<AMessage> msg; uint32_t type; const void *data; size_t size; CHECK_EQ(convertMetaDataToMessage(meta, &msg), (status_t)OK); int32_t value; if (meta->findInt32(kKeySmoothStreaming, &value)) { msg->setInt32("smooth-streaming", value); } if (meta->findInt32(kKeyIsDRM, &value)) { msg->setInt32("secure-op", 1); } if (meta->findInt32(kKeyRequiresSecureBuffers, &value)) { msg->setInt32("requires-secure-buffers", 1); } if (meta->findInt32(kKeyEnableDecodeOrder, &value)) { msg->setInt32("decodeOrderEnable", value); } if (meta->findData(kKeyAacCodecSpecificData, &type, &data, &size)) { if (size > 0 && data != NULL) { sp<ABuffer> buffer = new ABuffer(size); if (buffer != NULL) { memcpy(buffer->data(), data, size); buffer->meta()->setInt32("csd", true); buffer->meta()->setInt64("timeUs", 0); msg->setBuffer("csd-0", buffer); } else { ALOGE("kKeyAacCodecSpecificData ABuffer Allocation failed"); } } else { ALOGE("Not a valid data pointer or size == 0"); } } mCSDIndex = 0; for (size_t i = 0;; ++i) { sp<ABuffer> csd; if (!msg->findBuffer(StringPrintf("csd-%d", i).c_str(), &csd)) { break; } mCSD.push(csd); } return msg; }
// static std::string JSONReader::FormatErrorMessage(int line, int column, const std::string& description) { if(line || column) { return StringPrintf("Line: %i, column: %i, %s", line, column, description.c_str()); } return description; }
void SfDelegate::setProxy(const char *proxy, int port) { std::string host = proxy; std::string list = ""; MY_LOGI(StringPrintf("setProxy:host=%s,port=%d",host.c_str() ,port).c_str()); gProxyConfigService.get()->UpdateProxySettings(host,list); }
void EventGraphFixer::addEventAfterTargetHappensBefore() { std::string node_id; int num_arcs_added = 0; std::map<std::string, int> m_lastLoc; for (int event_action_id = 0; event_action_id <= m_log->maxEventActionId(); ++event_action_id) { if (m_eventGraph->isNodeDeleted(event_action_id)) continue; const ActionLog::EventAction& op = m_log->event_action(event_action_id); for (size_t i = 0; i < op.m_commands.size(); ++i) { const ActionLog::Command& cmd = op.m_commands[i]; if (cmd.m_cmdType == ActionLog::WRITE_MEMORY) { if (getTargetNodeString(m_vars->getString(cmd.m_location), &node_id)) { m_lastLoc[node_id] = event_action_id; m_log->mutable_event_action(event_action_id)->m_commands[i].m_location = m_vars->addString( StringPrintf("%s-%d", m_vars->getString(cmd.m_location), event_action_id).c_str()); } } else if (cmd.m_cmdType == ActionLog::READ_MEMORY) { if (getTargetNodeString(m_vars->getString(cmd.m_location), &node_id)) { std::map<std::string, int>::const_iterator it = m_lastLoc.find(node_id); if (it != m_lastLoc.end()) { if (m_eventGraph->addArcIfNeeded(it->second, event_action_id)) ++num_arcs_added; m_log->mutable_event_action(event_action_id)->m_commands[i].m_location = m_vars->addString( StringPrintf("%s-%d", m_vars->getString( cmd.m_location), it->second).c_str()); } } } } } printf("Added %d event arcs\n", num_arcs_added); }
// static void HTTPStream::RegisterSocketUser(int s, uid_t uid) { // Lower bits MUST be 0. static const uint64_t kTag = 0xdeadbeef00000000ll; AString line = StringPrintf("t %d %llu %d", s, kTag, uid); int fd = open("/proc/net/xt_qtaguid/ctrl", O_WRONLY); write(fd, line.c_str(), line.size()); close(fd); fd = -1; }
void SfDelegate::readMore(net::URLRequest *request) { while (mNumBytesRead < mNumBytesTotal) { size_t copy = mNumBytesTotal - mNumBytesRead; if (copy > mReadBuffer->size()) { copy = mReadBuffer->size(); } int n; if (request->Read(mReadBuffer, copy, &n)) { MY_LOGV(StringPrintf("Read %d bytes directly.", n).c_str()); CHECK_LE((size_t)n, copy); memcpy((uint8_t *)mDataDestination + mNumBytesRead, mReadBuffer->data(), n); mNumBytesRead += n; if (n == 0) { mAtEOS = true; break; } } else { MY_LOGV("readMore pending read"); if (request->status().status() != net::URLRequestStatus::IO_PENDING) { MY_LOGI(StringPrintf( "Direct read failed w/ status %d\n", request->status().status()).c_str()); mOwner->onReadCompleted(ERROR_IO); return; } return; } } mOwner->onReadCompleted(mNumBytesRead); }
static string SubAddDropResponseMessage(uint8_t code) { switch (code) { case sub_adddrop_already_there: return "You are already there"; case sub_adddrop_error: return "Error Adding or Droppign Sub"; case sub_adddrop_not_allowed: return "Not allowed to add or drop this sub"; case sub_adddrop_not_host: return "This system is not the host"; case sub_adddrop_not_there: return "You were not subscribed to the sub"; case sub_adddrop_ok: return "Add or Drop successful"; default: return StringPrintf("Unknown response code %d", code); } }
void TimeFmt::printCustom(int sec, const char *buf, int bufsize, const char *str_sep, const char *str_seconds, const char *str_minutes, const char *str_hours, const char *str_days) { if (buf == NULL || bufsize == 0) return; char *p = (char *)buf; *p = 0; int days, hours, minutes; String s; if (str_days) { days = sec / (3600*24); sec -= days * (3600*24); if (days != 0) { s += StringPrintf("%d%s", days, str_days); } } if (str_hours) { hours = sec / 3600; sec -= hours * 3600; if (hours != 0) { if (!s.isempty()) s += str_sep; s += StringPrintf("%d%s", hours, str_hours); } } if (str_minutes) { minutes = sec / 60; sec -= minutes * 60; if (minutes != 0) { if (!s.isempty()) s += str_sep; s += StringPrintf("%d%s", minutes, str_minutes); } } if (str_seconds) { if (sec != 0) { if (!s.isempty()) s += str_sep; s += StringPrintf("%d%s", sec, str_seconds); } } STRNCPY(p, s.getValue(), bufsize); int l = s.len(); if (l < bufsize) p[l] = 0; }
// Constructor Firnplayer::Player::Player() { ConfigDir = cleanpath(HomePath() + "/.firnplayer"); ConfigFile = cleanpath(ConfigDir + "/Configuration.json"); TrackInfoFile = cleanpath(ConfigDir + "/TrackInfo.json"); ThePlayer = this; // Check if Config path exists and make if not. if(!FileExists(ConfigDir)) { std::printf("Config folder %s does not exist, creating.\n", ConfigDir.c_str()); boost::filesystem::create_directory(ConfigDir); if(!FileExists(ConfigDir)) { FatalErrorString = StringPrintf("Could not create directory %s, aborting\n", ConfigDir.c_str()); } } // Load and sanitize config file. if(FileExists(ConfigFile)) { std::printf("Reading Config\n"); LoadJson(ConfigFile, Options); } SanitizeConfig(); ActiveViewPort = ACTIVE_ARTISTS; // Set the frame colours ArtistView.SetFrameColPair(COLPAIR_FRAME); TrackView.SetFrameColPair(COLPAIR_FRAME); QueueView.SetFrameColPair(COLPAIR_FRAME); PlaylistView.SetFrameColPair(COLPAIR_FRAME); // Load track info if it exists. std::string TrackDBPath = cleanpath(ConfigDir + "/TrackInfo.Json"); if(FileExists(TrackDBPath)) { std::printf("Loading Track Info\n"); if(!LoadJson(TrackDBPath, TrackList)) // No queue lock. No other threads should be running. { std::printf("Stored track info file corrupt, starting empty.\n"); } else { Threads["Sorter"] = std::thread(Sortfunction, std::ref(Artists), std::ref(ArtistsQueue), std::ref(TrackList), std::ref(TrackListQueue)); } } Running = 1; }
std::string os_version_string() { #if defined ( __linux__ ) File info("/proc/sys/kernel", "osrelease"); if (info.Exists()) { FILE *kernel_file; struct k_version { unsigned major, minor, update, iteration; }; struct k_version k_version; kernel_file = fopen("/proc/sys/kernel/osrelease","r"); fscanf(kernel_file,"%u%*c%u%*c%u%*c%u", &k_version.major, &k_version.minor, &k_version.update, &k_version.iteration); fclose(kernel_file); char osrelease[100]; sprintf(osrelease,"%u.%u.%u-%u", k_version.major, k_version.minor, k_version.update, k_version.iteration); info.Close(); return StringPrintf("Linux %s", osrelease); } return std::string("Linux"); #elif defined ( __APPLE__ ) return string("MacOSX"); // StringPrintf("%s %s", GetOSNameString(), GetMacVersionString()); #elif defined(__OS2__) return string("OS/2"); #elif defined(__FreeBSD__) return string("FreeBSD"); #elif defined(__OpenBSD__) return string("OpenBSD"); #elif defined(__NetBSD__) return string("NetBSD"); #elif defined(BSD) return string("BSD"); #elif defined(__solaris__) return string("Solaris"); #elif defined(__sun__) return string("SunOS"); #elif defined(__gnu__) return string("GNU/Hurd"); #elif defined(__QNX__) return string("QNX"); #elif defined(__unix__) return string("UNIX"); #elif defined(__HAIKU__) return string("Haiku"); #endif return string("UNKNOWN OS"); }
String UrlParse::getString() const { String ret; ret.printf("%s://%s", protocol.vs(), hostname.vs()); if (port != 80 && port != 0) ret.cat(StringPrintf(":%d", port)); if (!path.isempty()) { if (path.firstChar() != '/') ret.cat("/"); ret.cat(path); } if (!resource.isempty()) { if (resource.firstChar() != '/') ret.cat("/"); ret.cat(resource); } return ret; }
bool handle_sub_add_drop_resp(Context& context, Packet& p, const std::string& add_or_drop) { // We want to stop at the 1st \0 string subname = p.text.c_str(); StringTrimEnd(&subname); auto b = p.text.begin(); while (b != p.text.end() && *b != '\0') { b++; } if (b == p.text.end()) { LOG(INFO) << "Unable to determine code from add_drop response."; return false; } // NULL b++; if (b == p.text.end()) { LOG(INFO) << "Unable to determine code from add_drop response."; return false; } LOG(INFO) << "Processed " << add_or_drop << " response from system @" << p.nh.fromsys << " to subtype: " << subname; char code = *b++; string code_string = SubAddDropResponseMessage(static_cast<uint8_t>(code)); string message_text = string(b, p.text.end()); net_header_rec nh = {}; string title = StringPrintf("WWIV AreaFix (%s) Response for subtype '%s'", context.net.name, subname.c_str()); string byname = StringPrintf("WWIV AreaFix (%s) @%u", context.net.name, p.nh.fromsys); string body = StringPrintf("SubType '%s', (%s) Response: '%s'\r\n%s\r\n", subname.c_str(), add_or_drop.c_str(), code_string.c_str(), message_text.c_str()); nh.touser = 1; nh.fromuser = std::numeric_limits<uint16_t>::max(); nh.main_type = main_type_email; nh.daten = wwiv::sdk::time_t_to_daten(time(nullptr)); const string filename = create_pend(context.net.dir, true, static_cast<char>('0' + context.network_number)); return send_network_email(filename, context.net, nh, {}, body, byname, title); }
bool NotificationBackendLibnotify::init() { bindtextdomain (GETTEXT_PACKAGE, SYNCEVOLUTION_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #ifdef NOTIFY_COMPATIBILITY void *dlhandle = NULL; int i; for (i = 1; i <= 4; i++) { dlhandle = dlopen(StringPrintf("libnotify.so.%d", i).c_str(), RTLD_LAZY|RTLD_GLOBAL); if (!dlhandle) { SE_LOG_DEBUG(NULL, NULL, "failed to load libnotify.so.%d: %s", i, dlerror()); } else { break; } } if (!dlhandle) { return false; } #define LOOKUP(_x) ((_x = reinterpret_cast<typeof(_x)>(dlsym(dlhandle, #_x))) || \ NotFound(#_x)) if (!LOOKUP(notify_init) || !LOOKUP(notify_get_server_caps) || !LOOKUP(notify_notification_new) || !LOOKUP(notify_notification_add_action) || !LOOKUP(notify_notification_clear_actions) || !LOOKUP(notify_notification_close) || !LOOKUP(notify_notification_show)) { return false; } SE_LOG_DEBUG(NULL, NULL, "using libnotify.so.%d", i); #endif m_initialized = notify_init("SyncEvolution"); if(m_initialized) { GStringListFreeCXX list(notify_get_server_caps()); BOOST_FOREACH (const char *cap, list) { if(boost::iequals(cap, "actions")) { m_acceptsActions = true; } } return true; } return false; }
virtual std::string getOAuth2Bearer(const PasswordUpdateCallback &passwordUpdateCallback) { SE_LOG_DEBUG(NULL, "retrieving OAuth2 token"); if (!m_accessToken.empty() && !m_invalidateCache) { return m_accessToken; } // Retry login if even the refreshed token failed. g_hash_table_insert(m_sessionData, g_strdup("ForceTokenRefresh"), g_variant_ref_sink(g_variant_new_boolean(m_invalidateCache))); // We get assigned a plain pointer to an instance that we'll own, // so we have to use the "steal" variant to enable that assignment. GVariantStealCXX resultDataVar; GErrorCXX gerror; GVariantCXX sessionDataVar(HashTable2Variant(m_sessionData)); PlainGStr buffer(g_variant_print(sessionDataVar, true)); SE_LOG_DEBUG(NULL, "asking for OAuth2 token with method %s, mechanism %s and parameters %s", signon_auth_session_get_method(m_authSession), m_mechanism.c_str(), buffer.get()); #define signon_auth_session_process_async_finish signon_auth_session_process_finish SYNCEVO_GLIB_CALL_SYNC(resultDataVar, gerror, signon_auth_session_process_async, m_authSession, sessionDataVar, m_mechanism.c_str(), NULL); buffer.reset(resultDataVar ? g_variant_print(resultDataVar, true) : NULL); SE_LOG_DEBUG(NULL, "OAuth2 token result: %s, %s", buffer.get() ? buffer.get() : "<<null>>", gerror ? gerror->message : "???"); if (!resultDataVar || gerror) { SE_THROW_EXCEPTION_STATUS(StatusException, StringPrintf("could not obtain OAuth2 token: %s", gerror ? gerror->message : "???"), STATUS_FORBIDDEN); } GHashTableCXX resultData(Variant2HashTable(resultDataVar)); GVariant *tokenVar = static_cast<GVariant *>(g_hash_table_lookup(resultData, (gpointer)"AccessToken")); if (!tokenVar) { SE_THROW("no AccessToken in OAuth2 response"); } std::string newToken = g_variant_get_string(tokenVar, NULL); if (newToken.empty()) { SE_THROW("AccessToken did not contain a string value"); } else if (m_invalidateCache && newToken == m_accessToken) { SE_THROW("Got the same invalid AccessToken"); } m_accessToken = newToken; return m_accessToken; }
// static void WifiDisplaySource::AppendCommonResponse( AString *response, int32_t cseq, int32_t playbackSessionID) { time_t now = time(NULL); struct tm *now2 = gmtime(&now); char buf[128]; strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S %z", now2); response->append("Date: "); response->append(buf); response->append("\r\n"); response->append("Server: Mine/1.0\r\n"); if (cseq >= 0) { response->append(StringPrintf("CSeq: %d\r\n", cseq)); } if (playbackSessionID >= 0ll) { response->append( StringPrintf( "Session: %d;timeout=%lld\r\n", playbackSessionID, kPlaybackSessionTimeoutSecs)); } }
void SfDelegate::OnReadCompleted(net::URLRequest *request, int bytes_read) { if (bytes_read == -1) { MY_LOGI(StringPrintf( "OnReadCompleted, read failed, status %d", request->status().status()).c_str()); mOwner->onReadCompleted(ERROR_IO); return; } MY_LOGV(StringPrintf("OnReadCompleted, read %d bytes", bytes_read).c_str()); if (bytes_read < 0) { MY_LOGI(StringPrintf( "Read failed w/ status %d\n", request->status().status()).c_str()); mOwner->onReadCompleted(ERROR_IO); return; } else if (bytes_read == 0) { mAtEOS = true; mOwner->onReadCompleted(mNumBytesRead); return; } CHECK_GT(bytes_read, 0); CHECK_LE(mNumBytesRead + bytes_read, mNumBytesTotal); memcpy((uint8_t *)mDataDestination + mNumBytesRead, mReadBuffer->data(), bytes_read); mNumBytesRead += bytes_read; readMore(request); }
void SfNetLog::AddEntry( EventType type, const base::TimeTicks &time, const Source &source, EventPhase phase, EventParameters *params) { #if 0 MY_LOGI(StringPrintf( "AddEntry time=%s type=%s source=%s phase=%s\n", TickCountToString(time).c_str(), EventTypeToString(type), SourceTypeToString(source.type), EventPhaseToString(phase)).c_str()); #endif }
int main(int argc, const char** argv) { InitStatics(); Context context; Res res; res = context.ProcessArgs(argc, argv); ExitIfError(res, context); string absolute_root; string canonical_currdir; res = FindRoot(&absolute_root, &canonical_currdir); ExitIfError(res, context); context.LogVerbose(StringPrintf("absolute_root = %s\n", absolute_root.c_str())); context.LogVerbose(StringPrintf("canonical_currdir = %s\n", canonical_currdir.c_str())); res = context.Init(absolute_root, canonical_currdir); ExitIfError(res, context); assert(context.GetConfig()); context.Log(StringPrintf("dmb config: %s\n", context.GetConfig()->name().c_str())); res = context.Resolve(); ExitIfError(res, context); res = context.ProcessTargets(); ExitIfError(res, context); context.Log("dmb OK\n"); return 0; }
//通过NetBIOS获取MAC地址 bool GetMacAddressByNetBIOS(std::string &mac_address) { ASTAT Adapter; NCB Ncb; UCHAR uRetCode; LANA_ENUM lenum; int i; memset(&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBENUM; Ncb.ncb_buffer = (UCHAR *)&lenum; Ncb.ncb_length = sizeof(lenum); uRetCode = Netbios(&Ncb); for (i=0; i < lenum.length; ++i) { memset(&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBRESET; Ncb.ncb_lana_num = lenum.lana[i]; uRetCode = Netbios(&Ncb); memset(&Ncb, 0, sizeof(Ncb)); Ncb.ncb_command = NCBASTAT; Ncb.ncb_lana_num = lenum.lana[i]; strcpy((char *)Ncb.ncb_callname, "* "); Ncb.ncb_buffer = (unsigned char *)&Adapter; Ncb.ncb_length = sizeof(Adapter); uRetCode = Netbios(&Ncb); if (uRetCode == 0) { if (Adapter.adapt.adapter_address[0]+ Adapter.adapt.adapter_address[1]+ Adapter.adapt.adapter_address[2]+ Adapter.adapt.adapter_address[3]+ Adapter.adapt.adapter_address[4]+ Adapter.adapt.adapter_address[5]!=0) { StringPrintf(mac_address, "%02x-%02x-%02x-%02x-%02x-%02x", Adapter.adapt.adapter_address[0], Adapter.adapt.adapter_address[1], Adapter.adapt.adapter_address[2], Adapter.adapt.adapter_address[3], Adapter.adapt.adapter_address[4], Adapter.adapt.adapter_address[5]); return true; } } } return false; }
string net_info_minor_type_name(int typ) { switch (typ) { case net_info_general_message: return "net_info_general_message"; case net_info_bbslist: return "net_info_bbslist"; case net_info_connect: return "net_info_connect"; case net_info_sub_lst: return "net_info_sub_lst"; case net_info_wwivnews: return "net_info_wwivnews"; case net_info_fbackhdr: return "net_info_fbackhdr"; case net_info_more_wwivnews: return "net_info_more_wwivnews"; case net_info_categ_net: return "net_info_categ_net"; case net_info_network_lst: return "net_info_network_lst"; case net_info_file: return "net_info_file"; case net_info_binkp: return "net_info_binkp"; default: return StringPrintf("UNKNOWN type #%d", typ); } }
bool ExpectClose(double x, double y, double max_abs_relative_difference) { double absolute_difference = fabs(x - y); double relative_difference = absolute_difference / std::max(fabs(x), fabs(y)); if (x == 0 || y == 0) { // If x or y is exactly zero, then relative difference doesn't have any // meaning. Take the absolute difference instead. relative_difference = absolute_difference; } if (relative_difference > max_abs_relative_difference) { VLOG(1) << StringPrintf("x=%17g y=%17g abs=%17g rel=%17g", x, y, absolute_difference, relative_difference); } EXPECT_NEAR(relative_difference, 0.0, max_abs_relative_difference); return relative_difference <= max_abs_relative_difference; }
string GetMacAddress() { int fd; // Socket descriptor struct ifreq sIfReq; // Interface request struct if_nameindex *pIfList; // Ptr to interface name index struct if_nameindex *pListSave; // Ptr to interface name index //// Initialize this function pIfList = (struct if_nameindex *)NULL; pListSave = (struct if_nameindex *)NULL; // Create a socket that we can use for all of our ioctls fd = socket( PF_INET, SOCK_STREAM, 0 ); if ( fd < 0 ) { // Socket creation failed, this is a fatal error LOG(WARNING) << "Create socket fail"; return ""; } // Obtain a list of dynamically allocated structures pIfList = pListSave = if_nameindex(); // // Walk thru the array returned and query for each interface's // address // for (pIfList; *(char *)pIfList != 0; pIfList++ ) { strncpy( sIfReq.ifr_name, pIfList->if_name, IF_NAMESIZE ); // Get the MAC address for this interface if (ioctl(fd, SIOCGIFHWADDR, &sIfReq) != 0) { // We failed to get the MAC address for the interface LOG(WARNING) << pIfList->if_name << " Ioctl fail:" << strerror(errno); continue; } uint8 *mac_addr = reinterpret_cast<uint8*>(sIfReq.ifr_ifru.ifru_hwaddr.sa_data); if (mac_addr[0] == 0 && mac_addr[1] == 0 && mac_addr[2] == 0 && mac_addr[3] == 0 && mac_addr[4] == 0 && mac_addr[5] == 0) { VLOG(2) << pIfList->if_name << " haven't mac address"; continue; } string str_mac_address = StringPrintf("%02x:%02x:%02x:%02x:%02x:%02x", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); VLOG(2) << pIfList->if_name << " mac address : " << str_mac_address; if_freenameindex(pListSave); close(fd); return str_mac_address; } if_freenameindex(pListSave); close(fd); return ""; }
std::string create_pend(const string& directory, bool local, char network_app_id) { uint8_t prefix = (local) ? 0 : 1; for (int i = 0; i < 1000; i++) { const string filename = StringPrintf("p%u-%c-%d.net", prefix, network_app_id, i); File f(directory, filename); if (f.Exists()) { continue; } if (f.Open(File::modeCreateFile | File::modeReadWrite | File::modeExclusive)) { LOG(INFO) << "Created pending file: " << filename; return filename; } } LOG(ERROR) << "all attempts failed to create_pend"; return ""; }
status_t WifiDisplaySource::sendTrigger( int32_t sessionID, TriggerType triggerType) { AString body = "wfd_trigger_method: "; switch (triggerType) { case TRIGGER_SETUP: body.append("SETUP"); break; case TRIGGER_TEARDOWN: ALOGI("Sending TEARDOWN trigger."); body.append("TEARDOWN"); break; case TRIGGER_PAUSE: body.append("PAUSE"); break; case TRIGGER_PLAY: body.append("PLAY"); break; default: TRESPASS(); } body.append("\r\n"); AString request = "SET_PARAMETER rtsp://localhost/wfd1.0 RTSP/1.0\r\n"; AppendCommonResponse(&request, mNextCSeq); request.append("Content-Type: text/parameters\r\n"); request.append(StringPrintf("Content-Length: %d\r\n", body.size())); request.append("\r\n"); request.append(body); status_t err = mNetSession->sendRequest(sessionID, request.c_str(), request.size()); if (err != OK) { return err; } registerResponseHandler( sessionID, mNextCSeq, &WifiDisplaySource::onReceiveM5Response); ++mNextCSeq; return OK; }
//通过GetAdaptersInfo函数(适用于Windows 2000及以上版本) bool GetMacAddressByAdaptersInfo(std::string &mac_address) { bool ret = false; ULONG out_buf_len = sizeof(IP_ADAPTER_INFO); PIP_ADAPTER_INFO adapter_info = (IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO)); if(adapter_info == NULL) return false; // Make an initial call to GetAdaptersInfo to get the necessary size into the out_buf_len variable if(GetAdaptersInfo(adapter_info, &out_buf_len) == ERROR_BUFFER_OVERFLOW) { free(adapter_info); adapter_info = (IP_ADAPTER_INFO *)malloc(out_buf_len); if (adapter_info == NULL) return false; } if(GetAdaptersInfo(adapter_info, &out_buf_len) == NO_ERROR) { PIP_ADAPTER_INFO adapter = adapter_info; for(; adapter != NULL; adapter = adapter->Next) { // 确保是以太网 if(adapter->Type != MIB_IF_TYPE_ETHERNET) continue; // 确保MAC地址的长度为 00-00-00-00-00-00 if(adapter->AddressLength != 6) continue; StringPrintf(mac_address, "%02x-%02x-%02x-%02x-%02x-%02x", int (adapter->Address[0]), int (adapter->Address[1]), int (adapter->Address[2]), int (adapter->Address[3]), int (adapter->Address[4]), int (adapter->Address[5])); ret = true; break; } } free(adapter_info); return ret; }
static void printWaitMessage(const DebugOutputTarget* target, const char* detail, Object* obj, Thread* thread) { std::string msg(StringPrintf(" - waiting %s <%p> ", detail, obj)); if (obj->clazz != gDvm.classJavaLangClass) { // I(16573) - waiting on <0xf5feda38> (a java.util.LinkedList) // I(16573) - waiting on <0xf5ed54f8> (a java.lang.Class<java.lang.ref.ReferenceQueue>) msg += "(a " + dvmHumanReadableType(obj) + ")"; } if (thread != NULL) { std::string threadName(dvmGetThreadName(thread)); StringAppendF(&msg, " held by tid=%d (%s)", thread->threadId, threadName.c_str()); } dvmPrintDebugMessage(target, "%s\n", msg.c_str()); }
static void createFileSource( const AString &addr, int32_t port, const char *path) { sp<ANetworkSession> session = new ANetworkSession; session->start(); sp<ALooper> looper = new ALooper; looper->start(); sp<RemoteDisplayClient> client = new RemoteDisplayClient; sp<WifiDisplaySource> source = new WifiDisplaySource(session, client, path); looper->registerHandler(source); AString iface = StringPrintf("%s:%d", addr.c_str(), port); CHECK_EQ((status_t)OK, source->start(iface.c_str())); client->waitUntilDone(); source->stop(); }
//通过GetAdaptersAddresses函数(适用于Windows XP及以上版本) bool GetMacAddressByAdaptersAddresses(std::string &mac_address) { bool ret = false; ULONG out_buf_len = sizeof(IP_ADAPTER_ADDRESSES); PIP_ADAPTER_ADDRESSES addresses = (IP_ADAPTER_ADDRESSES*)malloc(out_buf_len); if (addresses == NULL) return false; // Make an initial call to GetAdaptersAddresses to get the necessary size into the ulOutBufLen variable if(GetAdaptersAddresses(AF_UNSPEC, 0, NULL, addresses, &out_buf_len) == ERROR_BUFFER_OVERFLOW) { free(addresses); addresses = (IP_ADAPTER_ADDRESSES*)malloc(out_buf_len); if (addresses == NULL) return false; } if(GetAdaptersAddresses(AF_UNSPEC, 0, NULL, addresses, &out_buf_len) == NO_ERROR) { // If successful, output some information from the data we received PIP_ADAPTER_ADDRESSES curr_addresses = addresses; for(; curr_addresses != NULL; curr_addresses = curr_addresses->Next) { // 确保MAC地址的长度为 00-00-00-00-00-00 if(curr_addresses->PhysicalAddressLength != 6) continue; StringPrintf(mac_address, "%02x-%02x-%02x-%02x-%02x-%02x", int (curr_addresses->PhysicalAddress[0]), int (curr_addresses->PhysicalAddress[1]), int (curr_addresses->PhysicalAddress[2]), int (curr_addresses->PhysicalAddress[3]), int (curr_addresses->PhysicalAddress[4]), int (curr_addresses->PhysicalAddress[5])); ret = true; break; } } free(addresses); return ret; }
void rename_pend(const string& directory, const string& filename, uint8_t network_app_num) { File pend_file(directory, filename); if (!pend_file.Exists()) { LOG(INFO) << " pending file does not exist: " << pend_file; return; } const string pend_filename(pend_file.full_pathname()); const string num = filename.substr(1); const string prefix = (atoi(num.c_str())) ? "1" : "0"; for (int i = 0; i < 1000; i++) { const string new_filename = StringPrintf("%sp%s-%u-%u.net", directory.c_str(), prefix.c_str(), network_app_num, i); if (File::Rename(pend_filename, new_filename)) { LOG(INFO) << "renamed file to: " << new_filename; return; } } LOG(ERROR) << "all attempts failed to rename_wwivnet_pend"; }