Mistake on this page?
Report an issue in GitHub or email us
SmartPoster.h
1 /* Copyright (c) 2018 ARM Limited. All rights reserved.
2  * SPDX-License-Identifier: Apache-2.0
3  * Licensed under the Apache License, Version 2.0 (the License); you may
4  * not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
11  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SMARTPOSTER_H_
17 #define SMARTPOSTER_H_
18 
19 #include "nfc/ndef/common/Text.h"
20 #include "nfc/ndef/common/URI.h"
21 #include "nfc/ndef/common/Mime.h"
22 #include "nfc/ndef/MessageBuilder.h"
23 
24 /**
25  * Smart poster object.
26  *
27  * A smart poster is one of the basic use case of NFC. It encapsulates a URI to
28  * a resource and meta-data of the resource.
29  *
30  * Meta-data are optional, they can be:
31  * - title: name of the resource
32  * - icon: image/media associated to the resource
33  * - action: Action the peer should execute upon reception of the smart poster
34  * - size: The size of the resource.
35  * - type: Mime type of the resource.
36  *
37  * @note It obeys to value semantic and can be copied around.
38  */
39 class SmartPoster {
40 public:
45 
46  /**
47  * Type of actions that should be executed upon smart poster reception.
48  */
49  enum action_t {
50  EXECUTE, //!< EXECUTE
51  SAVE, //!< SAVE
52  EDIT //!< EDIT
53  };
54 
55  /**
56  * Construct a smart poster.
57  *
58  * @param uri The URI to the resource.
59  */
60  SmartPoster(const URI &uri);
61 
62  /**
63  * Set the title of the resource.
64  *
65  * @param text The title of the resource to set.
66  */
67  void set_title(const Text &text);
68 
69  /**
70  * Set the icon of the resource.
71  *
72  * @param icon The icon to set.
73  */
74  void set_icon(const Mime &icon);
75 
76  /**
77  * Set the action to trigger upon smart poster reception.
78  *
79  * @param action The action to do upon reception.
80  */
81  void set_action(action_t action);
82 
83  /**
84  * Set the size of the resource.
85  *
86  * @param size The size of the resource.
87  */
88  void set_resource_size(uint32_t size);
89 
90  /**
91  * Set the type of the resource.
92  *
93  * @param resource_type The type of the resource pointed by the URI.
94  */
95  void set_resource_type(mbed::Span<const uint8_t> &resource_type);
96 
97  /**
98  * Append the smart poster as a ndef record.
99  *
100  * @param ndef_builder The message builder where the record is appended.
101  * @param is_last_record Indicates if this message is the last one.
102  *
103  * @return true if the message has been appended to the builder or false
104  * otherwise.
105  */
106  bool append_record(MessageBuilder &ndef_builder, bool is_last_record) const;
107 
108 private:
109  void append_uri(MessageBuilder &builder) const;
110  size_t get_uri_record_size() const;
111 
112  void append_title(MessageBuilder &builder) const;
113  size_t get_title_record_size() const;
114 
115  void append_icon(MessageBuilder &builder) const;
116  size_t get_icon_record_size() const;
117 
118  void append_action(MessageBuilder &builder) const;
119  size_t get_action_record_size() const;
120 
121  void append_resource_size(MessageBuilder &builder) const;
122  size_t get_resource_size_record_size() const;
123 
124  void append_type(MessageBuilder &builder) const;
125  size_t get_type_record_size() const;
126 
127  URI _uri;
128  Text _title;
129  Mime _icon;
130  action_t _action;
131  uint32_t _resource_size;
132  Text _type;
133 
134  bool _action_set : 1;
135  bool _resource_size_set : 1;
136 };
137 
138 #endif /* SMARTPOSTER_H_ */
Construct a NDEF Message.
SmartPoster(const URI &uri)
Construct a smart poster.
Model the well known type URI.
Definition: URI.h:41
action_t
Type of actions that should be executed upon smart poster reception.
Definition: SmartPoster.h:49
void set_resource_size(uint32_t size)
Set the size of the resource.
Smart poster object.
Definition: SmartPoster.h:39
void set_resource_type(mbed::Span< const uint8_t > &resource_type)
Set the type of the resource.
void set_icon(const Mime &icon)
Set the icon of the resource.
void set_title(const Text &text)
Set the title of the resource.
Represent the well known type text.
Definition: Text.h:40
Represent a mime object.
Definition: Mime.h:40
void set_action(action_t action)
Set the action to trigger upon smart poster reception.
bool append_record(MessageBuilder &ndef_builder, bool is_last_record) const
Append the smart poster as a ndef record.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.