[代码共享] 在Windows Mobile上监听Radio Interface Layer Notification
[CODE]
//------------------------------------------------------------------------
// <copyright file="RilSpy.cs" company="Yaping Xin">
// Copyright (c) Yaping Xin. All rights reserved.
// </copyright>
// <Description>Listen to the Radio Interface Layer</Description>
//------------------------------------------------------------------------
namespace RilSpyNet
{
using System;
using RilNET;
/// <summary>
/// Listen to the Radio Interface Layer, get events
/// </summary>
public class RilSpy
{
/// <summary>
/// Delegation definition of Log event handler
/// </summary>
/// <param name="message">Message to transfer</param>
public delegate void LogHandler(string message);
/// <summary>Event handler to record log</summary>
public event LogHandler Log;
/// <summary>Output handler</summary>
private IntPtr hRil;
/// <summary>
/// Start the listener
/// </summary>
public void Run()
{
int hr = Ril.Initialize(1, new RILRESULTCALLBACK(this.RilResultCallback), new RILNOTIFYCALLBACK(this.RilNotifyCallback), RIL_NCLASS.ALL, 0, out hRil);
}
/// <summary>
/// Record the message
/// </summary>
/// <param name="message">Message to transfer</param>
protected void OnLog(string message)
{
if (this.Log != null)
{
this.Log(message);
}
}
private void RilResultCallback(uint dwCode, int hrCmdID, IntPtr lpData, uint cbData, uint dwParam)
{
this.CallBackProc("RilResultCallback", dwCode, lpData, cbData, dwParam);
}
private void RilNotifyCallback(uint dwCode, IntPtr lpData, uint cbData, uint dwParam)
{
this.CallBackProc("RilNotifyCallback", dwCode, lpData, cbData, dwParam);
}
private void CallBackProc(string notifyTitle, uint dwCode, IntPtr lpData, uint cbData, uint dwParam)
{
RIL_NCLASS dwClass = ((RIL_NCLASS)dwCode & RIL_NCLASS.ALL);
string message = string.Format("{0} - dwCode: {1}, RIL_NCLASS: {2}", notifyTitle, dwCode, dwClass);
switch (dwClass)
{
case RIL_NCLASS.CALLCTRL:
RIL_NOTIFY_CALLCTR callControl = (RIL_NOTIFY_CALLCTR)dwCode;
message += string.Format(", CALLCTR: {0}", callControl);
break;
case RIL_NCLASS.RADIOSTATE:
RIL_NOTIFY_RADIOSTATE dwRadioState = (RIL_NOTIFY_RADIOSTATE)dwCode;
message += string.Format(", RADIOSTATE: {0}", dwRadioState);
break;
default:
break;
}
this.OnLog(message);
}
}
}
[/CODE]