00001 // message_server.h 00002 00003 /* Copyright 2009 10gen Inc. 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 abstract database server 00020 async io core, worker thread system 00021 */ 00022 00023 #pragma once 00024 00025 #include "../pch.h" 00026 00027 namespace mongo { 00028 00029 class MessageHandler { 00030 public: 00031 virtual ~MessageHandler() {} 00032 00033 virtual void connected( AbstractMessagingPort* p ) = 0; 00034 virtual void process( Message& m , AbstractMessagingPort* p , LastError * err ) = 0; 00035 virtual void disconnected( AbstractMessagingPort* p ) = 0; 00036 }; 00037 00038 class MessageServer { 00039 public: 00040 struct Options { 00041 int port; // port to bind to 00042 string ipList; // addresses to bind to 00043 00044 Options() : port(0), ipList("") {} 00045 }; 00046 00047 virtual ~MessageServer() {} 00048 virtual void run() = 0; 00049 virtual void setAsTimeTracker() = 0; 00050 }; 00051 00052 // TODO use a factory here to decide between port and asio variations 00053 MessageServer * createServer( const MessageServer::Options& opts , MessageHandler * handler ); 00054 }