Skip to content

Commit 03dbd23

Browse files
author
Pang Wu
committed
We don't need these interfaces anymore. We can send message without these interfaces when defined as abstract. (reverse-merged from commit 5d71efb)
1 parent 5d71efb commit 03dbd23

11 files changed

+130
-18
lines changed

MSNPSharp/Core/IMessageHandler.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#region
2+
/*
3+
Copyright (c) 2002-2012, Bas Geertsema, Xih Solutions
4+
(http://www.xihsolutions.net), Thiago.Sayao, Pang Wu, Ethem Evlice, Andy Phan, Chang Liu.
5+
All rights reserved. http://code.google.com/p/msnp-sharp/
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the names of Bas Geertsema or Xih Solutions nor the names of its
16+
contributors may be used to endorse or promote products derived from this
17+
software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29+
THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
#endregion
32+
33+
using System;
34+
35+
namespace MSNPSharp.Core
36+
{
37+
/// <summary>
38+
/// IMessageHandler defines the methods required to handle incoming network messages.
39+
/// </summary>
40+
public interface IMessageHandler
41+
{
42+
/// <summary>
43+
/// Gets or sets the processor of network messages.
44+
/// Every message handler is associated with a single message processor.
45+
/// This way the handler can initiate, or send, messages which are not a reply
46+
/// on incoming messages.
47+
/// </summary>
48+
IMessageProcessor MessageProcessor
49+
{
50+
get;
51+
set;
52+
}
53+
}
54+
};

MSNPSharp/Core/MessageProcessor.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#region
2+
/*
3+
Copyright (c) 2002-2012, Bas Geertsema, Xih Solutions
4+
(http://www.xihsolutions.net), Thiago.Sayao, Pang Wu, Ethem Evlice, Andy Phan, Chang Liu.
5+
All rights reserved. http://code.google.com/p/msnp-sharp/
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
10+
* Redistributions of source code must retain the above copyright notice,
11+
this list of conditions and the following disclaimer.
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
* Neither the names of Bas Geertsema or Xih Solutions nor the names of its
16+
contributors may be used to endorse or promote products derived from this
17+
software without specific prior written permission.
18+
19+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
20+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29+
THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
#endregion
32+
33+
using System;
34+
35+
namespace MSNPSharp.Core
36+
{
37+
using MSNPSharp;
38+
39+
/// <summary>
40+
/// Defines methods to send network messages.
41+
/// </summary>
42+
/// <remarks>
43+
/// IMessageProcessor is the abstraction of an object which can send network messages.
44+
/// Network messages can be any kind of messages: text messages, data messages.
45+
/// By using this interface a de-coupling is established between the handling of messages
46+
/// and the I/O of messages.
47+
/// </remarks>
48+
public interface IMessageProcessor
49+
{
50+
/// <summary>
51+
/// Sends a message to be processed by the processor.
52+
/// </summary>
53+
/// <param name="message"></param>
54+
void SendMessage(NetworkMessage message);
55+
}
56+
};

MSNPSharp/Core/SocketMessageProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public byte[] Bytes
8181
};
8282

8383

84-
public abstract class SocketMessageProcessor : IDisposable
84+
public abstract class SocketMessageProcessor : IMessageProcessor, IDisposable
8585
{
8686
#region Events
8787

MSNPSharp/MSNPSharp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<DependentUpon>enums.cs</DependentUpon>
9595
</Compile>
9696
<Compile Include="EventArgs.cs" />
97+
<Compile Include="Core\IMessageHandler.cs" />
9798
<Compile Include="Framework.cs" />
9899
<Compile Include="IO\DeltasList.cs" />
99100
<Compile Include="IO\IO.cs" />
@@ -103,6 +104,7 @@
103104
<Compile Include="IO\SerializableMemoryStream.cs" />
104105
<Compile Include="MailEventArgs.cs" />
105106
<Compile Include="Core\MessagePool.cs" />
107+
<Compile Include="Core\MessageProcessor.cs" />
106108
<Compile Include="MessageManager.cs" />
107109
<Compile Include="Messenger.cs" />
108110
<Compile Include="Core\MSNMessage.cs" />

MSNPSharp/Messenger.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public ConnectivitySettings ConnectivitySettings
146146
{
147147
connectivitySettings = value;
148148

149-
NSMessageProcessor mp = Nameserver.MessageProcessor;
149+
NSMessageProcessor mp = Nameserver.MessageProcessor as NSMessageProcessor;
150150

151151
if (mp != null)
152152
{
@@ -195,7 +195,7 @@ public bool Connected
195195
{
196196
get
197197
{
198-
NSMessageProcessor mp = Nameserver.MessageProcessor;
198+
NSMessageProcessor mp = Nameserver.MessageProcessor as NSMessageProcessor;
199199
return (mp != null && mp.Connected);
200200
}
201201
}
@@ -368,7 +368,7 @@ private void DoConnect()
368368
/// </summary>
369369
public virtual void Disconnect()
370370
{
371-
NSMessageProcessor mp = Nameserver.MessageProcessor;
371+
NSMessageProcessor mp = Nameserver.MessageProcessor as NSMessageProcessor;
372372

373373
if (mp != null && mp.Connected)
374374
{

MSNPSharp/NSMessageHandler.MSNP21.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public int CreateMultiparty(List<Contact> inviteQueue, EventHandler<MultipartyCr
275275
throw new InvalidOperationException("At least 2 contacts is required except you and contacts must support multiparty.");
276276

277277

278-
NSMessageProcessor nsmp = MessageProcessor;
278+
NSMessageProcessor nsmp = (NSMessageProcessor)MessageProcessor;
279279
int transId = nsmp.IncreaseTransactionID();
280280

281281
lock (multiParties)
@@ -1274,7 +1274,7 @@ private void OnNFYPUTReceived(MultiMimeMessage multiMimeMessage, RoutingInfo rou
12741274
if (mpo == null)
12751275
{
12761276
// Created remotely.
1277-
NSMessageProcessor nsmp = MessageProcessor;
1277+
NSMessageProcessor nsmp = (NSMessageProcessor)MessageProcessor;
12781278
int transId = nsmp.IncreaseTransactionID();
12791279

12801280
group = new Contact(routingInfo.SenderAccount, IMAddressInfoType.TemporaryGroup, this);

MSNPSharp/NSMessageHandler.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ namespace MSNPSharp
5555
/// Handles the protocol messages from the notification server
5656
/// and implements protocol version MSNP21.
5757
/// </summary>
58-
public partial class NSMessageHandler
58+
public partial class NSMessageHandler : IMessageHandler
5959
{
6060
/// <summary>
6161
/// Machine Guid
@@ -403,7 +403,7 @@ public ConnectivitySettings ConnectivitySettings
403403
{
404404
get
405405
{
406-
return MessageProcessor.ConnectivitySettings;
406+
return (MessageProcessor as NSMessageProcessor).ConnectivitySettings;
407407
}
408408
}
409409

@@ -459,7 +459,7 @@ internal Owner Owner
459459
/// <summary>
460460
/// The processor to handle the messages
461461
/// </summary>
462-
public NSMessageProcessor MessageProcessor
462+
public IMessageProcessor MessageProcessor
463463
{
464464
get
465465
{
@@ -635,7 +635,7 @@ protected virtual void OnProcessorConnectCallback(object sender, EventArgs e)
635635
/// </summary>
636636
protected virtual void SendInitialMessage()
637637
{
638-
MessageProcessor.ResetTransactionID();
638+
(MessageProcessor as NSMessageProcessor).ResetTransactionID();
639639

640640
// 1) VER: MSN Protocol used
641641
MessageProcessor.SendMessage(new NSMessage("VER", new string[] { "MSNP21", "CVR0" }));
@@ -902,7 +902,7 @@ protected virtual void OnXFRReceived(NSMessage message)
902902
if ((string)message.CommandValues[0] == "NS")
903903
{
904904
// switch to a new notification server. That means reconnecting our current message processor.
905-
NSMessageProcessor processor = MessageProcessor;
905+
NSMessageProcessor processor = (NSMessageProcessor)MessageProcessor;
906906
// set new connectivity settings
907907
ConnectivitySettings newSettings = new ConnectivitySettings(processor.ConnectivitySettings);
908908
// disconnect first
@@ -1364,7 +1364,7 @@ internal void SetDefaults()
13641364

13651365
private void SendInitialServiceADL()
13661366
{
1367-
NSMessageProcessor nsmp = MessageProcessor;
1367+
NSMessageProcessor nsmp = MessageProcessor as NSMessageProcessor;
13681368

13691369
if (nsmp == null)
13701370
return;
@@ -1397,7 +1397,7 @@ internal void SendInitialADL(Scenario scene)
13971397
if (scene == Scenario.None)
13981398
return;
13991399

1400-
NSMessageProcessor nsmp = MessageProcessor;
1400+
NSMessageProcessor nsmp = (NSMessageProcessor)MessageProcessor;
14011401

14021402
if (nsmp == null)
14031403
return;

MSNPSharp/NSMessageProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public NSMessage NSMessage
5858
}
5959
};
6060

61-
public class NSMessageProcessor
61+
public class NSMessageProcessor : IMessageProcessor
6262
{
6363
#region Events
6464

MSNPSharp/P2P/P2PDirectProcessor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public enum DirectConnectionState
5555
/// <summary>
5656
/// Handles the direct connections in P2P sessions.
5757
/// </summary>
58-
public class P2PDirectProcessor : IDisposable
58+
public class P2PDirectProcessor : IMessageProcessor, IDisposable
5959
{
6060
#region Events
6161

MSNPSharp/P2P/SDGBridge.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ protected override void SendOnePacket(P2PSession session, Contact remote, Guid r
185185
mmMessage.InnerMessage = p2pMessage;
186186
}
187187

188-
NSMessageProcessor nsmp = NSMessageHandler.MessageProcessor;
188+
NSMessageProcessor nsmp = (NSMessageProcessor)NSMessageHandler.MessageProcessor;
189189
int transId = nsmp.IncreaseTransactionID();
190190

191191
lock (p2pAckMessages)
@@ -202,7 +202,7 @@ protected override void SendMultiPacket(P2PSession session, Contact remote, Guid
202202
if (remote == null)
203203
return;
204204

205-
NSMessageProcessor nsmp = NSMessageHandler.MessageProcessor;
205+
NSMessageProcessor nsmp = (NSMessageProcessor)NSMessageHandler.MessageProcessor;
206206

207207
string to = ((int)remote.ClientType).ToString() + ":" + remote.Account;
208208
string from = ((int)NSMessageHandler.Owner.ClientType).ToString() + ":" + NSMessageHandler.Owner.Account;

0 commit comments

Comments
 (0)