/[pcsx2_0.9.7]/trunk/tools/GSDumpGUI/Library/TCPLibrary/Message/TCPMessage.cs
ViewVC logotype

Contents of /trunk/tools/GSDumpGUI/Library/TCPLibrary/Message/TCPMessage.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (show annotations) (download)
Sat Dec 25 02:51:30 2010 UTC (9 years ago) by william
File size: 3872 byte(s)
Auto Commited Import of: pcsx2-0.9.7-DEBUG (upstream: v0.9.7.4139 local: v0.9.7.283-latest) in ./trunk
1 /*
2 The MIT License
3
4 Copyright (c) 2008 Ferreri Alessio
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy
7 of this software and associated documentation files (the "Software"), to deal
8 in the Software without restriction, including without limitation the rights
9 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 copies of the Software, and to permit persons to whom the Software is
11 furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 THE SOFTWARE.
23 */
24
25 using System;
26 using System.Collections.Generic;
27 using System.Xml.Serialization;
28 using System.IO;
29 using System.Runtime.Serialization.Formatters.Binary;
30
31 namespace TCPLibrary.MessageBased.Core
32 {
33 /// <summary>
34 /// Message structure that contains all the information of the message exchanged between
35 /// Message driven server/client.
36 /// </summary>
37 [Serializable]
38 public class TCPMessage
39 {
40 /// <summary>
41 /// Message Type.
42 /// </summary>
43 private MessageType _messageType;
44 /// <summary>
45 /// Messages parameters.
46 /// </summary>
47 private List<object> _parameters;
48
49 /// <summary>
50 /// Get/set the message type.
51 /// </summary>
52 public MessageType MessageType
53 {
54 get { return _messageType; }
55 set { _messageType = value; }
56 }
57
58 /// <summary>
59 /// Get/set the message parameters.
60 /// </summary>
61 public List<object> Parameters
62 {
63 get { return _parameters; }
64 }
65
66 /// <summary>
67 /// Base constructor of the class.
68 /// </summary>
69 public TCPMessage()
70 {
71 _messageType = MessageType.Connect;
72 _parameters = new List<object>();
73 }
74
75 /// <summary>
76 /// Parse a string and create a Message structure.
77 /// </summary>
78 /// <param name="data">Raw data.</param>
79 /// <returns>Parsed message structure.</returns>
80 static public TCPMessage FromByteArray(byte[] data)
81 {
82 MemoryStream ms = new MemoryStream();
83 BinaryWriter sw = new BinaryWriter(ms);
84 sw.Write(data, 0, data.Length);
85 sw.Flush();
86 ms.Position = 0;
87
88 BinaryFormatter formatter = new BinaryFormatter();
89 TCPMessage msg = formatter.Deserialize(ms) as TCPMessage;
90
91 return msg;
92 }
93
94 /// <summary>
95 /// Trasform the structure into a String.
96 /// </summary>
97 /// <returns>The structure in a String format.</returns>
98 public byte[] ToByteArray()
99 {
100 MemoryStream ms = new MemoryStream();
101 BinaryFormatter formatter = new BinaryFormatter();
102 formatter.Serialize(ms, this);
103 ms.Position = 0;
104 return ms.ToArray();
105 }
106 }
107
108 public enum MessageType
109 {
110 Connect,
111 MaxUsers,
112 SizeDump,
113 Statistics,
114 StateOld,
115
116 GetDebugMode,
117 SetDebugMode,
118 DebugState,
119 PacketInfo,
120
121 Step,
122 RunToCursor,
123 RunToNextVSync
124 }
125 }

  ViewVC Help
Powered by ViewVC 1.1.22