summaryrefslogtreecommitdiff
path: root/indra/newview/lllandmarklist.cpp
blob: 57684fbc18946c38721b6ec76a6404b2ef7713a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/** 
 * @file lllandmarklist.cpp
 * @brief Landmark asset list class
 *
 * Copyright (c) 2002-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

#include "llviewerprecompiledheaders.h"

#include "lllandmarklist.h"

#include "message.h"
#include "llassetstorage.h"

#include "llagent.h"
#include "llnotify.h"
#include "llvfile.h"
#include "llviewerstats.h"

// Globals
LLLandmarkList gLandmarkList;


////////////////////////////////////////////////////////////////////////////
// LLLandmarkList

LLLandmarkList::~LLLandmarkList()
{
	std::for_each(mList.begin(), mList.end(), DeletePairedPointer());
}

LLLandmark* LLLandmarkList::getAsset( const LLUUID& asset_uuid )
{
	LLLandmark* landmark = get_ptr_in_map(mList, asset_uuid);
	if(landmark)
	{
		return landmark;
	}
	else
	{
	    if ( gLandmarkList.mBadList.find(asset_uuid) == gLandmarkList.mBadList.end() )
		{
			gAssetStorage->getAssetData(
				asset_uuid,
				LLAssetType::AT_LANDMARK,
				LLLandmarkList::processGetAssetReply,
				NULL);
		}
	}
	return NULL;
}

// static
void LLLandmarkList::processGetAssetReply(
	LLVFS *vfs,
	const LLUUID& uuid,
	LLAssetType::EType type,
	void* user_data,
	S32 status)
{
	if( status == 0 )
	{
		LLVFile file(vfs, uuid, type);
		S32 file_length = file.getSize();

		char* buffer = new char[ file_length + 1 ];
		file.read( (U8*)buffer, file_length);		/*Flawfinder: ignore*/
		buffer[ file_length ] = 0;

		LLLandmark* landmark = LLLandmark::constructFromString(buffer);
		if (landmark)
		{
			LLVector3d pos;
			if(!landmark->getGlobalPos(pos))
			{
				LLUUID region_id;
				if(landmark->getRegionID(region_id))
				{
					LLLandmark::requestRegionHandle(
						gMessageSystem,
						gAgent.getRegionHost(),
						region_id,
						NULL);
				}
			}
			gLandmarkList.mList[ uuid ] = landmark;
		}

		delete[] buffer;
	}
	else
	{
		if( gViewerStats )
		{
			gViewerStats->incStat( LLViewerStats::ST_DOWNLOAD_FAILED );
		}

		if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status )
		{
			LLNotifyBox::showXml("LandmarkMissing");
		}
		else
		{
			LLNotifyBox::showXml("UnableToLoadLandmark");
		}

		gLandmarkList.mBadList.insert(uuid);
	}

}

BOOL LLLandmarkList::assetExists(const LLUUID& asset_uuid)
{
	return mList.count(asset_uuid) != 0 || mBadList.count(asset_uuid) != 0;
}