~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/AvatarLogger.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-10-22 23:21:17 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20091022232117-isr8u3402qmu7ilo
Tags: 0.5.7-1
* New upstream release.
  - Compile against current ogre (Closes: #551431)
  - Removed debian/patches/ember-gcc4.4.patch. Merged upstream.
  - Updated Depends on ember-media.
* Add libboost-thread-dev tp Build-Depends.
* Make debian/rules independent from upstream version.
* Updated watch file to allow automatic download of new upstream
  tarballs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// C++ Implementation: AvatarLogger
3
3
//
4
 
// Description: 
 
4
// Description:
5
5
//
6
6
//
7
7
// Author: Erik Hjortsberg <erik.hjortsberg@gmail.com>, (C) 2008
10
10
// it under the terms of the GNU General Public License as published by
11
11
// the Free Software Foundation; either version 2 of the License, or
12
12
// (at your option) any later version.
13
 
// 
 
13
//
14
14
// This program is distributed in the hope that it will be useful,
15
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
17
// GNU General Public License for more details.
18
 
// 
 
18
//
19
19
// You should have received a copy of the GNU General Public License
20
20
// along with this program; if not, write to the Free Software
21
21
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.//
27
27
#include "AvatarLogger.h"
28
28
#include "Avatar.h"
29
29
#include "EmberEntity.h"
30
 
#include "EmberPhysicalEntity.h"
31
 
#include "AvatarEmberEntity.h"
 
30
#include "GUIManager.h"
32
31
#include "services/config/ConfigService.h"
33
32
#include "services/time/TimeService.h"
34
33
 
39
38
 
40
39
namespace EmberOgre {
41
40
 
42
 
AvatarLogger::AvatarLogger(AvatarEmberEntity& avatarEntity)
 
41
AvatarLogger::AvatarLogger(EmberEntity& avatarEntity)
43
42
: mChatLogger(0)
44
43
{
45
44
        assert(&avatarEntity);
46
 
        
 
45
 
47
46
        ///Put log files in a "logs" subdirectory of the home directory.
48
47
        const std::string dir = Ember::EmberServices::getSingleton().getConfigService()->getHomeDirectory() + "/logs/";
49
48
        try {
50
49
                //make sure the directory exists
51
 
                
 
50
 
52
51
                oslink::directory osdir(dir);
53
52
 
54
53
                if (!osdir.isExisting()) {
63
62
                logFileSS << dir << "/" << avatarEntity.getName() << "_chatlog.log";
64
63
                mChatLogger = std::auto_ptr<std::ofstream>(new std::ofstream(logFileSS.str().c_str(), std::ios::app));
65
64
                S_LOG_VERBOSE("Chat Logging set to write in [ " << logFileSS.str() << " ]");
66
 
                
 
65
 
67
66
                *mChatLogger << "-------------------------------------------------------" << std::endl;
68
67
                *mChatLogger << "Chat Logging Initialized at " <<  Ember::EmberServices::getSingleton().getTimeService()->getLocalTimeStr() << std::endl;
69
68
                *mChatLogger << "-------------------------------------------------------" << std::endl;
70
 
                
 
69
 
71
70
                ///wait with connecting until everything has been properly set up
72
71
                GUIManager::getSingleton().AppendIGChatLine.connect(sigc::mem_fun(*this, &AvatarLogger::GUIManager_AppendIGChatLine));
73
 
                
 
72
 
74
73
        } catch (const std::exception& ex) {
75
 
                S_LOG_FAILURE("Error when creating directory for logs. Message: " << std::string(ex.what()));
 
74
                S_LOG_FAILURE("Error when creating directory for logs." << ex);
76
75
        }
77
76
}
78
77
 
87
86
void AvatarLogger::GUIManager_AppendIGChatLine(const std::string& message, EmberEntity* entity)
88
87
{
89
88
        *mChatLogger << "[" << Ember::EmberServices::getSingleton().getTimeService()->getLocalTimeStr() << "] <" <<  entity->getName() << "> says: " << message << std::endl;
90
 
 
89
}
91
90
 
92
91
AvatarLoggerParent::AvatarLoggerParent(Avatar& avatar)
93
92
{
94
93
        ///we either already have an entity, or we need to wait until it's creeated
95
 
        if (avatar.getAvatarEmberEntity()) {
96
 
                mLogger = std::auto_ptr<AvatarLogger>(new AvatarLogger(*avatar.getAvatarEmberEntity()));
97
 
        } else
98
 
        {
99
 
                avatar.EventCreatedAvatarEntity.connect(sigc::mem_fun(*this, &AvatarLoggerParent::Avatar_CreatedAvatarEntity));
100
 
        }
 
94
        mLogger = std::auto_ptr<AvatarLogger>(new AvatarLogger(avatar.getEmberEntity()));
101
95
}
102
96
 
103
 
void AvatarLoggerParent::Avatar_CreatedAvatarEntity(AvatarEmberEntity* entity)
104
 
{
105
 
        mLogger = std::auto_ptr<AvatarLogger>(new AvatarLogger(*entity));
106
 
}
107
97
 
108
98
 
109
99
}