DServerAgent.cpp

Go to the documentation of this file.
00001 /*
00002  * This file is part of Micole Architecture
00003  *
00004  * Copyright (C) 2007 Micole partners
00005  *
00006  * Micole Architecture is free software: you can redistribute it 
00007  * and/or modify it under the terms of the GNU Lesser General 
00008  * Public License as published by the Free Software Foundation, 
00009  * either version 3 of the License, or (at your option) any 
00010  * later version.
00011  *
00012  * Micole Architecture is distributed in the hope that it will be 
00013  * useful, * but WITHOUT ANY WARRANTY; without even the implied 
00014  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00015  * PURPOSE.  See the GNU Lesser General Public License for more 
00016  * details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Micole Architecture.  If not, see
00020  * <http://www.gnu.org/licenses/>.
00021  */
00022 
00023 #include "stdafx.h"
00024 #include "DServerAgent.h"
00025 #include "MicoleAgentThread.h"
00026 #include "MicoleStringStream.h"
00027 
00028 
00029 DServerAgent::DServerAgent(SOCKET sock, ServerAgent * srv)
00030 : MicoleAgentThread("DServerAgent","DServerAgent")
00031 {
00032         _sock = sock;
00033         _parent = srv;
00034         send(_sock, "All is ok!!!\0", 13, 0);
00035         start(); //Start thread*/
00036 }
00037 
00038 DServerAgent::~DServerAgent()
00039 {}
00040 
00041 void DServerAgent::run ()
00042 {
00043         char *buffer = new char[1024];
00044         int result;
00045 
00046         while(getState()==ACTIVE)
00047         {
00048                 result = recv(_sock, buffer, 1023, 0);
00049 
00050                 if (result == -1) {
00051                         _parent->removeThread(this);
00052                 } else {
00053                         OutputDebugStringA("In network: ");
00054                         OutputDebugStringA(buffer);
00055                         OutputDebugStringA("\n");
00056                         _parent->sendOnAllClients(buffer);
00057                 }
00058                 //::Sleep(1);
00059         }
00060         closesocket(_sock);
00061         WSACleanup();
00062 
00063         
00064 }
00065 
00066 void DServerAgent::sendOnNetwork(string s) {
00067         send(_sock, (s+"\0").c_str(), (int(s.size())+1), 0);
00068 }
00069 
00070 
00074 void DServerAgent::prepareToStop(int argc, const char **argv)
00075 {
00076 }
00077 
00078 void DServerAgent::prepareToSuspend(int argc, const char **argv)
00079 {
00080 }

Generated on Tue Oct 16 17:10:42 2007 for Micole by  doxygen 1.4.7