Created
January 10, 2011 02:03
-
-
Save jasonsirota/772247 to your computer and use it in GitHub Desktop.
ideas for message passing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum HostMessageEnum | |
{ | |
SendRequestHeader, | |
SendRequestHeadersComplete, | |
SendRequestBodyStart, | |
SendRequestBodyPart, | |
SendRequestBodyComplete, | |
BeginGetResponse, | |
Error | |
} | |
public enum AppMessageEnum | |
{ | |
SendResponseHeader, | |
SendResponseHeadersComplete, | |
SendResponseStatus, | |
SendResponseBodyStart, | |
SendResponseBodyPart, | |
SendResponseBodyComplete, | |
Error | |
} | |
public class Host | |
{ | |
public Func<HostMessageEnum op, object data, bool received> SendMessageToApp; | |
public Host() { | |
//Register Listen function delegate here | |
SendMessageToApp = new App(Listen).Create() /* Listen is a delegate for Listen below */; | |
} | |
public bool Listen(AppMessageEnum op, object data) | |
{ | |
switch(op) { | |
case SendResponseHeader: | |
var header = data as KeyValuePair<string,string>; | |
if(header == null) { | |
SendMessagetoApp(HostMessageEnum.Error, | |
new Exception("data in message did not conform to this operation")); | |
return false; | |
} | |
//spin out another thread here that writes headers to the socket | |
//passing SendMessageToApp around | |
return true; | |
} | |
} | |
} | |
public class App | |
{ | |
public Func<AppMessageEnum op, object data, bool received> SendMessageToHost; | |
public App(Action<AppMessageEnum op, object data> delegate) { | |
SendMessageToHost = delegate; | |
} | |
public Func<HostMessageEnum op, object data, bool received> Create() { | |
return Listen //delegate for Listen below | |
} | |
public bool Listen(HostMessageEnum op, object data) | |
{ | |
switch(op) { | |
case BeginGetResponse: | |
//spin out another thread that sends headers | |
//host and body parts to the host message passing | |
//SendMessageToHost around | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment