tbx  0.7.6
uri.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2019 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 #ifndef TBX_URI_H_
26 #define TBX_URI_H_
27 
28 #include <string>
29 #include "wimpmessagelistener.h"
30 
31 namespace tbx
32 {
33 class URIResultHandler;
34 
42 class URI :
44 {
45  public:
46  URI(const std::string &uri);
47  virtual ~URI();
48 
49  void uri(const std::string &new_uri);
50 
51  static int version();
52  bool dispatch();
53  bool check();
54  void set_result_handler(URIResultHandler *handler);
55 
56  static bool dispatch(const std::string &uri);
57 
58  enum State {NotDispatched, Dispatched, DispatchError, WaitingForResult, Claimed, NotClaimed};
59  State state() const {return _state;}
60 
61  static bool ensure_uri_handler();
62  static bool uri_handler_started();
63 
64  private:
65  virtual void recorded_message(tbx::WimpMessageEvent &event, int reply_to);
66 
67  private:
68  std::string _uri;
69  int _uri_handle;
70  URIResultHandler *_handler;
71  State _state;
72  };
73 
78 {
79  public:
80  URIResultHandler() {}
81  virtual ~URIResultHandler() {}
82 
89  virtual void uri_result(URI &uri, bool claimed) = 0;
90 };
91 
92 }
93 
94 #endif
tbx
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:35
tbx::URI
Class to take a URI and dispatch it to the Wimp for processing.
Definition: uri.h:44
tbx::URI::uri
void uri(const std::string &new_uri)
Reset the URI.
Definition: uri.cc:63
tbx::URIResultHandler
Handler to check if a URI was successfully launched.
Definition: uri.h:78
tbx::URI::uri_handler_started
static bool uri_handler_started()
Check if the uri_handler has been started.
Definition: uri.cc:243
tbx::URI::set_result_handler
void set_result_handler(URIResultHandler *handler)
Set the object to handle the result status of a dispatch or check call.
Definition: uri.cc:182
tbx::URIResultHandler::uri_result
virtual void uri_result(URI &uri, bool claimed)=0
Called once the Wimp has attempted to launch the URI dispatcher.
tbx::WimpRecordedMessageListener
Listener to handle WimpRecordedMessages (event code 18)
Definition: wimpmessagelistener.h:270
tbx::URI::check
bool check()
Check if an application is open that can process the URI.
Definition: uri.cc:145
tbx::URI::URI
URI(const std::string &uri)
Create a URI object to dispatch a URI.
Definition: uri.cc:47
tbx::URI::ensure_uri_handler
static bool ensure_uri_handler()
Ensure the URI handler is started.
Definition: uri.cc:216
tbx::URI::~URI
virtual ~URI()
When the object is destroyed the result handler is cancelled.
Definition: uri.cc:77
tbx::WimpMessageEvent
Wimp message received event.
Definition: wimpmessagelistener.h:210
tbx::URI::dispatch
bool dispatch()
Dispatch the URI.
Definition: uri.cc:108
tbx::URI::version
static int version()
Get the URI version.
Definition: uri.cc:90