Danh mục

Smart Home Automation with Linux- P10

Số trang: 30      Loại file: pdf      Dung lượng: 978.03 KB      Lượt xem: 17      Lượt tải: 0    
Jamona

Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Smart Home Automation with Linux- P10:For every word I’ve written, five have been discarded. Such is the nature of writing. For every tenprograms I’ve downloaded, tried, and tested, nine have been discarded. Such is the nature of software.Finding a perspicuous overlap has been a long and arduous tasks, and one that I’d wish for no one tosuffer in solitude.
Nội dung trích xuất từ tài liệu:
Smart Home Automation with Linux- P10 CHAPTER 7 ■ CONTROL HUBS In the TODO example, your applet should be able to list the to-do list for the current user or the 5public and optionally be able to sort it alphabetically. This will ultimately provide you with five potentialparameters: • Refresh state parameter: Which user is visible? • Refresh state parameter: Is the list sorted? • Command argument: Switch to user X. • Command argument: Sort list. • Command argument: Unsort list (aka, show in order). This demonstrates the next point—there is redundancy here. It is technically possible to combinethe refresh state and command parameter in one, since they both control the same data. However, whenyou are building a web page, you need to know all the refresh state parameters so that the other links onthe page have the correct values. Unfortunately, that would require a lot of work to know which stateparameter would be overridden later by the command parameters. You can simplify this by writing arefresh function that describes the current state and that every other applet will indirectly call when itrequests a URL from the applet manager:function getRefreshParams(&$appMan){ return $appMan->getArgument($this, user, $this->_viewuser).&. $appMan->getArgument($this, sort, $this->_sortlist));} You next add links that contain command parameters, which are similar to those you’ve seenalready:$html = Show: ;$html.= $appMan->getAppletLink($this, dosort, 0, Chronologically). ;$html.= $appMan->getAppletLink($this, dosort, 1, Alphabetically);$html.= For: ;$html.= $appMan->getAppletLink($this, douser, $user, $user). ;$html.= $appMan->getAppletLink($this, douser, public, Public);5 To correctly delete an entry from the TODO list, you’d need to lock the file in case the file got corrupted when twopeople tried to delete at the same time. I have a truly marvelous solution to this, which this margin is too narrow tocontain! 253 CHAPTER 7 ■ CONTROL HUBS These parameters, by convention, are prefixed with do indicating that they should change the refresh state. That is, new state = old state + do changes. The applet manager generates a suitable link by gathering the refresh parameters from every applet present on the current page and appending these do links to the end. When the page is loaded, a new state is built based on these parameters and done in two stages. The first is to retrieve the refresh arguments: $this->_sortlist = $appMan->queryParameter($this, sort, false); $this->_viewuser = $appMan->queryParameter($this, user, public); The second is to look for any do parameters to change this state: $this->_sortlist = $appMan->queryParameter($this, dosort, $this->_sortlist); $this->_viewuser = $appMan->queryParameter($this, douser, $this->_viewuser); In both cases you’re using a default argument to queryParameter that covers the case when the applet is first used and no parameters at all are available and for when there are no command parameters. You can then flex your creative muscles in displaying the output from the Bearskin command todo (remember writing that all those pages ago?!) and write the list into the HTML: exec(/usr/local/minerva/bin/todo list .$this->_viewuser, $todolist); if ($this->_sortlist) { sort($todolist); } $html .= ; foreach($todolist AS $item) { $html .= $item; } $html .= ; To add a layer of polish to these, you could move the exec call into Zinc, but that can be left for another day! Global Configuration There are a small number of configuration files used in the web portion of Minerva to cope with the different directories structures you might adopt, as detailed in Table 7-1.254 CHAPTER 7 ■ CONTROL HUBSTable 7-1. Web Configuration DirectoriesInclude Filename Function Default Directory Descriptionminerva.conf getMinervaRoot /usr/local/minerva The base of the Minerva system itself.system/setup.conf getURLRoot /minerva The name used by Minerva web components. Can be chang ...

Tài liệu được xem nhiều: