Blog A simple blog based on Jekyll

Print ATL/MFC internal traces in Visual Studio 2012/2015/2017

Prior Visual Studio 2012, Microsoft provided a tool ATL/MFC Trace Tool to output trace messages in Visual Studio’s output debugging window.

ATLMFCTraceTool To use the ATL/MFC Trace Tool,

  • Open an MFC or an ATL project.
  • On the Debug menu, click Start Debugging.
  • On the Tools menu, click ATL/MFC Trace Tool.

However this tool is removed from VS2012, and missing atldebugapi.h if build from source.

I figured out that there is a major change in ATL/MFC after reading the source code. Add the following code in your code, e.g. CWinApp::InitInstance(), will enable full traces:

ATL::CTrace::SetCategories(ATL::CTrace::EnableAllCategories);
ATL::CTrace::SetLevel(ATL::CTrace::DisableTracing - 1);

Fix monitor with broken EDID

Issue description

Monitor’s EDID is damaged and Ubuntu is running at lower resolution

How to fix

  1. Read timing from a working monitor (same mode)
    sudo get-edid | parse-edid
    
  2. Create a new script /etc/lightdm/video-mode with desired timing
    #!/bin/sh
    
    /usr/bin/xrandr --newmode FHD 148.50 1920 2008 2052 2200 1080 1084 1089 1125 +hsync +vsync
    /usr/bin/xrandr --addmode DisplayPort-0 FHD
    
  3. Add the following line at the end of /etc/lightdm/lightdm.conf to autoload the timing
    display-setup-script=/etc/lightdm/video-mode
    

Microsoft OS descriptors

OS support

  • Microsoft OS 1.0 Descriptors are supported by:
    • Windows 8.1
    • Windows 8
    • Windows 7
    • Windows Vista, Windows Server 2008
    • Windows XP with Service Pack 1 (SP1), Windows Server 2003
  • Microsoft OS 2.0 Descriptors are supported by Windows 8.1 onwards

String Descriptor Request

  • Index: 0xEE, langid: 0
  • u”MSFT100?”, ? is bMS_VendorCode, which will be used for subsequent OS feature vendor request

OS Feature descriptor

  • Genre (0x1)
    • Used by HID devices to provide detailed configuration data. - Not implemented
  • Extended Compact ID (0x4), e.g. “WINUSB”, “RNDIS”
  • Extended Properties (0x5), e.g. URLs, icons, help pages, GUIDs
    • Class level
    • devnode level

Debugging

  • The OS only query 0xEE once
  • Make sure the length of CID descriptor is 0x28 for single interface configuration

Essential Javascript

ECMAScript

  • Javascript is also evolving over the years, the latest revision is ES6 (June 2015)
  • Regex/exception added in ES3, strict mode/json/reflection added in ES5
  • ES6: iterators, generators, binary data, arrow functions, typed arrays, collections, promises, proxies (metaprogramming for virtual objects and wrappers)

Electron Overview

Basic Electron app structure

  • html: page to render
  • js: starts the app and creates a browser window to render HTML
  • package.json: Points to the app’s js file and lists its details and dependencies

Google Cloud Messaging

System Architecture

Notifications vs data messages

Feature Notifications Data Messages
Size <=2KB <=4KB
Collapsible Forced default no
Notification tray True False

Messaging options

  • High priorty message will wake a sleeping device when possible
  • set time_to_live = 0 means messages that can’t be delivered immediately will be discarded

Topics

  • 2KB limit
  • Path must mathces regex /topics/[a-zA-Z0-9-_.~%]+
  • “to” field will set to topic path instead of registration token
  • registration token is not needed

Device Groups

  • Typically, “group” refers a set of different devices that belong to a single user
  • 2KB for iOS, 4KB for other platforms
  • registration token is needed
  • Group registration tokens by notification_key
  • Maximum number of member for each notication_key is 20

GCM Client

GCM XMPP server

  • XMPP connection server reference
  • XMPP app server sample
  • production: gcm-xmpp.googleapis.com:5235
  • testing: gcm-preprod.googleapis.com:5236
  • 1000 connections in parallel for each sender ID
  • CCS may send CONNECTION_DRAINING message to indicate that the connection is being drained and will be closed soon
  • delivery_receipt_requested is for Downstream only?
  • Flow control
    • Every message sent to CCS receives either an ACK or a NACK response.
    • Messages that haven’t received one of these responses are considered pending.
    • If the pending message count reaches 100, the app server should stop sending new messages and wait for CCS to acknowledge

HTTP vs XMPP

Feature HTTP XMPP
Direction Downstream only Both
Call Synchronous Asynchronous
Json HTTP Post encapsulated in XMPP
Multicast downstream Supported Not supported

Android Dev Best Practice

IntentService will create worker thread automatically for you

  • Set android:exported="false" flag if the service is only used locally
  • Broadcast could be used to notify back the caller, prefer LocalBroadcastManager to send broadcast

Repack Android image

  • ext2simg system.ext4 system.img.ext4