summaryrefslogtreecommitdiff
path: root/apps/JAWS/clients/Caching/Local_Locator.cpp
blob: 9799a4f21b3bd83615100afd0ab5a10865c104c1 (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// $Id$

#if !defined (ACE_LOCAL_LOCATOR_C)
#define ACE_LOCAL_LOCATOR_C

#define ACE_BUILD_DLL
#include "Local_Locator.h"

#if !defined (__ACE_INLINE__)
#include "Local_Locator.i"
#endif /* __ACE_INLINE__ */

int
ACE_URL_Local_Locator::url_query (const ACE_URL_Locator::ACE_Selection_Criteria how,
				  const ACE_URL_Property_Seq *pseq,
				  const size_t how_many,
				  size_t &num_query,
				  ACE_URL_Offer_Seq *offer)
{
  ACE_URL_Record *item = 0;

  ACE_NEW_RETURN (offer, ACE_URL_Offer_Seq (how_many), -1);
  
  for (ACE_Unbounded_Set_Iterator<ACE_URL_Record> iter (this->repository_);
       iter.next (item) != 0;
       iter.advance ())
    {
      switch (how)
	{
	case ACE_URL_Locator::NONE:
	  // Offers must not have any properties in <pseq>
	  errno = ACE_URL_Locator::UNIMPLEMENTED;
	  return -1;
	  break;
	case ACE_URL_Locator::SOME:
	  // Offers must have at least one property in <pseq>
	  errno = ACE_URL_Locator::UNIMPLEMENTED;
	  return -1;
	  break;
	case ACE_URL_Locator::ALL:
	  // Offers must have all the properties in <pseq>
	  errno = ACE_URL_Locator::UNIMPLEMENTED;
	  return -1;
	  break;
	default:
	  delete [] offer ;
	  offer = 0;
	  errno = ACE_URL_Locator::INVALID_ARGUMENT;
	  return -1;
	}
      if (how_many == 0)
	break;
    }

  return 0;
}

int
ACE_URL_Local_Locator::export_offer (ACE_URL_Offer *offer,
				     ACE_WString &offer_id)
{
  ACE_URL_Record *item = 0;

  // First check if we have registered this URL already.
  for (ACE_Unbounded_Set_Iterator<ACE_URL_Record> iter (this->repository_);
       iter.next (item) != 0; 
       iter.advance ())
    if (*item->offer_->url () == *offer->url ())
      {
	errno = ACE_URL_Locator::OFFER_EXIST;
	return -1;
      }

  ACE_URL_Record *new_offer;

  // Offer is not in repository, we can add new one in safely.
  ACE_NEW_RETURN (new_offer, ACE_URL_Record (offer),
		  ACE_URL_Locator::NOMEM);

  this->repository_.push (*new_offer);

  offer_id = *new_offer->id_;
  return 0;
}

int
ACE_URL_Local_Locator::withdraw_offer (const ACE_WString &offer_id)
{
  ACE_URL_Record *item = 0;
  
  // Iterate thru repository and remove offer with <offer_id>.
  for (ACE_Unbounded_Set_Iterator<ACE_URL_Record> iter (this->repository_);
       iter.next (item) != 0;
       iter.advance ())
      if (offer_id == *item->id_)
	{
	  if (this->repository_.remove (*item) == 0)
	    return 0
	  else
	    {
	      errno = ACE_URL_Locator::UNKNOWN;
	      return -1;
	    }
	}

  errno = ACE_URL_Locator::NO_SUCH_OFFER;
  return 0;
}

int
ACE_URL_Local_Locator::describe_offer (const ACE_WString &offer_id,
				       ACE_URL_Offer *offer)
{
  ACE_URL_Record *item = 0;
  
  // Iterate thru the repository and produce a copy of offer's
  // description.
  for (ACE_Unbounded_Set_Iterator<ACE_URL_Record> iter (this->repository_);
       iter.next (item) != 0;
       iter.advance ())
    if (offer_id == *item->id_)
      {
	ACE_NEW_RETURN (offer, ACE_URL_Offer (*item->offer_), -1);
	return 0;
      }

  errno = ACE_URL_Locator::NO_SUCH_OFFER;
  return -1;
}

int
ACE_URL_Local_Locator::modify_offer (const ACE_WString &offer_id,
				     const char *url,
				     const ACE_URL_Property_Seq *del,
				     const ACE_URL_Property_Seq *modify)
{
  errno = ACE_URL_Locator::UNIMPLEMENTED;
  return -1;
}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_Unbounded_Set<ACE_URL_Record>;
template class ACE_Unbounded_Set_Iterator<ACE_URL_Record>;
template class ACE_Node<ACE_URL_Record>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Unbounded_Set<ACE_URL_Record>
#pragma instantiate ACE_Unbounded_Set_Iterator<ACE_URL_Record>
#pragma instantiate ACE_Node<ACE_URL_Record>
#endif /*ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
#endif /* ACE_LOCAL_LOCATOR_C */